16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_GC_SHARED_COLLECTEDHEAP_INLINE_HPP
26 #define SHARE_VM_GC_SHARED_COLLECTEDHEAP_INLINE_HPP
27
28 #include "classfile/javaClasses.hpp"
29 #include "gc/shared/allocTracer.hpp"
30 #include "gc/shared/collectedHeap.hpp"
31 #include "gc/shared/threadLocalAllocBuffer.inline.hpp"
32 #include "memory/universe.hpp"
33 #include "oops/arrayOop.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "prims/jvmtiExport.hpp"
36 #include "runtime/sharedRuntime.hpp"
37 #include "runtime/thread.inline.hpp"
38 #include "services/lowMemoryDetector.hpp"
39 #include "utilities/copy.hpp"
40
41 // Inline allocation implementations.
42
43 void CollectedHeap::post_allocation_setup_common(KlassHandle klass,
44 HeapWord* obj_ptr) {
45 post_allocation_setup_no_klass_install(klass, obj_ptr);
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
55 }
62 if (UseBiasedLocking && (klass() != NULL)) {
63 obj->set_mark(klass->prototype_header());
64 } else {
65 // May be bootstrapping
66 obj->set_mark(markOopDesc::prototype());
67 }
68 }
69
70 // Support for jvmti and dtrace
71 inline void post_allocation_notify(KlassHandle klass, oop obj, int size) {
72 // support low memory notifications (no-op if not enabled)
73 LowMemoryDetector::detect_low_memory_for_collected_pools();
74
75 // support for JVMTI VMObjectAlloc event (no-op if not enabled)
76 JvmtiExport::vm_object_alloc_event_collector(obj);
77
78 if (DTraceAllocProbes) {
79 // support for Dtrace object alloc event (no-op most of the time)
80 if (klass() != NULL && klass()->name() != NULL) {
81 SharedRuntime::dtrace_object_alloc(obj, size);
82 }
83 }
84 }
85
86 void CollectedHeap::post_allocation_setup_obj(KlassHandle klass,
87 HeapWord* obj_ptr,
88 int size) {
89 post_allocation_setup_common(klass, obj_ptr);
90 oop obj = (oop)obj_ptr;
91 assert(Universe::is_bootstrapping() ||
92 !obj->is_array(), "must not be an array");
93 // notify jvmti and dtrace
94 post_allocation_notify(klass, obj, size);
95 }
96
97 void CollectedHeap::post_allocation_setup_class(KlassHandle klass,
98 HeapWord* obj_ptr,
99 int size) {
100 // Set oop_size field before setting the _klass field because a
101 // non-NULL _klass field indicates that the object is parsable by
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_GC_SHARED_COLLECTEDHEAP_INLINE_HPP
26 #define SHARE_VM_GC_SHARED_COLLECTEDHEAP_INLINE_HPP
27
28 #include "classfile/javaClasses.hpp"
29 #include "gc/shared/allocTracer.hpp"
30 #include "gc/shared/collectedHeap.hpp"
31 #include "gc/shared/threadLocalAllocBuffer.inline.hpp"
32 #include "memory/universe.hpp"
33 #include "oops/arrayOop.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "prims/jvmtiExport.hpp"
36 #include "runtime/heapMonitoring.hpp"
37 #include "runtime/sharedRuntime.hpp"
38 #include "runtime/thread.inline.hpp"
39 #include "services/lowMemoryDetector.hpp"
40 #include "utilities/copy.hpp"
41
42 // Inline allocation implementations.
43
44 void CollectedHeap::post_allocation_setup_common(KlassHandle klass,
45 HeapWord* obj_ptr) {
46 post_allocation_setup_no_klass_install(klass, obj_ptr);
47 oop obj = (oop)obj_ptr;
48 #if ! INCLUDE_ALL_GCS
49 obj->set_klass(klass());
50 #else
51 // Need a release store to ensure array/class length, mark word, and
52 // object zeroing are visible before setting the klass non-NULL, for
53 // concurrent collectors.
54 obj->release_set_klass(klass());
55 #endif
56 }
63 if (UseBiasedLocking && (klass() != NULL)) {
64 obj->set_mark(klass->prototype_header());
65 } else {
66 // May be bootstrapping
67 obj->set_mark(markOopDesc::prototype());
68 }
69 }
70
71 // Support for jvmti and dtrace
72 inline void post_allocation_notify(KlassHandle klass, oop obj, int size) {
73 // support low memory notifications (no-op if not enabled)
74 LowMemoryDetector::detect_low_memory_for_collected_pools();
75
76 // support for JVMTI VMObjectAlloc event (no-op if not enabled)
77 JvmtiExport::vm_object_alloc_event_collector(obj);
78
79 if (DTraceAllocProbes) {
80 // support for Dtrace object alloc event (no-op most of the time)
81 if (klass() != NULL && klass()->name() != NULL) {
82 SharedRuntime::dtrace_object_alloc(obj, size);
83 }
84 }
85
86 if (HeapMonitor) {
87 // support for object alloc event (no-op most of the time)
88 if (klass() != NULL && klass()->name() != NULL) {
89 Thread *base_thread = Thread::current();
90 if (base_thread->is_Java_thread()) {
91 JavaThread *thread = (JavaThread *) base_thread;
92 size_t *bytes_until_sample = thread->bytes_until_sample();
93 size_t size_in_bytes = ((size_t) size) << LogHeapWordSize;
94 assert(size > 0, "positive size");
95 if (*bytes_until_sample < size_in_bytes) {
96 HeapMonitoring::object_alloc_do_sample(thread, obj);
97 } else {
98 *bytes_until_sample -= size_in_bytes;
99 }
100 }
101 }
102 }
103 }
104
105 void CollectedHeap::post_allocation_setup_obj(KlassHandle klass,
106 HeapWord* obj_ptr,
107 int size) {
108 post_allocation_setup_common(klass, obj_ptr);
109 oop obj = (oop)obj_ptr;
110 assert(Universe::is_bootstrapping() ||
111 !obj->is_array(), "must not be an array");
112 // notify jvmti and dtrace
113 post_allocation_notify(klass, obj, size);
114 }
115
116 void CollectedHeap::post_allocation_setup_class(KlassHandle klass,
117 HeapWord* obj_ptr,
118 int size) {
119 // Set oop_size field before setting the _klass field because a
120 // non-NULL _klass field indicates that the object is parsable by
|