hotspot/agent/src/share/classes/sun/jvm/hotspot/code/CodeBlob.java
author twisti
Thu, 20 May 2010 06:34:23 -0700
changeset 5686 5435e77aa3df
parent 1 489c9b5090e2
child 5702 201c5cde25bb
permissions -rw-r--r--
6951083: oops and relocations should part of nmethod not CodeBlob Summary: This moves the oops from Codeblob to nmethod. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
     2
 * Copyright 2000-2010 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.asm.x86.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.compiler.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
public class CodeBlob extends VMObject {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  private static AddressField  nameField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  private static CIntegerField sizeField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  private static CIntegerField headerSizeField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  private static CIntegerField relocationSizeField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  private static CIntegerField instructionsOffsetField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  private static CIntegerField frameCompleteOffsetField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  private static CIntegerField dataOffsetField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  private static CIntegerField frameSizeField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  private static AddressField  oopMapsField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // Only used by server compiler on x86; computed over in SA rather
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // than relying on computation in target VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  private static final int     NOT_YET_COMPUTED = -2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  private static final int     UNDEFINED        = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  private              int     linkOffset       = NOT_YET_COMPUTED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  private static       int     matcherInterpreterFramePointerReg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  private static void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    Type type = db.lookupType("CodeBlob");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    nameField                = type.getAddressField("_name");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    sizeField                = type.getCIntegerField("_size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    headerSizeField          = type.getCIntegerField("_header_size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    relocationSizeField      = type.getCIntegerField("_relocation_size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    frameCompleteOffsetField = type.getCIntegerField("_frame_complete_offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    instructionsOffsetField  = type.getCIntegerField("_instructions_offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    dataOffsetField          = type.getCIntegerField("_data_offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    frameSizeField           = type.getCIntegerField("_frame_size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    oopMapsField             = type.getAddressField("_oop_maps");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    if (VM.getVM().isServerCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      matcherInterpreterFramePointerReg =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
        db.lookupIntConstant("Matcher::interpreter_frame_pointer_reg").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  public CodeBlob(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    super(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // Typing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  public boolean isBufferBlob()         { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  public boolean isNMethod()            { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  public boolean isRuntimeStub()        { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  public boolean isDeoptimizationStub() { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  public boolean isUncommonTrapStub()   { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  public boolean isExceptionStub()      { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  public boolean isSafepointStub()      { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Fine grain nmethod support: isNmethod() == isJavaMethod() || isNativeMethod() || isOSRMethod()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  public boolean isJavaMethod()         { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  public boolean isNativeMethod()       { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  /** On-Stack Replacement method */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  public boolean isOSRMethod()          { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // Boundaries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  public Address headerBegin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    return addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  public Address headerEnd() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    return addr.addOffsetTo(headerSizeField.getValue(addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // FIXME: add RelocInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  //  public RelocInfo relocationBegin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  //  public RelocInfo relocationEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  public Address instructionsBegin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    return headerBegin().addOffsetTo(instructionsOffsetField.getValue(addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  public Address instructionsEnd() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    return headerBegin().addOffsetTo(dataOffsetField.getValue(addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  public Address dataBegin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    return headerBegin().addOffsetTo(dataOffsetField.getValue(addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  public Address dataEnd() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    return headerBegin().addOffsetTo(sizeField.getValue(addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Offsets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  public int getRelocationOffset()   { return (int) headerSizeField.getValue(addr);         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  public int getInstructionsOffset() { return (int) instructionsOffsetField.getValue(addr); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  public int getDataOffset()         { return (int) dataOffsetField.getValue(addr);         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // Sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  public int getSize()             { return (int) sizeField.getValue(addr);                     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  public int getHeaderSize()       { return (int) headerSizeField.getValue(addr);               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  // FIXME: add getRelocationSize()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  public int getInstructionsSize() { return (int) instructionsEnd().minus(instructionsBegin()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  public int getDataSize()         { return (int) dataEnd().minus(dataBegin());                 }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // Containment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  public boolean blobContains(Address addr)         { return headerBegin().lessThanOrEqual(addr) && dataEnd().greaterThan(addr);               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // FIXME: add relocationContains
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  public boolean instructionsContains(Address addr) { return instructionsBegin().lessThanOrEqual(addr) && instructionsEnd().greaterThan(addr); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  public boolean dataContains(Address addr)         { return dataBegin().lessThanOrEqual(addr) && dataEnd().greaterThan(addr);                 }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  public boolean contains(Address addr)             { return instructionsContains(addr);                                                       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  public boolean isFrameCompleteAt(Address a)       { return instructionsContains(a) && a.minus(instructionsBegin()) >= frameCompleteOffsetField.getValue(addr); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Reclamation support (really only used by the nmethods, but in order to get asserts to work
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // in the CodeCache they are defined virtual here)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  public boolean isZombie()             { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  public boolean isLockedByVM()         { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  /** OopMap for frame; can return null if none available */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  public OopMapSet getOopMaps() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    Address oopMapsAddr = oopMapsField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    if (oopMapsAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    return new OopMapSet(oopMapsAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  //  void set_oop_maps(OopMapSet* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  public OopMap getOopMapForReturnAddress(Address returnAddress, boolean debugging) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    Address pc = returnAddress;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      Assert.that(getOopMaps() != null, "nope");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    return getOopMaps().findMapAtOffset(pc.minus(instructionsBegin()), debugging);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  //  virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, void f(oop*)) { ShouldNotReachHere(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  //  FIXME;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  /** NOTE: this returns a size in BYTES in this system! */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  public long getFrameSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    return VM.getVM().getAddressSize() * frameSizeField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // Returns true, if the next frame is responsible for GC'ing oops passed as arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  public boolean callerMustGCArguments(JavaThread thread) { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  public String getName() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    return CStringUtilities.getString(nameField.getValue(addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // FIXME: NOT FINISHED
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // FIXME: add more accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  public void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    printOn(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  public void printOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    tty.print(getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    printComponentsOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  protected void printComponentsOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    tty.println(" instructions: [" + instructionsBegin() + ", " + instructionsEnd() + "), " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
                " data: [" + dataBegin() + ", " + dataEnd() + "), " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                " frame size: " + getFrameSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
}