200 // first collect all the code blobs
201 {
202 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
203 collector.collect();
204 }
205
206 // iterate over the collected list and post an event for each blob
207 JvmtiCodeBlobDesc* blob = collector.first();
208 while (blob != NULL) {
209 JvmtiExport::post_dynamic_code_generated(env, blob->name(), blob->code_begin(), blob->code_end());
210 blob = collector.next();
211 }
212 return JVMTI_ERROR_NONE;
213 }
214
215
216 // Support class to describe a nmethod in the CodeCache
217
218 class nmethodDesc: public CHeapObj {
219 private:
220 methodHandle _method;
221 address _code_begin;
222 address _code_end;
223 jvmtiAddrLocationMap* _map;
224 jint _map_length;
225 public:
226 nmethodDesc(methodHandle method, address code_begin, address code_end,
227 jvmtiAddrLocationMap* map, jint map_length) {
228 _method = method;
229 _code_begin = code_begin;
230 _code_end = code_end;
231 _map = map;
232 _map_length = map_length;
233 }
234 methodHandle method() const { return _method; }
235 address code_begin() const { return _code_begin; }
236 address code_end() const { return _code_end; }
237 jvmtiAddrLocationMap* map() const { return _map; }
238 jint map_length() const { return _map_length; }
239 };
240
241
242 // Support class to collect a list of the nmethod CodeBlobs in
243 // the CodeCache.
244 //
245 // Usage :-
246 //
247 // nmethodCollector collector;
248 //
249 // collector.collect();
250 // JvmtiCodeBlobDesc* blob = collector.first();
251 // while (blob != NULL) {
252 // :
253 // blob = collector.next();
254 // }
306
307
308 // called for each nmethod in the CodeCache
309 //
310 // This function simply adds a descriptor for each nmethod to the global list.
311
312 void nmethodCollector::do_nmethod(nmethod* nm) {
313 // ignore zombies
314 if (!nm->is_alive()) {
315 return;
316 }
317
318 assert(nm->method() != NULL, "checking");
319
320 // create the location map for the nmethod.
321 jvmtiAddrLocationMap* map;
322 jint map_length;
323 JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nm, &map, &map_length);
324
325 // record the nmethod details
326 methodHandle mh(nm->method());
327 nmethodDesc* snm = new nmethodDesc(mh,
328 nm->code_begin(),
329 nm->code_end(),
330 map,
331 map_length);
332 _global_nmethods->append(snm);
333 }
334
335 // collects a list of nmethod in the CodeCache.
336 //
337 // The created list is growable array of nmethodDesc - each one describes
338 // a nmethod and includs its JVMTI address location map.
339
340 void nmethodCollector::collect() {
341 assert_locked_or_safepoint(CodeCache_lock);
342 assert(_global_nmethods == NULL, "checking");
343
344 // create the list
345 _global_nmethods = new (ResourceObj::C_HEAP) GrowableArray<nmethodDesc*>(100,true);
346
347 // any a descriptor for each nmethod to the list.
350 // make the list the instance list
351 _nmethods = _global_nmethods;
352 _global_nmethods = NULL;
353 }
354
355 // Generate a COMPILED_METHOD_LOAD event for each nnmethod
356
357 jvmtiError JvmtiCodeBlobEvents::generate_compiled_method_load_events(JvmtiEnv* env) {
358 HandleMark hm;
359 nmethodCollector collector;
360
361 // first collect all nmethods
362 {
363 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
364 collector.collect();
365 }
366
367 // iterate over the list and post an event for each nmethod
368 nmethodDesc* nm_desc = collector.first();
369 while (nm_desc != NULL) {
370 methodOop method = nm_desc->method()();
371 jmethodID mid = method->jmethod_id();
372 assert(mid != NULL, "checking");
373 JvmtiExport::post_compiled_method_load(env, mid,
374 (jint)(nm_desc->code_end() - nm_desc->code_begin()),
375 nm_desc->code_begin(), nm_desc->map_length(),
376 nm_desc->map());
377 nm_desc = collector.next();
378 }
379 return JVMTI_ERROR_NONE;
380 }
381
382
383 // create a C-heap allocated address location map for an nmethod
384 void JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nmethod *nm,
385 jvmtiAddrLocationMap** map_ptr,
386 jint *map_length_ptr)
387 {
388 ResourceMark rm;
389 jvmtiAddrLocationMap* map = NULL;
390 jint map_length = 0;
391
|
200 // first collect all the code blobs
201 {
202 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
203 collector.collect();
204 }
205
206 // iterate over the collected list and post an event for each blob
207 JvmtiCodeBlobDesc* blob = collector.first();
208 while (blob != NULL) {
209 JvmtiExport::post_dynamic_code_generated(env, blob->name(), blob->code_begin(), blob->code_end());
210 blob = collector.next();
211 }
212 return JVMTI_ERROR_NONE;
213 }
214
215
216 // Support class to describe a nmethod in the CodeCache
217
218 class nmethodDesc: public CHeapObj {
219 private:
220 jmethodID _jmethod_id;
221 address _code_begin;
222 address _code_end;
223 jvmtiAddrLocationMap* _map;
224 jint _map_length;
225 public:
226 nmethodDesc(jmethodID jmethod_id, address code_begin, address code_end,
227 jvmtiAddrLocationMap* map, jint map_length) {
228 _jmethod_id = jmethod_id;
229 _code_begin = code_begin;
230 _code_end = code_end;
231 _map = map;
232 _map_length = map_length;
233 }
234 jmethodID jmethod_id() const { return _jmethod_id; }
235 address code_begin() const { return _code_begin; }
236 address code_end() const { return _code_end; }
237 jvmtiAddrLocationMap* map() const { return _map; }
238 jint map_length() const { return _map_length; }
239 };
240
241
242 // Support class to collect a list of the nmethod CodeBlobs in
243 // the CodeCache.
244 //
245 // Usage :-
246 //
247 // nmethodCollector collector;
248 //
249 // collector.collect();
250 // JvmtiCodeBlobDesc* blob = collector.first();
251 // while (blob != NULL) {
252 // :
253 // blob = collector.next();
254 // }
306
307
308 // called for each nmethod in the CodeCache
309 //
310 // This function simply adds a descriptor for each nmethod to the global list.
311
312 void nmethodCollector::do_nmethod(nmethod* nm) {
313 // ignore zombies
314 if (!nm->is_alive()) {
315 return;
316 }
317
318 assert(nm->method() != NULL, "checking");
319
320 // create the location map for the nmethod.
321 jvmtiAddrLocationMap* map;
322 jint map_length;
323 JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nm, &map, &map_length);
324
325 // record the nmethod details
326 nmethodDesc* snm = new nmethodDesc(nm->get_and_cache_jmethod_id(),
327 nm->code_begin(),
328 nm->code_end(),
329 map,
330 map_length);
331 _global_nmethods->append(snm);
332 }
333
334 // collects a list of nmethod in the CodeCache.
335 //
336 // The created list is growable array of nmethodDesc - each one describes
337 // a nmethod and includs its JVMTI address location map.
338
339 void nmethodCollector::collect() {
340 assert_locked_or_safepoint(CodeCache_lock);
341 assert(_global_nmethods == NULL, "checking");
342
343 // create the list
344 _global_nmethods = new (ResourceObj::C_HEAP) GrowableArray<nmethodDesc*>(100,true);
345
346 // any a descriptor for each nmethod to the list.
349 // make the list the instance list
350 _nmethods = _global_nmethods;
351 _global_nmethods = NULL;
352 }
353
354 // Generate a COMPILED_METHOD_LOAD event for each nnmethod
355
356 jvmtiError JvmtiCodeBlobEvents::generate_compiled_method_load_events(JvmtiEnv* env) {
357 HandleMark hm;
358 nmethodCollector collector;
359
360 // first collect all nmethods
361 {
362 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
363 collector.collect();
364 }
365
366 // iterate over the list and post an event for each nmethod
367 nmethodDesc* nm_desc = collector.first();
368 while (nm_desc != NULL) {
369 jmethodID mid = nm_desc->jmethod_id();
370 assert(mid != NULL, "checking");
371 JvmtiExport::post_compiled_method_load(env, mid,
372 (jint)(nm_desc->code_end() - nm_desc->code_begin()),
373 nm_desc->code_begin(), nm_desc->map_length(),
374 nm_desc->map());
375 nm_desc = collector.next();
376 }
377 return JVMTI_ERROR_NONE;
378 }
379
380
381 // create a C-heap allocated address location map for an nmethod
382 void JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nmethod *nm,
383 jvmtiAddrLocationMap** map_ptr,
384 jint *map_length_ptr)
385 {
386 ResourceMark rm;
387 jvmtiAddrLocationMap* map = NULL;
388 jint map_length = 0;
389
|