33 #include "oops/instanceMirrorKlass.hpp"
34 #include "oops/instanceOop.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "oops/symbol.hpp"
37 #include "runtime/handles.inline.hpp"
38 #include "utilities/macros.hpp"
39
40 int InstanceMirrorKlass::_offset_of_static_fields = 0;
41
42 int InstanceMirrorKlass::instance_size(KlassHandle k) {
43 if (k() != NULL && k->is_instance_klass()) {
44 return align_object_size(size_helper() + InstanceKlass::cast(k())->static_field_size());
45 }
46 return size_helper();
47 }
48
49 instanceOop InstanceMirrorKlass::allocate_instance(KlassHandle k, TRAPS) {
50 // Query before forming handle.
51 int size = instance_size(k);
52 KlassHandle h_k(THREAD, this);
53 instanceOop i = (instanceOop)CollectedHeap::obj_allocate(h_k, size, CHECK_NULL);
54
55 // Since mirrors can be variable sized because of the static fields, store
56 // the size in the mirror itself.
57 java_lang_Class::set_oop_size(i, size);
58
59 return i;
60 }
61
62 int InstanceMirrorKlass::oop_size(oop obj) const {
63 return java_lang_Class::oop_size(obj);
64 }
65
66 int InstanceMirrorKlass::compute_static_oop_field_count(oop obj) {
67 Klass* k = java_lang_Class::as_Klass(obj);
68 if (k != NULL && k->is_instance_klass()) {
69 return InstanceKlass::cast(k)->static_oop_field_count();
70 }
71 return 0;
72 }
|
33 #include "oops/instanceMirrorKlass.hpp"
34 #include "oops/instanceOop.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "oops/symbol.hpp"
37 #include "runtime/handles.inline.hpp"
38 #include "utilities/macros.hpp"
39
40 int InstanceMirrorKlass::_offset_of_static_fields = 0;
41
42 int InstanceMirrorKlass::instance_size(KlassHandle k) {
43 if (k() != NULL && k->is_instance_klass()) {
44 return align_object_size(size_helper() + InstanceKlass::cast(k())->static_field_size());
45 }
46 return size_helper();
47 }
48
49 instanceOop InstanceMirrorKlass::allocate_instance(KlassHandle k, TRAPS) {
50 // Query before forming handle.
51 int size = instance_size(k);
52 KlassHandle h_k(THREAD, this);
53 int field_offset = java_lang_Class::oop_size_offset();
54
55 assert(field_offset != 0, "must be set");
56 assert(size > 0, "total object size must be positive: %d", size);
57
58 instanceOop i = (instanceOop)CollectedHeap::class_allocate(h_k, size, field_offset, CHECK_NULL);
59 // oop_size is set by class_allocate() before the header is set.
60 return i;
61 }
62
63 int InstanceMirrorKlass::oop_size(oop obj) const {
64 return java_lang_Class::oop_size(obj);
65 }
66
67 int InstanceMirrorKlass::compute_static_oop_field_count(oop obj) {
68 Klass* k = java_lang_Class::as_Klass(obj);
69 if (k != NULL && k->is_instance_klass()) {
70 return InstanceKlass::cast(k)->static_oop_field_count();
71 }
72 return 0;
73 }
|