< prev index next >

src/hotspot/share/jfr/leakprofiler/checkpoint/eventEmitter.cpp

Print this page

  1 /*
  2  * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 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  *

103       }
104       current = prev;
105     }
106   }
107   return count;
108 }
109 
110 static int array_size(const oop object) {
111   assert(object != NULL, "invariant");
112   if (object->is_array()) {
113     return arrayOop(object)->length();
114   }
115   return min_jint;
116 }
117 
118 void EventEmitter::link_sample_with_edge(const ObjectSample* sample, EdgeStore* edge_store) {
119   assert(sample != NULL, "invariant");
120   assert(!sample->is_dead(), "invariant");
121   assert(edge_store != NULL, "invariant");
122   if (SafepointSynchronize::is_at_safepoint()) {
123     if (!sample->object()->mark().is_marked()) {
124       // Associated with an edge (chain) already during heap traversal.
125       return;
126     }
127   }
128   // In order to dump out a representation of the event
129   // even though the sample object was found not reachable / too long to reach,
130   // we need to register a top level edge.
131   edge_store->put(UnifiedOopRef::encode_in_native(sample->object_addr()));
132 }
133 
134 void EventEmitter::write_event(const ObjectSample* sample, EdgeStore* edge_store) {
135   assert(sample != NULL, "invariant");
136   assert(!sample->is_dead(), "invariant");
137   assert(edge_store != NULL, "invariant");
138   assert(_jfr_thread_local != NULL, "invariant");
139 
140   traceid gc_root_id = 0;
141   const Edge* edge = NULL;
142   if (SafepointSynchronize::is_at_safepoint()) {
143     if (!sample->object()->mark().is_marked()) {
144       edge = (const Edge*)(sample->object())->mark().to_pointer();
145     }
146   }
147   if (edge == NULL) {
148     edge = edge_store->get(UnifiedOopRef::encode_in_native(sample->object_addr()));
149   } else {
150     gc_root_id = edge_store->gc_root_id(edge);
151   }
152   assert(edge != NULL, "invariant");

153   const traceid object_id = edge_store->get_id(edge);
154   assert(object_id != 0, "invariant");

155 
156   Tickspan object_age = Ticks(_start_time.value()) - sample->allocation_time();
157 
158   EventOldObjectSample e(UNTIMED);
159   e.set_starttime(_start_time);
160   e.set_endtime(_end_time);
161   e.set_allocationTime(sample->allocation_time());
162   e.set_objectAge(object_age);
163   e.set_lastKnownHeapUsage(sample->heap_used_at_last_gc());
164   e.set_object(object_id);
165   e.set_arrayElements(array_size(edge->pointee()));
166   e.set_root(gc_root_id);
167 
168   // Temporarily assigning both the stack trace id and thread id
169   // onto the thread local data structure of the emitter thread (for the duration
170   // of the commit() call). This trick provides a means to override
171   // the event generation mechanism by injecting externally provided id's.
172   // At this particular location, it allows us to emit an old object event
173   // supplying information from where the actual sampling occurred.
174   _jfr_thread_local->set_cached_stack_trace_id(sample->stack_trace_id());

  1 /*
  2  * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 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  *

103       }
104       current = prev;
105     }
106   }
107   return count;
108 }
109 
110 static int array_size(const oop object) {
111   assert(object != NULL, "invariant");
112   if (object->is_array()) {
113     return arrayOop(object)->length();
114   }
115   return min_jint;
116 }
117 
118 void EventEmitter::link_sample_with_edge(const ObjectSample* sample, EdgeStore* edge_store) {
119   assert(sample != NULL, "invariant");
120   assert(!sample->is_dead(), "invariant");
121   assert(edge_store != NULL, "invariant");
122   if (SafepointSynchronize::is_at_safepoint()) {
123     if (edge_store->has_leak_context(sample)) {
124       // Associated with an edge (chain) already during heap traversal.
125       return;
126     }
127   }
128   // In order to dump out a representation of the event
129   // even though the sample object was found not reachable / too long to reach,
130   // we need to register a top level edge.
131   edge_store->put(UnifiedOopRef::encode_in_native(sample->object_addr()));
132 }
133 
134 void EventEmitter::write_event(const ObjectSample* sample, EdgeStore* edge_store) {
135   assert(sample != NULL, "invariant");
136   assert(!sample->is_dead(), "invariant");
137   assert(edge_store != NULL, "invariant");
138   assert(_jfr_thread_local != NULL, "invariant");
139 
140   const StoredEdge* const edge = edge_store->get(sample);











141   assert(edge != NULL, "invariant");
142   assert(edge->pointee() == sample->object(), "invariant");
143   const traceid object_id = edge_store->get_id(edge);
144   assert(object_id != 0, "invariant");
145   const traceid gc_root_id = edge->gc_root_id();
146 
147   Tickspan object_age = Ticks(_start_time.value()) - sample->allocation_time();
148 
149   EventOldObjectSample e(UNTIMED);
150   e.set_starttime(_start_time);
151   e.set_endtime(_end_time);
152   e.set_allocationTime(sample->allocation_time());
153   e.set_objectAge(object_age);
154   e.set_lastKnownHeapUsage(sample->heap_used_at_last_gc());
155   e.set_object(object_id);
156   e.set_arrayElements(array_size(edge->pointee()));
157   e.set_root(gc_root_id);
158 
159   // Temporarily assigning both the stack trace id and thread id
160   // onto the thread local data structure of the emitter thread (for the duration
161   // of the commit() call). This trick provides a means to override
162   // the event generation mechanism by injecting externally provided id's.
163   // At this particular location, it allows us to emit an old object event
164   // supplying information from where the actual sampling occurred.
165   _jfr_thread_local->set_cached_stack_trace_id(sample->stack_trace_id());
< prev index next >