comparison agent/src/share/classes/sun/jvm/hotspot/code/NMethod.java @ 6782:5a98bf7d847b

6879063: SA should use hsdis for disassembly Summary: We should in SA to use hsdis for it like the JVM does to replace the current java based disassembler. Reviewed-by: twisti, jrose, sla Contributed-by: yumin.qi@oracle.com
author minqi
date Mon, 24 Sep 2012 12:44:00 -0700
parents da91efe96a93
children bd7a7ce2e264
comparison
equal deleted inserted replaced
6780:8440414b0fd8 6782:5a98bf7d847b
349 } 349 }
350 } 350 }
351 return bestGuessPCDesc; 351 return bestGuessPCDesc;
352 } 352 }
353 353
354 PCDesc find_pc_desc(long pc, boolean approximate) {
355 return find_pc_desc_internal(pc, approximate);
356 }
357
358 // Finds a PcDesc with real-pc equal to "pc"
359 PCDesc find_pc_desc_internal(long pc, boolean approximate) {
360 long base_address = VM.getAddressValue(codeBegin());
361 int pc_offset = (int) (pc - base_address);
362
363 // Fallback algorithm: quasi-linear search for the PcDesc
364 // Find the last pc_offset less than the given offset.
365 // The successor must be the required match, if there is a match at all.
366 // (Use a fixed radix to avoid expensive affine pointer arithmetic.)
367 Address lower = scopesPCsBegin();
368 Address upper = scopesPCsEnd();
369 upper = upper.addOffsetTo(-pcDescSize); // exclude final sentinel
370 if (lower.greaterThan(upper)) return null; // native method; no PcDescs at all
371
372 // Take giant steps at first (4096, then 256, then 16, then 1)
373 int LOG2_RADIX = 4;
374 int RADIX = (1 << LOG2_RADIX);
375 Address mid;
376 for (int step = (1 << (LOG2_RADIX*3)); step > 1; step >>= LOG2_RADIX) {
377 while ((mid = lower.addOffsetTo(step * pcDescSize)).lessThan(upper)) {
378 PCDesc m = new PCDesc(mid);
379 if (m.getPCOffset() < pc_offset) {
380 lower = mid;
381 } else {
382 upper = mid;
383 break;
384 }
385 }
386 }
387 // Sneak up on the value with a linear search of length ~16.
388 while (true) {
389 mid = lower.addOffsetTo(pcDescSize);
390 PCDesc m = new PCDesc(mid);
391 if (m.getPCOffset() < pc_offset) {
392 lower = mid;
393 } else {
394 upper = mid;
395 break;
396 }
397 }
398
399 PCDesc u = new PCDesc(upper);
400 if (match_desc(u, pc_offset, approximate)) {
401 return u;
402 } else {
403 return null;
404 }
405 }
406
407 // ScopeDesc retrieval operation
408 PCDesc pc_desc_at(long pc) { return find_pc_desc(pc, false); }
409 // pc_desc_near returns the first PCDesc at or after the givne pc.
410 PCDesc pc_desc_near(long pc) { return find_pc_desc(pc, true); }
411
412 // Return a the last scope in (begin..end]
413 public ScopeDesc scope_desc_in(long begin, long end) {
414 PCDesc p = pc_desc_near(begin+1);
415 if (p != null && VM.getAddressValue(p.getRealPC(this)) <= end) {
416 return new ScopeDesc(this, p.getScopeDecodeOffset(), p.getObjDecodeOffset(), p.getReexecute());
417 }
418 return null;
419 }
420
421 static boolean match_desc(PCDesc pc, int pc_offset, boolean approximate) {
422 if (!approximate) {
423 return pc.getPCOffset() == pc_offset;
424 } else {
425 PCDesc prev = new PCDesc(pc.getAddress().addOffsetTo(-pcDescSize));
426 return prev.getPCOffset() < pc_offset && pc_offset <= pc.getPCOffset();
427 }
428 }
429
354 /** This is only for use by the debugging system, and is only 430 /** This is only for use by the debugging system, and is only
355 intended for use in the topmost frame, where we are not 431 intended for use in the topmost frame, where we are not
356 guaranteed to be at a PC for which we have a PCDesc. It finds 432 guaranteed to be at a PC for which we have a PCDesc. It finds
357 the ScopeDesc closest to the current PC. NOTE that this may 433 the ScopeDesc closest to the current PC. NOTE that this may
358 return NULL for compiled methods which don't have any 434 return NULL for compiled methods which don't have any