hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java
author coleenp
Thu, 27 Jan 2011 16:11:27 -0800
changeset 8076 96d498ec7ae1
parent 7436 dbc43da3d512
child 9116 9bc44be338d6
child 8921 14bfe81f2a9d
permissions -rw-r--r--
6990754: Use native memory and reference counting to implement SymbolTable Summary: move symbols from permgen into C heap and reference count them Reviewed-by: never, acorn, jmasa, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
     2
 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5341
diff changeset
    21
 * questions.
1
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.oops;
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
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    34
// A ConstantPool is an oop containing class constants
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// as described in the class file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    37
public class ConstantPool extends Oop implements ClassConstants {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    38
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    39
  public class CPSlot {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    40
    private Address ptr;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    41
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    42
    CPSlot(Address ptr) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    43
      this.ptr = ptr;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    44
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    45
    CPSlot(Symbol sym) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    46
      this.ptr = sym.getAddress().orWithMask(1);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    47
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    48
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    49
    public boolean isOop() {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    50
      return (ptr.minus(null) & 1) == 0;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    51
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    52
    public boolean isMetaData() {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    53
      return (ptr.minus(null) & 1) == 1;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    54
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    55
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    56
    public Symbol getSymbol() {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    57
      if (isMetaData()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    58
        return Symbol.create(ptr.xorWithMask(1));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    59
      }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    60
      throw new InternalError("not a symbol");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    61
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    62
    public Oop getOop() {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    63
      if (isOop()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    64
        return VM.getVM().getObjectHeap().newOop(ptr.addOffsetToAsOopHandle(0));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    65
      }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    66
      throw new InternalError("not an oop");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    67
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    68
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    69
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Used for debugging this code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  private static final boolean DEBUG = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  protected void debugMessage(String message) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    System.out.println(message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    Type type   = db.lookupType("constantPoolOopDesc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    tags        = new OopField(type.getOopField("_tags"), 0);
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
    88
    operands    = new OopField(type.getOopField("_operands"), 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    cache       = new OopField(type.getOopField("_cache"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    poolHolder  = new OopField(type.getOopField("_pool_holder"), 0);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    91
    length      = new CIntField(type.getCIntegerField("_length"), 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    headerSize  = type.getSize();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    93
    elementSize = 0;
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
    94
    // fetch constants:
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
    95
    INDY_BSM_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_bsm_offset").intValue();
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
    96
    INDY_ARGC_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_argc_offset").intValue();
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
    97
    INDY_ARGV_OFFSET = db.lookupIntConstant("constantPoolOopDesc::_indy_argv_offset").intValue();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  ConstantPool(OopHandle handle, ObjectHeap heap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    super(handle, heap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  public boolean isConstantPool()      { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  private static OopField tags;
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   107
  private static OopField operands;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  private static OopField cache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  private static OopField poolHolder;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   110
  private static CIntField length; // number of elements in oop
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  private static long headerSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  private static long elementSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   115
  private static int INDY_BSM_OFFSET;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   116
  private static int INDY_ARGC_OFFSET;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   117
  private static int INDY_ARGV_OFFSET;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   118
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  public TypeArray         getTags()       { return (TypeArray)         tags.getValue(this); }
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   120
  public TypeArray         getOperands()   { return (TypeArray)         operands.getValue(this); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  public ConstantPoolCache getCache()      { return (ConstantPoolCache) cache.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  public Klass             getPoolHolder() { return (Klass)             poolHolder.getValue(this); }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   123
  public int               getLength()     { return (int)length.getValue(this); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   124
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   125
  private long getElementSize() {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   126
    if (elementSize !=0 ) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   127
      return elementSize;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   128
    } else {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   129
      elementSize = VM.getVM().getOopSize();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   130
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   131
    return elementSize;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   132
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  private long indexOffset(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    if (Assert.ASSERTS_ENABLED) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   136
      Assert.that(index > 0 && index < getLength(),  "invalid cp index " + index + " " + getLength());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   138
    return (index * getElementSize()) + headerSize;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  public ConstantTag getTagAt(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    return new ConstantTag(getTags().getByteAt((int) index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   145
  public CPSlot getSlotAt(long index) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   146
    return new CPSlot(getHandle().getAddressAt(indexOffset(index)));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   147
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   148
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   149
  public Oop getObjAtRaw(long index){
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    return getHeap().newOop(getHandle().getOopHandleAt(indexOffset(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  public Symbol getSymbolAt(long index) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   154
    CPSlot slot = getSlotAt(index);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   155
    return slot.getSymbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  public int getIntAt(long index){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    return getHandle().getJIntAt(indexOffset(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  public float getFloatAt(long index){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    return getHandle().getJFloatAt(indexOffset(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  public long getLongAt(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    int oneHalf = getHandle().getJIntAt(indexOffset(index + 1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    int otherHalf   = getHandle().getJIntAt(indexOffset(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    // buildLongFromIntsPD accepts higher address value, lower address value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    // in that order.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    return VM.getVM().buildLongFromIntsPD(oneHalf, otherHalf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  public double getDoubleAt(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    return Double.longBitsToDouble(getLongAt(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  public int getFieldOrMethodAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      System.err.print("ConstantPool.getFieldOrMethodAt(" + which + "): new index = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    int i = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    ConstantPoolCache cache = getCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    if (cache == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      i = which;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      // change byte-ordering and go via cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      i = cache.getEntryAt(0xFFFF & VM.getVM().getBytes().swapShort((short) which)).getConstantPoolIndex();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      Assert.that(getTagAt(i).isFieldOrMethod(), "Corrupted constant pool");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      System.err.println(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    int res = getIntAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      System.err.println("ConstantPool.getFieldOrMethodAt(" + i + "): result = " + res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   203
  public int[] getNameAndTypeAt(int which) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      Assert.that(getTagAt(which).isNameAndType(), "Corrupted constant pool");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    int i = getIntAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
      System.err.println("ConstantPool.getNameAndTypeAt(" + which + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   211
    return new int[] { extractLowShortFromInt(i), extractHighShortFromInt(i) };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  public Symbol getNameRefAt(int which) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   215
    int nameIndex = getNameAndTypeAt(getNameAndTypeRefIndexAt(which))[0];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    return getSymbolAt(nameIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  public Symbol getSignatureRefAt(int which) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   220
    int sigIndex = getNameAndTypeAt(getNameAndTypeRefIndexAt(which))[1];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    return getSymbolAt(sigIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  public Klass getKlassRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    if( ! getTagAt(which).isKlass()) return null;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   227
    return (Klass) getObjAtRaw(which);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  public InstanceKlass getFieldOrMethodKlassRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    int refIndex = getFieldOrMethodAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    int klassIndex = extractLowShortFromInt(refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    return (InstanceKlass) getKlassRefAt(klassIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  public Method getMethodRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    InstanceKlass klass = getFieldOrMethodKlassRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    if (klass == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    Symbol name = getNameRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    Symbol sig  = getSignatureRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    return klass.findMethod(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  public Field getFieldRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    InstanceKlass klass = getFieldOrMethodKlassRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    if (klass == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    Symbol name = getNameRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    Symbol sig  = getSignatureRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    return klass.findField(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  public int getNameAndTypeRefIndexAt(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    int refIndex = getFieldOrMethodAt(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      System.err.println("ConstantPool.getNameAndTypeRefIndexAt(" + index + "): refIndex = " + refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    int i = extractHighShortFromInt(refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      System.err.println("ConstantPool.getNameAndTypeRefIndexAt(" + index + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  /** Lookup for entries consisting of (name_index, signature_index) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  public int getNameRefIndexAt(int index) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   269
    int[] refIndex = getNameAndTypeAt(index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    if (DEBUG) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   271
      System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): refIndex = " + refIndex[0]+"/"+refIndex[1]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   273
    int i = refIndex[0];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  /** Lookup for entries consisting of (name_index, signature_index) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  public int getSignatureRefIndexAt(int index) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   282
    int[] refIndex = getNameAndTypeAt(index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    if (DEBUG) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   284
      System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): refIndex = " + refIndex[0]+"/"+refIndex[1]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   286
    int i = refIndex[1];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   293
  /** Lookup for MethodHandle entries. */
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   294
  public int getMethodHandleIndexAt(int i) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   295
    if (Assert.ASSERTS_ENABLED) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   296
      Assert.that(getTagAt(i).isMethodHandle(), "Corrupted constant pool");
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   297
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   298
    int res = extractHighShortFromInt(getIntAt(i));
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   299
    if (DEBUG) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   300
      System.err.println("ConstantPool.getMethodHandleIndexAt(" + i + "): result = " + res);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   301
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   302
    return res;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   303
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   304
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   305
  /** Lookup for MethodHandle entries. */
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   306
  public int getMethodHandleRefKindAt(int i) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   307
    if (Assert.ASSERTS_ENABLED) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   308
      Assert.that(getTagAt(i).isMethodHandle(), "Corrupted constant pool");
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   309
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   310
    int res = extractLowShortFromInt(getIntAt(i));
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   311
    if (DEBUG) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   312
      System.err.println("ConstantPool.getMethodHandleRefKindAt(" + i + "): result = " + res);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   313
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   314
    return res;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   315
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   316
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   317
  /** Lookup for MethodType entries. */
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   318
  public int getMethodTypeIndexAt(int i) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   319
    if (Assert.ASSERTS_ENABLED) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   320
      Assert.that(getTagAt(i).isMethodType(), "Corrupted constant pool");
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   321
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   322
    int res = getIntAt(i);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   323
    if (DEBUG) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   324
      System.err.println("ConstantPool.getMethodHandleTypeAt(" + i + "): result = " + res);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   325
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   326
    return res;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   327
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   328
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   329
  /** Lookup for multi-operand (InvokeDynamic) entries. */
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   330
  public short[] getBootstrapSpecifierAt(int i) {
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   331
    if (Assert.ASSERTS_ENABLED) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   332
      Assert.that(getTagAt(i).isInvokeDynamic(), "Corrupted constant pool");
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   333
    }
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   334
    if (getTagAt(i).value() == JVM_CONSTANT_InvokeDynamicTrans)
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   335
        return null;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   336
    int bsmSpec = extractLowShortFromInt(this.getIntAt(i));
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   337
    TypeArray operands = getOperands();
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   338
    if (operands == null)  return null;  // safety first
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   339
    int basePos = VM.getVM().buildIntFromShorts(operands.getShortAt(bsmSpec * 2 + 0),
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   340
                                                operands.getShortAt(bsmSpec * 2 + 1));
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   341
    int argv = basePos + INDY_ARGV_OFFSET;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   342
    int argc = operands.getShortAt(basePos + INDY_ARGC_OFFSET);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   343
    int endPos = argv + argc;
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   344
    short[] values = new short[endPos - basePos];
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   345
    for (int j = 0; j < values.length; j++) {
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   346
        values[j] = operands.getShortAt(basePos+j);
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   347
    }
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   348
    return values;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   349
  }
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   350
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  final private static String[] nameForTag = new String[] {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  private String nameForTag(int tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    switch (tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    case JVM_CONSTANT_Utf8:               return "JVM_CONSTANT_Utf8";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    case JVM_CONSTANT_Unicode:            return "JVM_CONSTANT_Unicode";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    case JVM_CONSTANT_Integer:            return "JVM_CONSTANT_Integer";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    case JVM_CONSTANT_Float:              return "JVM_CONSTANT_Float";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    case JVM_CONSTANT_Long:               return "JVM_CONSTANT_Long";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    case JVM_CONSTANT_Double:             return "JVM_CONSTANT_Double";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    case JVM_CONSTANT_Class:              return "JVM_CONSTANT_Class";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    case JVM_CONSTANT_String:             return "JVM_CONSTANT_String";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    case JVM_CONSTANT_Fieldref:           return "JVM_CONSTANT_Fieldref";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    case JVM_CONSTANT_Methodref:          return "JVM_CONSTANT_Methodref";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    case JVM_CONSTANT_InterfaceMethodref: return "JVM_CONSTANT_InterfaceMethodref";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    case JVM_CONSTANT_NameAndType:        return "JVM_CONSTANT_NameAndType";
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   368
    case JVM_CONSTANT_MethodHandle:       return "JVM_CONSTANT_MethodHandle";
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   369
    case JVM_CONSTANT_MethodType:         return "JVM_CONSTANT_MethodType";
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   370
    case JVM_CONSTANT_InvokeDynamic:      return "JVM_CONSTANT_InvokeDynamic";
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   371
    case JVM_CONSTANT_InvokeDynamicTrans: return "JVM_CONSTANT_InvokeDynamic/transitional";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    case JVM_CONSTANT_Invalid:            return "JVM_CONSTANT_Invalid";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    case JVM_CONSTANT_UnresolvedClass:    return "JVM_CONSTANT_UnresolvedClass";
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   374
    case JVM_CONSTANT_UnresolvedClassInError:    return "JVM_CONSTANT_UnresolvedClassInError";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    case JVM_CONSTANT_ClassIndex:         return "JVM_CONSTANT_ClassIndex";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    case JVM_CONSTANT_UnresolvedString:   return "JVM_CONSTANT_UnresolvedString";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    case JVM_CONSTANT_StringIndex:        return "JVM_CONSTANT_StringIndex";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   379
    throw new InternalError("Unknown tag: " + tag);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  public void iterateFields(OopVisitor visitor, boolean doVMFields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    super.iterateFields(visitor, doVMFields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    if (doVMFields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
      visitor.doOop(tags, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      visitor.doOop(cache, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
      visitor.doOop(poolHolder, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      final int length = (int) getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      // zero'th pool entry is always invalid. ignore it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      for (int index = 1; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
        int ctag = (int) getTags().getByteAt((int) index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
        switch (ctag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
        case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
        case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
        case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
          visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
        case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
          visitor.doFloat(new FloatField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
        case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
          visitor.doLong(new LongField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
          // long entries occupy two slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
          index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
        case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
          visitor.doDouble(new DoubleField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
          // double entries occupy two slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
          index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   416
        case JVM_CONSTANT_UnresolvedClassInError:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
        case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
        case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
        case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
        case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
          visitor.doOop(new OopField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
        case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
        case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
        case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
        case JVM_CONSTANT_NameAndType:
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   428
        case JVM_CONSTANT_MethodHandle:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   429
        case JVM_CONSTANT_MethodType:
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   430
        case JVM_CONSTANT_InvokeDynamic:
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   431
        case JVM_CONSTANT_InvokeDynamicTrans:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
          visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
    /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    int length = getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    for (int index = 0; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
      long offset = baseOffset + (index + typeDataBase.getOopSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
      visitor.doOop(new IndexableField(index, offset, false), getObjAt(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  public void writeBytes(OutputStream os) throws IOException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
          // Map between any modified UTF-8 and it's constant pool index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
          Map utf8ToIndex = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
      DataOutputStream dos = new DataOutputStream(os);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
      TypeArray tags = getTags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
      int len = (int)getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
      int ci = 0; // constant pool index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      // collect all modified UTF-8 Strings from Constant Pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
      for (ci = 1; ci < len; ci++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
          byte cpConstType = tags.getByteAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
          if(cpConstType == JVM_CONSTANT_Utf8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
              Symbol sym = getSymbolAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
              utf8ToIndex.put(sym.asString(), new Short((short) ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
          else if(cpConstType == JVM_CONSTANT_Long ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
                  cpConstType == JVM_CONSTANT_Double) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
              ci++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      for(ci = 1; ci < len; ci++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
          int cpConstType = (int)tags.getByteAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
          // write cp_info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
          // write constant type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
          switch(cpConstType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
              case JVM_CONSTANT_Utf8: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
                  Symbol sym = getSymbolAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
                  dos.writeShort((short)sym.getLength());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
                  dos.write(sym.asByteArray());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
                  if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
              case JVM_CONSTANT_Unicode:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
                  throw new IllegalArgumentException("Unicode constant!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
              case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
                  dos.writeInt(getIntAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
                  if (DEBUG) debugMessage("CP[" + ci + "] = int " + getIntAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
              case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
                  dos.writeFloat(getFloatAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
                  if (DEBUG) debugMessage("CP[" + ci + "] = float " + getFloatAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
              case JVM_CONSTANT_Long: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
                  long l = getLongAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
                  // long entries occupy two pool entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
                  ci++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
                  dos.writeLong(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
              case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
                  dos.writeDouble(getDoubleAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
                  // double entries occupy two pool entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
                  ci++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
              case JVM_CONSTANT_Class: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
                  // Klass already resolved. ConstantPool constains klassOop.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   517
                  Klass refKls = (Klass) getObjAtRaw(ci);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
                  String klassName = refKls.getName().asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
                  Short s = (Short) utf8ToIndex.get(klassName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
                  if (DEBUG) debugMessage("CP[" + ci  + "] = class " + s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
              // case JVM_CONSTANT_ClassIndex:
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   526
              case JVM_CONSTANT_UnresolvedClassInError:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
              case JVM_CONSTANT_UnresolvedClass: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
                  dos.writeByte(JVM_CONSTANT_Class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
                  String klassName = getSymbolAt(ci).asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
                  Short s = (Short) utf8ToIndex.get(klassName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
                  if (DEBUG) debugMessage("CP[" + ci + "] = class " + s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
              case JVM_CONSTANT_String: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
                  dos.writeByte(cpConstType);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   538
                  String str = OopUtilities.stringOopToString(getObjAtRaw(ci));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
                  Short s = (Short) utf8ToIndex.get(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
                  if (DEBUG) debugMessage("CP[" + ci + "] = string " + s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
                  // case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
              case JVM_CONSTANT_UnresolvedString: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
                  dos.writeByte(JVM_CONSTANT_String);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
                  String val = getSymbolAt(ci).asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
                  Short s = (Short) utf8ToIndex.get(val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
                  if (DEBUG) debugMessage("CP[" + ci + "] = string " + s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
              // all external, internal method/field references
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
              case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
              case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
              case JVM_CONSTANT_InterfaceMethodref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
                  int value = getIntAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
                  short klassIndex = (short) extractLowShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
                  short nameAndTypeIndex = (short) extractHighShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
                  dos.writeShort(klassIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
                  dos.writeShort(nameAndTypeIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
                  if (DEBUG) debugMessage("CP[" + ci + "] = ref klass = " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
                                          klassIndex + ", N&T = " + nameAndTypeIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
              case JVM_CONSTANT_NameAndType: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
                  int value = getIntAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
                  short nameIndex = (short) extractLowShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
                  short signatureIndex = (short) extractHighShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
                  dos.writeShort(nameIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
                  dos.writeShort(signatureIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
                  if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
                                          + ", type = " + signatureIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
              }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   582
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   583
              case JVM_CONSTANT_MethodHandle: {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   584
                  dos.writeByte(cpConstType);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   585
                  int value = getIntAt(ci);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   586
                  short nameIndex = (short) extractLowShortFromInt(value);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   587
                  short signatureIndex = (short) extractHighShortFromInt(value);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   588
                  dos.writeShort(nameIndex);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   589
                  dos.writeShort(signatureIndex);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   590
                  if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   591
                                          + ", type = " + signatureIndex);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   592
                  break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   593
              }
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   594
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   595
              case JVM_CONSTANT_InvokeDynamicTrans:
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   596
              case JVM_CONSTANT_InvokeDynamic: {
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   597
                  dos.writeByte(cpConstType);
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   598
                  int value = getIntAt(ci);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   599
                  short bsmIndex = (short) extractLowShortFromInt(value);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   600
                  short nameAndTypeIndex = (short) extractHighShortFromInt(value);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   601
                  dos.writeShort(bsmIndex);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   602
                  dos.writeShort(nameAndTypeIndex);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   603
                  if (DEBUG) debugMessage("CP[" + ci + "] = indy BSM = " + bsmIndex
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   604
                                          + ", N&T = " + nameAndTypeIndex);
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   605
                  break;
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   606
              }
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   607
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   608
              default:
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   609
                  throw new InternalError("unknown tag: " + cpConstType);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
          } // switch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
      dos.flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  public void printValueOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
    tty.print("ConstantPool for " + getPoolHolder().getName().asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  public long getObjectSize() {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   621
    return alignObjectSize(headerSize + (getLength() * getElementSize()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  private static int extractHighShortFromInt(int val) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   629
    // must stay in sync with constantPoolOopDesc::name_and_type_at_put, method_at_put, etc.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    return (val >> 16) & 0xFFFF;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  private static int extractLowShortFromInt(int val) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   634
    // must stay in sync with constantPoolOopDesc::name_and_type_at_put, method_at_put, etc.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    return val & 0xFFFF;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
}