diff --git a/src/hotspot/share/runtime/sharedRuntime.cpp b/src/hotspot/share/runtime/sharedRuntime.cpp index edb33b3500a..9c710fc98e4 100644 --- a/src/hotspot/share/runtime/sharedRuntime.cpp +++ b/src/hotspot/share/runtime/sharedRuntime.cpp @@ -2199,10 +2199,11 @@ class AdapterFingerPrint : public MetaspaceObj { } // Private construtor. Use allocate() to get an instance. - AdapterFingerPrint(int total_args_passed, BasicType* sig_bt) { + AdapterFingerPrint(int total_args_passed, BasicType* sig_bt, int len) { int* data = data_pointer(); // Pack the BasicTypes with 8 per int - _length = length(total_args_passed); + assert(len == length(total_args_passed), "sanity"); + _length = len; int sig_index = 0; for (int index = 0; index < _length; index++) { int value = 0; @@ -2217,16 +2218,15 @@ class AdapterFingerPrint : public MetaspaceObj { // Call deallocate instead ~AdapterFingerPrint() { - FreeHeap(this); + ShouldNotCallThis(); } static int length(int total_args) { return (total_args + (_basic_types_per_int-1)) / _basic_types_per_int; } - static int compute_size(int total_args_passed, BasicType* sig_bt) { - int len = length(total_args_passed); - return sizeof(AdapterFingerPrint) + (len * sizeof(int)); + static int compute_size_in_words(int len) { + return (int)heap_word_size(sizeof(AdapterFingerPrint) + (len * sizeof(int))); } // Remap BasicTypes that are handled equivalently by the adapters. @@ -2289,12 +2289,15 @@ class AdapterFingerPrint : public MetaspaceObj { public: static AdapterFingerPrint* allocate(int total_args_passed, BasicType* sig_bt) { - int size_in_bytes = compute_size(total_args_passed, sig_bt); - return new (size_in_bytes) AdapterFingerPrint(total_args_passed, sig_bt); + int len = length(total_args_passed); + int size_in_bytes = BytesPerWord * compute_size_in_words(len); + AdapterFingerPrint* afp = new (size_in_bytes) AdapterFingerPrint(total_args_passed, sig_bt, len); + assert((afp->size() * BytesPerWord) == size_in_bytes, "should match"); + return afp; } static void deallocate(AdapterFingerPrint* fp) { - fp->~AdapterFingerPrint(); + FreeHeap(fp); } int value(int index) { @@ -2418,7 +2421,7 @@ class AdapterFingerPrint : public MetaspaceObj { // methods required by virtue of being a MetaspaceObj void metaspace_pointers_do(MetaspaceClosure* it) { return; /* nothing to do here */ } - int size() const { return (int)heap_word_size(sizeof(AdapterFingerPrint) + (_length * sizeof(int))); } + int size() const { return compute_size_in_words(_length); } MetaspaceObj::Type type() const { return AdapterFingerPrintType; } static bool equals(AdapterFingerPrint* const& fp1, AdapterFingerPrint* const& fp2) { diff --git a/src/hotspot/share/runtime/sharedRuntime.hpp b/src/hotspot/share/runtime/sharedRuntime.hpp index 86074ac7aca..eb2ffb82e5a 100644 --- a/src/hotspot/share/runtime/sharedRuntime.hpp +++ b/src/hotspot/share/runtime/sharedRuntime.hpp @@ -711,6 +711,7 @@ class AdapterHandlerEntry : public MetaspaceObj { // Dummy argument is used to avoid C++ warning about using // deleted opearator MetaspaceObj::delete(). void* operator new(size_t size, size_t dummy) throw() { + assert(size == BytesPerWord * heap_word_size(sizeof(AdapterHandlerEntry)), "should match"); void* p = AllocateHeap(size, mtCode); memset(p, 0, size); return p;