Skip to content

Commit f7838bb

Browse files
committed
Adjust for missing functionality for downports
1 parent a41f66c commit f7838bb

File tree

4 files changed

+72
-19
lines changed

4 files changed

+72
-19
lines changed

ddprof-lib/src/main/cpp/codeCache.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,6 @@ void CodeCache::sort() {
162162
_max_address = _blobs[_count - 1]._end;
163163
}
164164

165-
void CodeCache::mark(NamePredicate predicate) {
166-
for (int i = 0; i < _count; i++) {
167-
const char *blob_name = _blobs[i]._name;
168-
if (blob_name != NULL && predicate(blob_name)) {
169-
NativeFunc::mark(blob_name);
170-
}
171-
}
172-
}
173-
174165
CodeBlob *CodeCache::findBlob(const char *name) {
175166
for (int i = 0; i < _count; i++) {
176167
const char *blob_name = _blobs[i]._name;

ddprof-lib/src/main/cpp/codeCache.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ enum ImportType {
3838
NUM_IMPORT_TYPES
3939
};
4040

41+
enum Mark {
42+
MARK_VM_RUNTIME = 1,
43+
MARK_INTERPRETER = 2,
44+
MARK_COMPILER_ENTRY = 3,
45+
MARK_ASYNC_PROFILER = 4, // async-profiler internals such as native hooks.
46+
};
47+
4148
class NativeFunc {
4249
private:
4350
short _lib_index;
@@ -63,7 +70,13 @@ class NativeFunc {
6370

6471
static bool isMarked(const char *name) { return from(name)->_mark != 0; }
6572

66-
static void mark(const char *name) { from(name)->_mark = 1; }
73+
static char mark(const char* name) {
74+
return from(name)->_mark;
75+
}
76+
77+
static void mark(const char* name, char value) {
78+
from(name)->_mark = value;
79+
}
6780
};
6881

6982
class CodeBlob {
@@ -154,7 +167,20 @@ class CodeCache {
154167
bool update_bounds = false);
155168
void updateBounds(const void *start, const void *end);
156169
void sort();
157-
void mark(NamePredicate predicate);
170+
template <typename NamePredicate>
171+
inline void mark(NamePredicate predicate, char value) {
172+
for (int i = 0; i < _count; i++) {
173+
const char* blob_name = _blobs[i]._name;
174+
if (blob_name != NULL && predicate(blob_name)) {
175+
NativeFunc::mark(blob_name, value);
176+
}
177+
}
178+
179+
if (value == MARK_VM_RUNTIME && _name != NULL) {
180+
// In case a library has no debug symbols
181+
NativeFunc::mark(_name, value);
182+
}
183+
}
158184

159185
void addImport(void **entry, const char *name);
160186
void **findImport(ImportId id);

ddprof-lib/src/main/cpp/vmEntry.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ JVM_GetManagement VM::_getManagement;
5151

5252
static void wakeupHandler(int signo) {
5353
// Dummy handler for interrupting syscalls
54+
}
5455

5556
static bool isVmRuntimeEntry(const char* blob_name) {
5657
return strcmp(blob_name, "_ZNK12MemAllocator8allocateEv") == 0
@@ -302,14 +303,32 @@ bool VM::initShared(JavaVM* vm) {
302303
}
303304

304305
VMStructs::init(lib);
305-
if (is_zero_vm) {
306-
lib->mark(isZeroInterpreterMethod);
307-
} else if (isOpenJ9()) {
308-
lib->mark(isOpenJ9InterpreterMethod);
309-
CodeCache *libjit = libraries->findJvmLibrary("libj9jit");
310-
if (libjit != NULL) {
311-
libjit->mark(isOpenJ9JitStub);
312-
}
306+
if (isOpenJ9()) {
307+
Libraries* libraries = Libraries::instance();
308+
lib->mark(isOpenJ9InterpreterMethod, MARK_INTERPRETER);
309+
lib->mark(isOpenJ9Resolve, MARK_VM_RUNTIME);
310+
CodeCache* libjit = libraries->findJvmLibrary("libj9jit");
311+
if (libjit != NULL) {
312+
libjit->mark(isOpenJ9JitStub, MARK_INTERPRETER);
313+
libjit->mark(isOpenJ9JitAlloc, MARK_VM_RUNTIME);
314+
}
315+
CodeCache* libgc = libraries->findJvmLibrary("libj9gc");
316+
if (libgc != NULL) {
317+
libgc->mark(isOpenJ9GcAlloc, MARK_VM_RUNTIME);
318+
}
319+
CodeCache* libjvmti = libraries->findJvmLibrary("libj9jvmti");
320+
if (libjvmti != NULL) {
321+
libjvmti->mark(isOpenJ9JvmtiAlloc, MARK_VM_RUNTIME);
322+
}
323+
} else {
324+
lib->mark(isVmRuntimeEntry, MARK_VM_RUNTIME);
325+
if (isZing()) {
326+
lib->mark(isZingRuntimeEntry, MARK_VM_RUNTIME);
327+
} else if (is_zero_vm) {
328+
lib->mark(isZeroInterpreterMethod, MARK_INTERPRETER);
329+
} else {
330+
lib->mark(isCompilerEntry, MARK_COMPILER_ENTRY);
331+
}
313332
}
314333
return true;
315334
}

ddprof-lib/src/main/cpp/vmStructs.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,12 @@ class CodeHeap : VMStructs {
547547

548548
class JVMFlag : VMStructs {
549549
private:
550+
enum {
551+
ORIGIN_DEFAULT = 0,
552+
ORIGIN_MASK = 15,
553+
SET_ON_CMDLINE = 1 << 17
554+
};
555+
550556
static JVMFlag* find(const char *name, int type_mask);
551557
public:
552558
enum Type {
@@ -570,10 +576,21 @@ class JVMFlag : VMStructs {
570576
int type();
571577

572578
void *addr() { return *(void **)at(_flag_addr_offset); }
579+
573580
char origin() {
574581
return _flag_origin_offset >= 0 ? (*(char*) at(_flag_origin_offset)) & 15 : 0;
575582
}
576583

584+
bool isDefault() {
585+
return _flag_origin_offset < 0 || (*(int*) at(_flag_origin_offset) & ORIGIN_MASK) == ORIGIN_DEFAULT;
586+
}
587+
588+
void setCmdline() {
589+
if (_flag_origin_offset >= 0) {
590+
*(int*) at(_flag_origin_offset) |= SET_ON_CMDLINE;
591+
}
592+
}
593+
577594
char get() {
578595
return *((char*)addr());
579596
}

0 commit comments

Comments
 (0)