agent/src/share/classes/sun/jvm/hotspot/code/NMethod.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6892186 Sdiff agent/src/share/classes/sun/jvm/hotspot/code

agent/src/share/classes/sun/jvm/hotspot/code/NMethod.java

Print this page




  25 package sun.jvm.hotspot.code;
  26 
  27 import java.io.*;
  28 import java.util.*;
  29 import sun.jvm.hotspot.debugger.*;
  30 import sun.jvm.hotspot.memory.*;
  31 import sun.jvm.hotspot.oops.*;
  32 import sun.jvm.hotspot.runtime.*;
  33 import sun.jvm.hotspot.types.*;
  34 import sun.jvm.hotspot.utilities.*;
  35 
  36 public class NMethod extends CodeBlob {
  37   private static long          pcDescSize;
  38   private static CIntegerField zombieInstructionSizeField;
  39   private static sun.jvm.hotspot.types.OopField methodField;
  40   /** != InvocationEntryBci if this nmethod is an on-stack replacement method */
  41   private static CIntegerField entryBCIField;
  42   /** To support simple linked-list chaining of nmethods */
  43   private static AddressField  osrLinkField;
  44   private static AddressField  scavengeRootLinkField;
  45   private static CIntegerField scavengeRootStateField;
  46 
  47   /** Offsets for different nmethod parts */
  48   private static CIntegerField exceptionOffsetField;
  49   private static CIntegerField deoptOffsetField;
  50   private static CIntegerField origPCOffsetField;
  51   private static CIntegerField stubOffsetField;
  52   private static CIntegerField scopesDataOffsetField;
  53   private static CIntegerField scopesPCsOffsetField;
  54   private static CIntegerField dependenciesOffsetField;
  55   private static CIntegerField handlerTableOffsetField;
  56   private static CIntegerField nulChkTableOffsetField;
  57   private static CIntegerField nmethodEndOffsetField;
  58 
  59   /** Offsets for entry points */
  60   /** Entry point with class check */
  61   private static AddressField  entryPointField;
  62   /** Entry point without class check */
  63   private static AddressField  verifiedEntryPointField;
  64   /** Entry point for on stack replacement */
  65   private static AddressField  osrEntryPointField;


  75       more activations, i.e., when the _stack_traversal_mark is less than
  76       current sweep traversal index. */
  77   private static CIntegerField stackTraversalMarkField;
  78 
  79   static {
  80     VM.registerVMInitializedObserver(new Observer() {
  81         public void update(Observable o, Object data) {
  82           initialize(VM.getVM().getTypeDataBase());
  83         }
  84       });
  85   }
  86 
  87   private static void initialize(TypeDataBase db) {
  88     Type type = db.lookupType("nmethod");
  89 
  90     zombieInstructionSizeField  = type.getCIntegerField("_zombie_instruction_size");
  91     methodField                 = type.getOopField("_method");
  92     entryBCIField               = type.getCIntegerField("_entry_bci");
  93     osrLinkField                = type.getAddressField("_osr_link");
  94     scavengeRootLinkField       = type.getAddressField("_scavenge_root_link");
  95     scavengeRootStateField      = type.getCIntegerField("_scavenge_root_state");
  96 
  97     exceptionOffsetField        = type.getCIntegerField("_exception_offset");
  98     deoptOffsetField            = type.getCIntegerField("_deoptimize_offset");
  99     origPCOffsetField           = type.getCIntegerField("_orig_pc_offset");
 100     stubOffsetField             = type.getCIntegerField("_stub_offset");
 101     scopesDataOffsetField       = type.getCIntegerField("_scopes_data_offset");
 102     scopesPCsOffsetField        = type.getCIntegerField("_scopes_pcs_offset");
 103     dependenciesOffsetField     = type.getCIntegerField("_dependencies_offset");
 104     handlerTableOffsetField     = type.getCIntegerField("_handler_table_offset");
 105     nulChkTableOffsetField      = type.getCIntegerField("_nul_chk_table_offset");
 106     nmethodEndOffsetField       = type.getCIntegerField("_nmethod_end_offset");
 107     entryPointField             = type.getAddressField("_entry_point");
 108     verifiedEntryPointField     = type.getAddressField("_verified_entry_point");
 109     osrEntryPointField          = type.getAddressField("_osr_entry_point");
 110     lockCountField              = type.getJIntField("_lock_count");
 111     stackTraversalMarkField     = type.getCIntegerField("_stack_traversal_mark");
 112 
 113     pcDescSize = db.lookupType("PcDesc").getSize();
 114   }
 115 


 257   //  void adjust_pointers();
 258 
 259   /** Finds a PCDesc with real-pc equal to "pc" */
 260   public PCDesc getPCDescAt(Address pc) {
 261     // FIXME: consider adding cache like the one down in the VM
 262     for (Address p = scopesPCsBegin(); p.lessThan(scopesPCsEnd()); p = p.addOffsetTo(pcDescSize)) {
 263       PCDesc pcDesc = new PCDesc(p);
 264       if (pcDesc.getRealPC(this).equals(pc)) {
 265         return pcDesc;
 266       }
 267     }
 268     return null;
 269   }
 270 
 271   /** ScopeDesc for an instruction */
 272   public ScopeDesc getScopeDescAt(Address pc) {
 273     PCDesc pd = getPCDescAt(pc);
 274     if (Assert.ASSERTS_ENABLED) {
 275       Assert.that(pd != null, "scope must be present");
 276     }
 277     return new ScopeDesc(this, pd.getScopeDecodeOffset(), pd.getReexecute());
 278   }
 279 
 280   /** This is only for use by the debugging system, and is only
 281       intended for use in the topmost frame, where we are not
 282       guaranteed to be at a PC for which we have a PCDesc. It finds
 283       the PCDesc with realPC closest to the current PC. */
 284   public PCDesc getPCDescNearDbg(Address pc) {
 285     PCDesc bestGuessPCDesc = null;
 286     long bestDistance = 0;
 287     for (Address p = scopesPCsBegin(); p.lessThan(scopesPCsEnd()); p = p.addOffsetTo(pcDescSize)) {
 288       PCDesc pcDesc = new PCDesc(p);
 289       // In case pc is null
 290       long distance = -pcDesc.getRealPC(this).minus(pc);
 291       if ((bestGuessPCDesc == null) ||
 292           ((distance >= 0) && (distance < bestDistance))) {
 293         bestGuessPCDesc = pcDesc;
 294         bestDistance    = distance;
 295       }
 296     }
 297     return bestGuessPCDesc;
 298   }
 299 
 300   /** This is only for use by the debugging system, and is only
 301       intended for use in the topmost frame, where we are not
 302       guaranteed to be at a PC for which we have a PCDesc. It finds
 303       the ScopeDesc closest to the current PC. NOTE that this may
 304       return NULL for compiled methods which don't have any
 305       ScopeDescs! */
 306   public ScopeDesc getScopeDescNearDbg(Address pc) {
 307     PCDesc pd = getPCDescNearDbg(pc);
 308     if (pd == null) return null;
 309     return new ScopeDesc(this, pd.getScopeDecodeOffset(), pd.getReexecute());
 310   }
 311 
 312   public Map/*<Address, PcDesc>*/ getSafepoints() {
 313     Map safepoints = new HashMap(); // Map<Address, PcDesc>
 314     sun.jvm.hotspot.debugger.Address p = null;
 315     for (p = scopesPCsBegin(); p.lessThan(scopesPCsEnd());
 316          p = p.addOffsetTo(pcDescSize)) {
 317        PCDesc pcDesc = new PCDesc(p);
 318        sun.jvm.hotspot.debugger.Address pc = pcDesc.getRealPC(this);
 319        safepoints.put(pc, pcDesc);
 320     }
 321     return safepoints;
 322   }
 323 
 324   // FIXME: add getPCOffsetForBCI()
 325   // FIXME: add embeddedOopAt()
 326   // FIXME: add isDependentOn()
 327   // FIXME: add isPatchableAt()
 328 
 329   /** Support for code generation. Only here for proof-of-concept. */
 330   public static int getEntryPointOffset()            { return (int) entryPointField.getOffset();            }
 331   public static int getVerifiedEntryPointOffset()    { return (int) verifiedEntryPointField.getOffset();    }
 332   public static int getOSREntryPointOffset()         { return (int) osrEntryPointField.getOffset();         }
 333   public static int getEntryBCIOffset()              { return (int) entryBCIField.getOffset();              }




  25 package sun.jvm.hotspot.code;
  26 
  27 import java.io.*;
  28 import java.util.*;
  29 import sun.jvm.hotspot.debugger.*;
  30 import sun.jvm.hotspot.memory.*;
  31 import sun.jvm.hotspot.oops.*;
  32 import sun.jvm.hotspot.runtime.*;
  33 import sun.jvm.hotspot.types.*;
  34 import sun.jvm.hotspot.utilities.*;
  35 
  36 public class NMethod extends CodeBlob {
  37   private static long          pcDescSize;
  38   private static CIntegerField zombieInstructionSizeField;
  39   private static sun.jvm.hotspot.types.OopField methodField;
  40   /** != InvocationEntryBci if this nmethod is an on-stack replacement method */
  41   private static CIntegerField entryBCIField;
  42   /** To support simple linked-list chaining of nmethods */
  43   private static AddressField  osrLinkField;
  44   private static AddressField  scavengeRootLinkField;
  45   private static JByteField    scavengeRootStateField;
  46 
  47   /** Offsets for different nmethod parts */
  48   private static CIntegerField exceptionOffsetField;
  49   private static CIntegerField deoptOffsetField;
  50   private static CIntegerField origPCOffsetField;
  51   private static CIntegerField stubOffsetField;
  52   private static CIntegerField scopesDataOffsetField;
  53   private static CIntegerField scopesPCsOffsetField;
  54   private static CIntegerField dependenciesOffsetField;
  55   private static CIntegerField handlerTableOffsetField;
  56   private static CIntegerField nulChkTableOffsetField;
  57   private static CIntegerField nmethodEndOffsetField;
  58 
  59   /** Offsets for entry points */
  60   /** Entry point with class check */
  61   private static AddressField  entryPointField;
  62   /** Entry point without class check */
  63   private static AddressField  verifiedEntryPointField;
  64   /** Entry point for on stack replacement */
  65   private static AddressField  osrEntryPointField;


  75       more activations, i.e., when the _stack_traversal_mark is less than
  76       current sweep traversal index. */
  77   private static CIntegerField stackTraversalMarkField;
  78 
  79   static {
  80     VM.registerVMInitializedObserver(new Observer() {
  81         public void update(Observable o, Object data) {
  82           initialize(VM.getVM().getTypeDataBase());
  83         }
  84       });
  85   }
  86 
  87   private static void initialize(TypeDataBase db) {
  88     Type type = db.lookupType("nmethod");
  89 
  90     zombieInstructionSizeField  = type.getCIntegerField("_zombie_instruction_size");
  91     methodField                 = type.getOopField("_method");
  92     entryBCIField               = type.getCIntegerField("_entry_bci");
  93     osrLinkField                = type.getAddressField("_osr_link");
  94     scavengeRootLinkField       = type.getAddressField("_scavenge_root_link");
  95     scavengeRootStateField      = type.getJByteField("_scavenge_root_state");
  96 
  97     exceptionOffsetField        = type.getCIntegerField("_exception_offset");
  98     deoptOffsetField            = type.getCIntegerField("_deoptimize_offset");
  99     origPCOffsetField           = type.getCIntegerField("_orig_pc_offset");
 100     stubOffsetField             = type.getCIntegerField("_stub_offset");
 101     scopesDataOffsetField       = type.getCIntegerField("_scopes_data_offset");
 102     scopesPCsOffsetField        = type.getCIntegerField("_scopes_pcs_offset");
 103     dependenciesOffsetField     = type.getCIntegerField("_dependencies_offset");
 104     handlerTableOffsetField     = type.getCIntegerField("_handler_table_offset");
 105     nulChkTableOffsetField      = type.getCIntegerField("_nul_chk_table_offset");
 106     nmethodEndOffsetField       = type.getCIntegerField("_nmethod_end_offset");
 107     entryPointField             = type.getAddressField("_entry_point");
 108     verifiedEntryPointField     = type.getAddressField("_verified_entry_point");
 109     osrEntryPointField          = type.getAddressField("_osr_entry_point");
 110     lockCountField              = type.getJIntField("_lock_count");
 111     stackTraversalMarkField     = type.getCIntegerField("_stack_traversal_mark");
 112 
 113     pcDescSize = db.lookupType("PcDesc").getSize();
 114   }
 115 


 257   //  void adjust_pointers();
 258 
 259   /** Finds a PCDesc with real-pc equal to "pc" */
 260   public PCDesc getPCDescAt(Address pc) {
 261     // FIXME: consider adding cache like the one down in the VM
 262     for (Address p = scopesPCsBegin(); p.lessThan(scopesPCsEnd()); p = p.addOffsetTo(pcDescSize)) {
 263       PCDesc pcDesc = new PCDesc(p);
 264       if (pcDesc.getRealPC(this).equals(pc)) {
 265         return pcDesc;
 266       }
 267     }
 268     return null;
 269   }
 270 
 271   /** ScopeDesc for an instruction */
 272   public ScopeDesc getScopeDescAt(Address pc) {
 273     PCDesc pd = getPCDescAt(pc);
 274     if (Assert.ASSERTS_ENABLED) {
 275       Assert.that(pd != null, "scope must be present");
 276     }
 277     return new ScopeDesc(this, pd.getScopeDecodeOffset(), pd.getObjDecodeOffset(), pd.getReexecute());
 278   }
 279 
 280   /** This is only for use by the debugging system, and is only
 281       intended for use in the topmost frame, where we are not
 282       guaranteed to be at a PC for which we have a PCDesc. It finds
 283       the PCDesc with realPC closest to the current PC. */
 284   public PCDesc getPCDescNearDbg(Address pc) {
 285     PCDesc bestGuessPCDesc = null;
 286     long bestDistance = 0;
 287     for (Address p = scopesPCsBegin(); p.lessThan(scopesPCsEnd()); p = p.addOffsetTo(pcDescSize)) {
 288       PCDesc pcDesc = new PCDesc(p);
 289       // In case pc is null
 290       long distance = -pcDesc.getRealPC(this).minus(pc);
 291       if ((bestGuessPCDesc == null) ||
 292           ((distance >= 0) && (distance < bestDistance))) {
 293         bestGuessPCDesc = pcDesc;
 294         bestDistance    = distance;
 295       }
 296     }
 297     return bestGuessPCDesc;
 298   }
 299 
 300   /** This is only for use by the debugging system, and is only
 301       intended for use in the topmost frame, where we are not
 302       guaranteed to be at a PC for which we have a PCDesc. It finds
 303       the ScopeDesc closest to the current PC. NOTE that this may
 304       return NULL for compiled methods which don't have any
 305       ScopeDescs! */
 306   public ScopeDesc getScopeDescNearDbg(Address pc) {
 307     PCDesc pd = getPCDescNearDbg(pc);
 308     if (pd == null) return null;
 309     return new ScopeDesc(this, pd.getScopeDecodeOffset(), pd.getObjDecodeOffset(), pd.getReexecute());
 310   }
 311 
 312   public Map/*<Address, PCDesc>*/ getSafepoints() {
 313     Map safepoints = new HashMap(); // Map<Address, PCDesc>
 314     sun.jvm.hotspot.debugger.Address p = null;
 315     for (p = scopesPCsBegin(); p.lessThan(scopesPCsEnd());
 316          p = p.addOffsetTo(pcDescSize)) {
 317        PCDesc pcDesc = new PCDesc(p);
 318        sun.jvm.hotspot.debugger.Address pc = pcDesc.getRealPC(this);
 319        safepoints.put(pc, pcDesc);
 320     }
 321     return safepoints;
 322   }
 323 
 324   // FIXME: add getPCOffsetForBCI()
 325   // FIXME: add embeddedOopAt()
 326   // FIXME: add isDependentOn()
 327   // FIXME: add isPatchableAt()
 328 
 329   /** Support for code generation. Only here for proof-of-concept. */
 330   public static int getEntryPointOffset()            { return (int) entryPointField.getOffset();            }
 331   public static int getVerifiedEntryPointOffset()    { return (int) verifiedEntryPointField.getOffset();    }
 332   public static int getOSREntryPointOffset()         { return (int) osrEntryPointField.getOffset();         }
 333   public static int getEntryBCIOffset()              { return (int) entryBCIField.getOffset();              }


agent/src/share/classes/sun/jvm/hotspot/code/NMethod.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File