diff --git a/src/share/vm/prims/jvmtiEnvBase.cpp b/src/share/vm/prims/jvmtiEnvBase.cpp index 99f7514265201fb5c1087a84f7af65497e847134..c0c98f01e53c3b06eac8eecee67ba7fb9ba18289 100644 --- a/src/share/vm/prims/jvmtiEnvBase.cpp +++ b/src/share/vm/prims/jvmtiEnvBase.cpp @@ -94,6 +94,35 @@ JvmtiEnvBase::initialize() { } +bool +JvmtiEnvBase::is_valid() { + jint value = 0; + + // This object might not be a JvmtiEnvBase so we can't assume + // the _magic field is properly aligned. Get the value in a safe + // way and then check against JVMTI_MAGIC. + + switch (sizeof(_magic)) { + case 2: + value = Bytes::get_native_u2((address)&_magic); + break; + + case 4: + value = Bytes::get_native_u4((address)&_magic); + break; + + case 8: + value = Bytes::get_native_u8((address)&_magic); + break; + + default: + guarantee(false, "_magic field is an unexpected size"); + } + + return value == JVMTI_MAGIC; +} + + JvmtiEnvBase::JvmtiEnvBase() : _env_event_enable() { _env_local_storage = NULL; _tag_map = NULL; diff --git a/src/share/vm/prims/jvmtiEnvBase.hpp b/src/share/vm/prims/jvmtiEnvBase.hpp index 477725ffec5cd2c172bd61ac9099ce0382071a98..e6dd31e5870c7d22768c9d9784dc47006557ac8d 100644 --- a/src/share/vm/prims/jvmtiEnvBase.hpp +++ b/src/share/vm/prims/jvmtiEnvBase.hpp @@ -120,7 +120,7 @@ class JvmtiEnvBase : public CHeapObj { public: - bool is_valid() { return _magic == JVMTI_MAGIC; } + bool is_valid(); bool is_retransformable() { return _is_retransformable; } diff --git a/src/share/vm/prims/jvmtiImpl.cpp b/src/share/vm/prims/jvmtiImpl.cpp index f9a512c4222b8b579e5b351a27a9afb3bc3288a1..5a174b35bc3e53b712e7cde40231a6108fc9b8c7 100644 --- a/src/share/vm/prims/jvmtiImpl.cpp +++ b/src/share/vm/prims/jvmtiImpl.cpp @@ -238,6 +238,35 @@ JvmtiRawMonitor::~JvmtiRawMonitor() { } +bool +JvmtiRawMonitor::is_valid() { + int value = 0; + + // This object might not be a JvmtiRawMonitor so we can't assume + // the _magic field is properly aligned. Get the value in a safe + // way and then check against JVMTI_RM_MAGIC. + + switch (sizeof(_magic)) { + case 2: + value = Bytes::get_native_u2((address)&_magic); + break; + + case 4: + value = Bytes::get_native_u4((address)&_magic); + break; + + case 8: + value = Bytes::get_native_u8((address)&_magic); + break; + + default: + guarantee(false, "_magic field is an unexpected size"); + } + + return value == JVMTI_RM_MAGIC; +} + + // // class JvmtiBreakpoint // diff --git a/src/share/vm/prims/jvmtiImpl.hpp b/src/share/vm/prims/jvmtiImpl.hpp index d1b8414e61efa6c0cb84364ffda0265c88138899..2605546c62d047574b646b6bebd22a99b6d8e4e3 100644 --- a/src/share/vm/prims/jvmtiImpl.hpp +++ b/src/share/vm/prims/jvmtiImpl.hpp @@ -349,7 +349,7 @@ public: ~JvmtiRawMonitor(); int magic() { return _magic; } const char *get_name() { return _name; } - bool is_valid() { return _magic == JVMTI_RM_MAGIC; } + bool is_valid(); }; // Onload pending raw monitors