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

Print this page
rev 1162 : 6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
Summary: use PcDesc to keep record of the reexecute bit instead of using DebugInfoStreams
Reviewed-by: kvn, never, twisti
rev 1220 : 6863023: need non-perm oops in code cache for JSR 292
Summary: Make a special root-list for those few nmethods which might contain non-perm oops.
Reviewed-by: twisti, kvn, never, jmasa, ysr
rev 1271 : 6892186: SA does not dump debug info for scalar replaced objects
Summary: Implement scalar replaced objects debug info dump in SA.
Reviewed-by: twisti
rev 1539 : 6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair
rev 1547 : Merge
   1 /*
   2  * Copyright 2000-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  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  linkField;



  44   /** Offsets for different nmethod parts */
  45   private static CIntegerField exceptionOffsetField;
  46   private static CIntegerField deoptOffsetField;
  47   private static CIntegerField origPCOffsetField;
  48   private static CIntegerField stubOffsetField;
  49   private static CIntegerField scopesDataOffsetField;
  50   private static CIntegerField scopesPCsOffsetField;
  51   private static CIntegerField dependenciesOffsetField;
  52   private static CIntegerField handlerTableOffsetField;
  53   private static CIntegerField nulChkTableOffsetField;
  54   private static CIntegerField nmethodEndOffsetField;
  55 
  56   /** Offsets for entry points */
  57   /** Entry point with class check */
  58   private static AddressField  entryPointField;
  59   /** Entry point without class check */
  60   private static AddressField  verifiedEntryPointField;
  61   /** Entry point for on stack replacement */
  62   private static AddressField  osrEntryPointField;
  63 


  70       this mark to current sweep invocation count if it is seen on the
  71       stack.  An not_entrant method can be removed when there is no
  72       more activations, i.e., when the _stack_traversal_mark is less than
  73       current sweep traversal index. */
  74   private static CIntegerField stackTraversalMarkField;
  75 
  76   static {
  77     VM.registerVMInitializedObserver(new Observer() {
  78         public void update(Observable o, Object data) {
  79           initialize(VM.getVM().getTypeDataBase());
  80         }
  81       });
  82   }
  83 
  84   private static void initialize(TypeDataBase db) {
  85     Type type = db.lookupType("nmethod");
  86 
  87     zombieInstructionSizeField  = type.getCIntegerField("_zombie_instruction_size");
  88     methodField                 = type.getOopField("_method");
  89     entryBCIField               = type.getCIntegerField("_entry_bci");
  90     linkField                   = type.getAddressField("_link");



  91     exceptionOffsetField        = type.getCIntegerField("_exception_offset");
  92     deoptOffsetField            = type.getCIntegerField("_deoptimize_offset");
  93     origPCOffsetField           = type.getCIntegerField("_orig_pc_offset");
  94     stubOffsetField             = type.getCIntegerField("_stub_offset");
  95     scopesDataOffsetField       = type.getCIntegerField("_scopes_data_offset");
  96     scopesPCsOffsetField        = type.getCIntegerField("_scopes_pcs_offset");
  97     dependenciesOffsetField     = type.getCIntegerField("_dependencies_offset");
  98     handlerTableOffsetField     = type.getCIntegerField("_handler_table_offset");
  99     nulChkTableOffsetField      = type.getCIntegerField("_nul_chk_table_offset");
 100     nmethodEndOffsetField       = type.getCIntegerField("_nmethod_end_offset");
 101     entryPointField             = type.getAddressField("_entry_point");
 102     verifiedEntryPointField     = type.getAddressField("_verified_entry_point");
 103     osrEntryPointField          = type.getAddressField("_osr_entry_point");
 104     lockCountField              = type.getJIntField("_lock_count");
 105     stackTraversalMarkField     = type.getCIntegerField("_stack_traversal_mark");
 106 
 107     pcDescSize = db.lookupType("PcDesc").getSize();
 108   }
 109 
 110   public NMethod(Address addr) {


 202   // public boolean isOld();
 203   // public int     age();
 204   // public boolean isMarkedForDeoptimization();
 205   // public boolean isMarkedForUnloading();
 206   // public boolean isMarkedForReclamation();
 207   // public int     level();
 208   // public int     version();
 209 
 210   // FIXME: add mutators for above
 211   // FIXME: add exception cache access?
 212 
 213   /** On-stack replacement support */
 214   // FIXME: add mutators
 215   public int getOSREntryBCI() {
 216     if (Assert.ASSERTS_ENABLED) {
 217       Assert.that(getEntryBCI() != VM.getVM().getInvocationEntryBCI(), "wrong kind of nmethod");
 218     }
 219     return getEntryBCI();
 220   }
 221 
 222   public NMethod getLink() {
 223     return (NMethod) VMObjectFactory.newObject(NMethod.class, linkField.getValue(addr));




 224   }
 225 





 226   /** Tells whether frames described by this nmethod can be
 227       deoptimized. Note: native wrappers cannot be deoptimized. */
 228   public boolean canBeDeoptimized() { return isJavaMethod(); }
 229 
 230   // FIXME: add inline cache support
 231   // FIXME: add flush()
 232 
 233   public boolean isLockedByVM() { return lockCountField.getValue(addr) > 0; }
 234 
 235   // FIXME: add mark_as_seen_on_stack
 236   // FIXME: add can_not_entrant_be_converted
 237 
 238   // FIXME: add GC support
 239   //  void follow_roots_or_mark_for_unloading(bool unloading_occurred, bool& marked_for_unloading);
 240   //  void follow_root_or_mark_for_unloading(oop* root, bool unloading_occurred, bool& marked_for_unloading);
 241   //  void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, void f(oop*));
 242   //  void adjust_pointers();
 243 
 244   /** Finds a PCDesc with real-pc equal to "pc" */
 245   public PCDesc getPCDescAt(Address pc) {
 246     // FIXME: consider adding cache like the one down in the VM
 247     for (Address p = scopesPCsBegin(); p.lessThan(scopesPCsEnd()); p = p.addOffsetTo(pcDescSize)) {
 248       PCDesc pcDesc = new PCDesc(p);
 249       if (pcDesc.getRealPC(this).equals(pc)) {
 250         return pcDesc;
 251       }
 252     }
 253     return null;
 254   }
 255 
 256   /** ScopeDesc for an instruction */
 257   public ScopeDesc getScopeDescAt(Address pc) {
 258     PCDesc pd = getPCDescAt(pc);
 259     if (Assert.ASSERTS_ENABLED) {
 260       Assert.that(pd != null, "scope must be present");
 261     }
 262     return new ScopeDesc(this, pd.getScopeDecodeOffset());
 263   }
 264 
 265   /** This is only for use by the debugging system, and is only
 266       intended for use in the topmost frame, where we are not
 267       guaranteed to be at a PC for which we have a PCDesc. It finds
 268       the PCDesc with realPC closest to the current PC. */
 269   public PCDesc getPCDescNearDbg(Address pc) {
 270     PCDesc bestGuessPCDesc = null;
 271     long bestDistance = 0;
 272     for (Address p = scopesPCsBegin(); p.lessThan(scopesPCsEnd()); p = p.addOffsetTo(pcDescSize)) {
 273       PCDesc pcDesc = new PCDesc(p);
 274       // In case pc is null
 275       long distance = -pcDesc.getRealPC(this).minus(pc);
 276       if ((bestGuessPCDesc == null) ||
 277           ((distance >= 0) && (distance < bestDistance))) {
 278         bestGuessPCDesc = pcDesc;
 279         bestDistance    = distance;
 280       }
 281     }
 282     return bestGuessPCDesc;
 283   }
 284 
 285   /** This is only for use by the debugging system, and is only
 286       intended for use in the topmost frame, where we are not
 287       guaranteed to be at a PC for which we have a PCDesc. It finds
 288       the ScopeDesc closest to the current PC. NOTE that this may
 289       return NULL for compiled methods which don't have any
 290       ScopeDescs! */
 291   public ScopeDesc getScopeDescNearDbg(Address pc) {
 292     PCDesc pd = getPCDescNearDbg(pc);
 293     if (pd == null) return null;
 294     return new ScopeDesc(this, pd.getScopeDecodeOffset());
 295   }
 296 
 297   public Map/*<Address, PcDesc>*/ getSafepoints() {
 298     Map safepoints = new HashMap(); // Map<Address, PcDesc>
 299     sun.jvm.hotspot.debugger.Address p = null;
 300     for (p = scopesPCsBegin(); p.lessThan(scopesPCsEnd());
 301          p = p.addOffsetTo(pcDescSize)) {
 302        PCDesc pcDesc = new PCDesc(p);
 303        sun.jvm.hotspot.debugger.Address pc = pcDesc.getRealPC(this);
 304        safepoints.put(pc, pcDesc);
 305     }
 306     return safepoints;
 307   }
 308 
 309   // FIXME: add getPCOffsetForBCI()
 310   // FIXME: add embeddedOopAt()
 311   // FIXME: add isDependentOn()
 312   // FIXME: add isPatchableAt()
 313 
 314   /** Support for code generation. Only here for proof-of-concept. */
 315   public static int getEntryPointOffset()            { return (int) entryPointField.getOffset();            }
 316   public static int getVerifiedEntryPointOffset()    { return (int) verifiedEntryPointField.getOffset();    }
 317   public static int getOSREntryPointOffset()         { return (int) osrEntryPointField.getOffset();         }
 318   public static int getEntryBCIOffset()              { return (int) entryBCIField.getOffset();              }


   1 /*
   2  * Copyright (c) 2000, 2009, 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,
  20  * CA 94065 USA or visit www.oracle.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  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;
  66 


  73       this mark to current sweep invocation count if it is seen on the
  74       stack.  An not_entrant method can be removed when there is no
  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 
 116   public NMethod(Address addr) {


 208   // public boolean isOld();
 209   // public int     age();
 210   // public boolean isMarkedForDeoptimization();
 211   // public boolean isMarkedForUnloading();
 212   // public boolean isMarkedForReclamation();
 213   // public int     level();
 214   // public int     version();
 215 
 216   // FIXME: add mutators for above
 217   // FIXME: add exception cache access?
 218 
 219   /** On-stack replacement support */
 220   // FIXME: add mutators
 221   public int getOSREntryBCI() {
 222     if (Assert.ASSERTS_ENABLED) {
 223       Assert.that(getEntryBCI() != VM.getVM().getInvocationEntryBCI(), "wrong kind of nmethod");
 224     }
 225     return getEntryBCI();
 226   }
 227 
 228   public NMethod getOSRLink() {
 229     return (NMethod) VMObjectFactory.newObject(NMethod.class, osrLinkField.getValue(addr));
 230   }
 231 
 232   public NMethod getScavengeRootLink() {
 233     return (NMethod) VMObjectFactory.newObject(NMethod.class, scavengeRootLinkField.getValue(addr));
 234   }
 235 
 236   public int getScavengeRootState() {
 237     return (int) scavengeRootStateField.getValue(addr);
 238   }
 239 
 240 
 241   /** Tells whether frames described by this nmethod can be
 242       deoptimized. Note: native wrappers cannot be deoptimized. */
 243   public boolean canBeDeoptimized() { return isJavaMethod(); }
 244 
 245   // FIXME: add inline cache support
 246   // FIXME: add flush()
 247 
 248   public boolean isLockedByVM() { return lockCountField.getValue(addr) > 0; }
 249 
 250   // FIXME: add mark_as_seen_on_stack
 251   // FIXME: add can_not_entrant_be_converted
 252 
 253   // FIXME: add GC support
 254   //  void follow_roots_or_mark_for_unloading(bool unloading_occurred, bool& marked_for_unloading);
 255   //  void follow_root_or_mark_for_unloading(oop* root, bool unloading_occurred, bool& marked_for_unloading);
 256   //  void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, void f(oop*));
 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();              }