< prev index next >

src/hotspot/share/oops/klass.cpp

Print this page
rev 48545 : Value-based classes (vbc) / Oop value test via metadata ptr

@@ -168,14 +168,29 @@
 #endif
   ShouldNotReachHere();
   return NULL;
 }
 
+#if INCLUDE_VBC
+void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, bool is_value, TRAPS) throw() {
+  // Pad size in case need adjust to even/odd klass ptr
+  uintptr_t addr = (uintptr_t) Metaspace::allocate(loader_data, word_size + (1 << LogKlassAlignment), MetaspaceObj::ClassType, THREAD);
+  // values are odd, otherwise make even (and vice versa)
+  if (is_value ^ ((addr & KlassPtrEvenOddMask) >> LogKlassAlignmentInBytes)) {
+          addr += (1 << LogKlassAlignmentInBytes);
+  }
+  assert(is_aligned(addr, (1 << LogKlassAlignmentInBytes)), "Klass base alignment incorrect");
+  assert(is_value || (addr & KlassPtrEvenOddMask) == 0,     "Klass even alignment incorrect");
+  assert((!is_value) || (addr & KlassPtrEvenOddMask),       "Klass odd alignment incorrect");
+  return (void*) addr;
+#else
 void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
   return Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD);
+#endif
 }
 
+
 // "Normal" instantiation is preceeded by a MetaspaceObj allocation
 // which zeros out memory - calloc equivalent.
 // The constructor is also used from CppVtableCloner,
 // which doesn't zero out the memory before calling the constructor.
 // Need to set the _java_mirror field explicitly to not hit an assert that the field
< prev index next >