diff --git a/src/hotspot/share/oops/oop.cpp b/src/hotspot/share/oops/oop.cpp index 9385379a617..7851fb26fac 100644 --- a/src/hotspot/share/oops/oop.cpp +++ b/src/hotspot/share/oops/oop.cpp @@ -217,3 +217,5 @@ void oopDesc::release_float_field_put(int offset, jfloat value) { Atomic:: jdouble oopDesc::double_field_acquire(int offset) const { return Atomic::load_acquire(field_addr(offset)); } void oopDesc::release_double_field_put(int offset, jdouble value) { Atomic::release_store(field_addr(offset), value); } + +int oopDesc::cached_base_offset_in_bytes = -1; \ No newline at end of file diff --git a/src/hotspot/share/oops/oop.hpp b/src/hotspot/share/oops/oop.hpp index dcf42c7343b..952d8e7e243 100644 --- a/src/hotspot/share/oops/oop.hpp +++ b/src/hotspot/share/oops/oop.hpp @@ -349,18 +349,25 @@ class oopDesc { return klass_offset_in_bytes() + sizeof(narrowKlass); } - static int base_offset_in_bytes() { + static int cached_base_offset_in_bytes; + + static void initialize() { if (UseCompactObjectHeaders) { // With compact headers, the Klass* field is not used for the Klass* // and is used for the object fields instead. - return sizeof(markWord); + cached_base_offset_in_bytes = sizeof(markWord); } else if (UseCompressedClassPointers) { - return sizeof(markWord) + sizeof(narrowKlass); + cached_base_offset_in_bytes = sizeof(markWord) + sizeof(narrowKlass); } else { - return sizeof(markWord) + sizeof(Klass*); + cached_base_offset_in_bytes = sizeof(markWord) + sizeof(Klass *); } } + static int base_offset_in_bytes() { + assert(cached_base_offset_in_bytes != -1, "Should have been initialized"); + return cached_base_offset_in_bytes; + } + // for error reporting static void* load_oop_raw(oop obj, int offset); }; diff --git a/src/hotspot/share/runtime/threads.cpp b/src/hotspot/share/runtime/threads.cpp index 76ee237ae5e..729179f4478 100644 --- a/src/hotspot/share/runtime/threads.cpp +++ b/src/hotspot/share/runtime/threads.cpp @@ -484,6 +484,9 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { // Timing (must come after argument parsing) TraceTime timer("Create VM", TRACETIME_LOG(Info, startuptime)); + // Initialize oop constants after argument parsing + oopDesc::initialize(); + // Initialize the os module after parsing the args jint os_init_2_result = os::init_2(); if (os_init_2_result != JNI_OK) return os_init_2_result;