Skip to content

Commit

Permalink
#914: Do not set DebugNonSafepoints, if it is already set in the Comm…
Browse files Browse the repository at this point in the history
…and Line
  • Loading branch information
apangin committed Apr 19, 2024
1 parent 059cf13 commit ac514e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/vmEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,17 @@ bool VM::init(JavaVM* vm, bool attach) {
} else {
// DebugNonSafepoints is automatically enabled with CompiledMethodLoad,
// otherwise we set the flag manually
char* flag_addr = (char*)JVMFlag::find("DebugNonSafepoints");
if (flag_addr != NULL) {
*flag_addr = 1;
JVMFlag* f = JVMFlag::find("DebugNonSafepoints");
if (f != NULL && f->origin() == 0) {
f->set(1);
}
}

if (_can_sample_objects) {
// SetHeapSamplingInterval does not have immediate effect, so apply the configuration
// as early as possible to allow profiling all startup allocations
char* use_tlab = (char*)JVMFlag::find("UseTLAB");
if (use_tlab != NULL && *use_tlab == 0) {
JVMFlag* f = JVMFlag::find("UseTLAB");
if (f != NULL && !f->get()) {
_jvmti->SetHeapSamplingInterval(0);
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/vmStructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ int VMStructs::_vs_low_offset = -1;
int VMStructs::_vs_high_offset = -1;
int VMStructs::_flag_name_offset = -1;
int VMStructs::_flag_addr_offset = -1;
int VMStructs::_flag_origin_offset = -1;
const char* VMStructs::_flags_addr = NULL;
int VMStructs::_flag_count = 0;
int VMStructs::_flag_size = 0;
Expand Down Expand Up @@ -335,6 +336,8 @@ void VMStructs::initOffsets() {
_flag_name_offset = *(int*)(entry + offset_offset);
} else if (strcmp(field, "_addr") == 0 || strcmp(field, "addr") == 0) {
_flag_addr_offset = *(int*)(entry + offset_offset);
} else if (strcmp(field, "_flags") == 0 || strcmp(field, "origin") == 0) {
_flag_origin_offset = *(int*)(entry + offset_offset);
} else if (strcmp(field, "flags") == 0) {
_flags_addr = **(char***)(entry + address_offset);
} else if (strcmp(field, "numFlags") == 0) {
Expand Down Expand Up @@ -396,14 +399,14 @@ void VMStructs::resolveOffsets() {
_klass = (jfieldID)(uintptr_t)(*_klass_offset_addr << 2 | 2);
}

char* ccp = (char*)JVMFlag::find("UseCompressedClassPointers");
if (ccp != NULL && *ccp && _narrow_klass_base_addr != NULL && _narrow_klass_shift_addr != NULL) {
JVMFlag* ccp = JVMFlag::find("UseCompressedClassPointers");
if (ccp != NULL && ccp->get() && _narrow_klass_base_addr != NULL && _narrow_klass_shift_addr != NULL) {
_narrow_klass_base = *_narrow_klass_base_addr;
_narrow_klass_shift = *_narrow_klass_shift_addr;
}

char* coh = (char*)JVMFlag::find("UseCompactObjectHeaders");
if (coh != NULL && *coh) {
JVMFlag* coh = JVMFlag::find("UseCompactObjectHeaders");
if (coh != NULL && coh->get()) {
_compact_object_headers = true;
}

Expand Down Expand Up @@ -644,12 +647,12 @@ NMethod* CodeHeap::findNMethod(char* heap, const void* pc) {
return block[sizeof(size_t)] ? (NMethod*)(block + 2 * sizeof(size_t)) : NULL;
}

void* JVMFlag::find(const char* name) {
JVMFlag* JVMFlag::find(const char* name) {
if (_flags_addr != NULL && _flag_size > 0) {
for (int i = 0; i < _flag_count; i++) {
JVMFlag* f = (JVMFlag*)(_flags_addr + i * _flag_size);
if (f->name() != NULL && strcmp(f->name(), name) == 0) {
return f->addr();
if (f->name() != NULL && strcmp(f->name(), name) == 0 && f->addr() != NULL) {
return f;
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions src/vmStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class VMStructs {
static int _vs_high_offset;
static int _flag_name_offset;
static int _flag_addr_offset;
static int _flag_origin_offset;
static const char* _flags_addr;
static int _flag_count;
static int _flag_size;
Expand Down Expand Up @@ -510,14 +511,26 @@ class CollectedHeap : VMStructs {

class JVMFlag : VMStructs {
public:
static void* find(const char* name);
static JVMFlag* find(const char* name);

const char* name() {
return *(const char**) at(_flag_name_offset);
}

void* addr() {
return *(void**) at(_flag_addr_offset);
char* addr() {
return *(char**) at(_flag_addr_offset);
}

char origin() {
return _flag_origin_offset >= 0 ? (*(char*) at(_flag_origin_offset)) & 15 : 0;
}

char get() {
return *addr();
}

void set(char value) {
*addr() = value;
}
};

Expand Down

0 comments on commit ac514e5

Please sign in to comment.