< prev index next >

src/hotspot/share/oops/klass.cpp

Print this page
*** 48,11 ***
--- 48,13 ---
  #include "oops/oop.inline.hpp"
  #include "oops/oopHandle.inline.hpp"
  #include "prims/jvmtiExport.hpp"
  #include "runtime/arguments.hpp"
  #include "runtime/atomic.hpp"
+ #include "runtime/globals.hpp"
  #include "runtime/handles.inline.hpp"
+ #include "utilities/align.hpp"
  #include "utilities/macros.hpp"
  #include "utilities/powerOfTwo.hpp"
  #include "utilities/stack.inline.hpp"
  
  void Klass::set_java_mirror(Handle m) {

*** 190,18 ***
    ShouldNotReachHere();
    return nullptr;
  }
  
  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);
  }
  
  // "Normal" instantiation is preceded 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.
  Klass::Klass(KlassKind kind) : _kind(kind),
                             _shared_class_path_index(-1) {
    CDS_ONLY(_shared_class_flags = 0;)
    CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1;)
    _primary_supers[0] = this;
    set_super_check_offset(in_bytes(primary_supers_offset()));
--- 192,33 ---
    ShouldNotReachHere();
    return nullptr;
  }
  
  void* Klass::operator new(size_t size, ClassLoaderData* loader_data, size_t word_size, TRAPS) throw() {
!   MetaWord* p = Metaspace::allocate(loader_data, word_size, MetaspaceObj::ClassType, THREAD);
+   assert(is_aligned(p, KlassAlignmentInBytes),
+          "metaspace returned badly aligned memory (" PTR_FORMAT "), alignment required: %u",
+          p2i(p), (unsigned)KlassAlignmentInBytes);
+   return p;
+ }
+ 
+ static markWord make_prototype(Klass* kls) {
+   markWord prototype = markWord::prototype();
+ #ifdef _LP64
+   if (UseCompactObjectHeaders) {
+     prototype = prototype.set_klass(kls);
+   }
+ #endif
+   return prototype;
  }
  
  // "Normal" instantiation is preceded 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.
  Klass::Klass(KlassKind kind) : _kind(kind),
+                            _prototype_header(make_prototype(this)),
                             _shared_class_path_index(-1) {
    CDS_ONLY(_shared_class_flags = 0;)
    CDS_JAVA_HEAP_ONLY(_archived_mirror_index = -1;)
    _primary_supers[0] = this;
    set_super_check_offset(in_bytes(primary_supers_offset()));

*** 742,10 ***
--- 759,14 ---
  
    if (WizardMode) {
       // print header
       obj->mark().print_on(st);
       st->cr();
+      if (UseCompactObjectHeaders) {
+        st->print(BULLET"prototype_header: " INTPTR_FORMAT, _prototype_header.value());
+        st->cr();
+      }
    }
  
    // print class
    st->print(BULLET"klass: ");
    obj->klass()->print_value_on(st);

*** 765,10 ***
--- 786,14 ---
  
    // This can be expensive, but it is worth checking that this klass is actually
    // in the CLD graph but not in production.
    assert(Metaspace::contains((address)this), "Should be");
  
+   if (UseCompressedClassPointers) {
+     assert(is_aligned(this, KlassAlignmentInBytes), "misaligned Klass structure");
+   }
+ 
    guarantee(this->is_klass(),"should be klass");
  
    if (super() != nullptr) {
      guarantee(super()->is_klass(), "should be klass");
    }
< prev index next >