39 #include "utilities/copy.hpp" |
39 #include "utilities/copy.hpp" |
40 |
40 |
41 // Inline allocation implementations. |
41 // Inline allocation implementations. |
42 |
42 |
43 void CollectedHeap::post_allocation_setup_common(KlassHandle klass, |
43 void CollectedHeap::post_allocation_setup_common(KlassHandle klass, |
44 HeapWord* obj) { |
44 HeapWord* obj_ptr) { |
45 post_allocation_setup_no_klass_install(klass, obj); |
45 post_allocation_setup_no_klass_install(klass, obj_ptr); |
46 post_allocation_install_obj_klass(klass, oop(obj)); |
46 oop obj = (oop)obj_ptr; |
|
47 #if ! INCLUDE_ALL_GCS |
|
48 obj->set_klass(klass()); |
|
49 #else |
|
50 // Need a release store to ensure array/class length, mark word, and |
|
51 // object zeroing are visible before setting the klass non-NULL, for |
|
52 // concurrent collectors. |
|
53 obj->release_set_klass(klass()); |
|
54 #endif |
47 } |
55 } |
48 |
56 |
49 void CollectedHeap::post_allocation_setup_no_klass_install(KlassHandle klass, |
57 void CollectedHeap::post_allocation_setup_no_klass_install(KlassHandle klass, |
50 HeapWord* objPtr) { |
58 HeapWord* obj_ptr) { |
51 oop obj = (oop)objPtr; |
59 oop obj = (oop)obj_ptr; |
52 |
60 |
53 assert(obj != NULL, "NULL object pointer"); |
61 assert(obj != NULL, "NULL object pointer"); |
54 if (UseBiasedLocking && (klass() != NULL)) { |
62 if (UseBiasedLocking && (klass() != NULL)) { |
55 obj->set_mark(klass->prototype_header()); |
63 obj->set_mark(klass->prototype_header()); |
56 } else { |
64 } else { |
57 // May be bootstrapping |
65 // May be bootstrapping |
58 obj->set_mark(markOopDesc::prototype()); |
66 obj->set_mark(markOopDesc::prototype()); |
59 } |
67 } |
60 } |
68 } |
61 |
69 |
62 void CollectedHeap::post_allocation_install_obj_klass(KlassHandle klass, |
|
63 oop obj) { |
|
64 // These asserts are kind of complicated because of klassKlass |
|
65 // and the beginning of the world. |
|
66 assert(klass() != NULL || !Universe::is_fully_initialized(), "NULL klass"); |
|
67 assert(klass() == NULL || klass()->is_klass(), "not a klass"); |
|
68 assert(obj != NULL, "NULL object pointer"); |
|
69 obj->set_klass(klass()); |
|
70 assert(!Universe::is_fully_initialized() || obj->klass() != NULL, |
|
71 "missing klass"); |
|
72 } |
|
73 |
|
74 // Support for jvmti and dtrace |
70 // Support for jvmti and dtrace |
75 inline void post_allocation_notify(KlassHandle klass, oop obj, int size) { |
71 inline void post_allocation_notify(KlassHandle klass, oop obj, int size) { |
76 // support low memory notifications (no-op if not enabled) |
72 // support low memory notifications (no-op if not enabled) |
77 LowMemoryDetector::detect_low_memory_for_collected_pools(); |
73 LowMemoryDetector::detect_low_memory_for_collected_pools(); |
78 |
74 |
86 } |
82 } |
87 } |
83 } |
88 } |
84 } |
89 |
85 |
90 void CollectedHeap::post_allocation_setup_obj(KlassHandle klass, |
86 void CollectedHeap::post_allocation_setup_obj(KlassHandle klass, |
91 HeapWord* obj, |
87 HeapWord* obj_ptr, |
92 int size) { |
88 int size) { |
93 post_allocation_setup_common(klass, obj); |
89 post_allocation_setup_common(klass, obj_ptr); |
|
90 oop obj = (oop)obj_ptr; |
94 assert(Universe::is_bootstrapping() || |
91 assert(Universe::is_bootstrapping() || |
95 !((oop)obj)->is_array(), "must not be an array"); |
92 !obj->is_array(), "must not be an array"); |
96 // notify jvmti and dtrace |
93 // notify jvmti and dtrace |
97 post_allocation_notify(klass, (oop)obj, size); |
94 post_allocation_notify(klass, obj, size); |
98 } |
95 } |
99 |
96 |
100 void CollectedHeap::post_allocation_setup_class(KlassHandle klass, |
97 void CollectedHeap::post_allocation_setup_class(KlassHandle klass, |
101 HeapWord* obj, |
98 HeapWord* obj_ptr, |
102 int size) { |
99 int size) { |
103 // Set oop_size field before setting the _klass field |
100 // Set oop_size field before setting the _klass field because a |
104 // in post_allocation_setup_common() because the klass field |
101 // non-NULL _klass field indicates that the object is parsable by |
105 // indicates that the object is parsable by concurrent GC. |
102 // concurrent GC. |
106 oop new_cls = (oop)obj; |
103 oop new_cls = (oop)obj_ptr; |
107 assert(size > 0, "oop_size must be positive."); |
104 assert(size > 0, "oop_size must be positive."); |
108 java_lang_Class::set_oop_size(new_cls, size); |
105 java_lang_Class::set_oop_size(new_cls, size); |
109 post_allocation_setup_common(klass, obj); |
106 post_allocation_setup_common(klass, obj_ptr); |
110 assert(Universe::is_bootstrapping() || |
107 assert(Universe::is_bootstrapping() || |
111 !new_cls->is_array(), "must not be an array"); |
108 !new_cls->is_array(), "must not be an array"); |
112 // notify jvmti and dtrace |
109 // notify jvmti and dtrace |
113 post_allocation_notify(klass, new_cls, size); |
110 post_allocation_notify(klass, new_cls, size); |
114 } |
111 } |
115 |
112 |
116 void CollectedHeap::post_allocation_setup_array(KlassHandle klass, |
113 void CollectedHeap::post_allocation_setup_array(KlassHandle klass, |
117 HeapWord* obj, |
114 HeapWord* obj_ptr, |
118 int length) { |
115 int length) { |
119 // Set array length before setting the _klass field |
116 // Set array length before setting the _klass field because a |
120 // in post_allocation_setup_common() because the klass field |
117 // non-NULL klass field indicates that the object is parsable by |
121 // indicates that the object is parsable by concurrent GC. |
118 // concurrent GC. |
122 assert(length >= 0, "length should be non-negative"); |
119 assert(length >= 0, "length should be non-negative"); |
123 ((arrayOop)obj)->set_length(length); |
120 ((arrayOop)obj_ptr)->set_length(length); |
124 post_allocation_setup_common(klass, obj); |
121 post_allocation_setup_common(klass, obj_ptr); |
125 oop new_obj = (oop)obj; |
122 oop new_obj = (oop)obj_ptr; |
126 assert(new_obj->is_array(), "must be an array"); |
123 assert(new_obj->is_array(), "must be an array"); |
127 // notify jvmti and dtrace (must be after length is set for dtrace) |
124 // notify jvmti and dtrace (must be after length is set for dtrace) |
128 post_allocation_notify(klass, new_obj, new_obj->size()); |
125 post_allocation_notify(klass, new_obj, new_obj->size()); |
129 } |
126 } |
130 |
127 |