hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/oops/ConstantPool.java
author iklam
Fri, 03 Mar 2017 23:08:35 -0800
changeset 46427 54713555867e
parent 42087 afd6ae4fec81
child 46460 d25a320cd821
permissions -rw-r--r--
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only Summary: Added _resolved_klasses; moved _resolved_references to ConstantPoolCache, etc. Reviewed-by: coleenp, lfoltan, simonis, aph
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46427
54713555867e 8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents: 42087
diff changeset
     2
 * Copyright (c) 2000, 2017, 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
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    37
public class ConstantPool extends Metadata implements ClassConstants {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    38
  public class CPSlot {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    39
    private Address ptr;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    40
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    41
    CPSlot(Address ptr) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    42
      this.ptr = ptr;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    43
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    44
    CPSlot(Symbol sym) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    45
      this.ptr = sym.getAddress().orWithMask(1);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    46
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    47
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    48
    public boolean isResolved() {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    49
      return (ptr.minus(null) & 1) == 0;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    50
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    51
    public boolean isUnresolved() {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    52
      return (ptr.minus(null) & 1) == 1;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    53
    }
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
    public Symbol getSymbol() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    56
      if (!isUnresolved()) throw new InternalError("not a symbol");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    57
        return Symbol.create(ptr.xorWithMask(1));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    58
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    59
    public Klass getKlass() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    60
      if (!isResolved()) throw new InternalError("not klass");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    61
      return (Klass)Metadata.instantiateWrapperFor(ptr);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    62
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    63
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
    64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // Used for debugging this code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  private static final boolean DEBUG = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  protected void debugMessage(String message) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    System.out.println(message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    81
    Type type   = db.lookupType("ConstantPool");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    82
    tags        = type.getAddressField("_tags");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    83
    operands    = type.getAddressField("_operands");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    84
    cache       = type.getAddressField("_cache");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    85
    poolHolder  = new MetadataField(type.getAddressField("_pool_holder"), 0);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    86
    length      = new CIntField(type.getCIntegerField("_length"), 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    headerSize  = type.getSize();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    88
    elementSize = 0;
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
    89
    // fetch constants:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    90
    INDY_BSM_OFFSET = db.lookupIntConstant("ConstantPool::_indy_bsm_offset").intValue();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    91
    INDY_ARGC_OFFSET = db.lookupIntConstant("ConstantPool::_indy_argc_offset").intValue();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    92
    INDY_ARGV_OFFSET = db.lookupIntConstant("ConstantPool::_indy_argv_offset").intValue();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    95
  public ConstantPool(Address addr) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
    96
    super(addr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  public boolean isConstantPool()      { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   101
  private static AddressField tags;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   102
  private static AddressField operands;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   103
  private static AddressField cache;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   104
  private static MetadataField poolHolder;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   105
  private static CIntField length; // number of elements in oop
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  private static long headerSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  private static long elementSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   110
  private static int INDY_BSM_OFFSET;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   111
  private static int INDY_ARGC_OFFSET;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   112
  private static int INDY_ARGV_OFFSET;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   113
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   114
  public U1Array           getTags()       { return new U1Array(tags.getValue(getAddress())); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   115
  public U2Array           getOperands()   { return new U2Array(operands.getValue(getAddress())); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   116
  public ConstantPoolCache getCache()      {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   117
    Address addr = cache.getValue(getAddress());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   118
    return (ConstantPoolCache) VMObjectFactory.newObject(ConstantPoolCache.class, addr);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   119
  }
14391
df0a1573d5bd 8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents: 13728
diff changeset
   120
  public InstanceKlass     getPoolHolder() { return (InstanceKlass)poolHolder.getValue(this); }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   121
  public int               getLength()     { return (int)length.getValue(getAddress()); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   122
  public Oop               getResolvedReferences() {
46427
54713555867e 8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents: 42087
diff changeset
   123
    return getCache().getResolvedReferences();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   124
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   125
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   126
  public U2Array referenceMap() {
46427
54713555867e 8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents: 42087
diff changeset
   127
    return getCache().referenceMap();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   128
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   129
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   130
  public int objectToCPIndex(int index) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   131
    return referenceMap().at(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   132
  }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   133
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   134
  private long getElementSize() {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   135
    if (elementSize !=0 ) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   136
      return elementSize;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   137
    } else {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   138
      elementSize = VM.getVM().getOopSize();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   139
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   140
    return elementSize;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   141
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  private long indexOffset(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    if (Assert.ASSERTS_ENABLED) {
22536
193172c33a3a 8032247: SA: Constantpool lookup for invokedynamic is not implemented
dsamersoff
parents: 15799
diff changeset
   145
      Assert.that(index >= 0 && index < getLength(),  "invalid cp index " + index + " " + getLength());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   147
    return (index * getElementSize()) + headerSize;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  public ConstantTag getTagAt(long index) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   151
    return new ConstantTag((byte)getTags().at((int) index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   154
  public CPSlot getSlotAt(long index) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   155
    return new CPSlot(getAddressAtRaw(index));
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   156
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7436
diff changeset
   157
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   158
  public Address getAddressAtRaw(long index) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   159
    return getAddress().getAddressAt(indexOffset(index));
1
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 Symbol getSymbolAt(long index) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   163
    return Symbol.create(getAddressAtRaw(index));
1
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 int getIntAt(long index){
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   167
    return getAddress().getJIntAt(indexOffset(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  public float getFloatAt(long index){
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   171
    return getAddress().getJFloatAt(indexOffset(index));
1
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 long getLongAt(long index) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   175
    int oneHalf = getAddress().getJIntAt(indexOffset(index + 1));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   176
    int otherHalf   = getAddress().getJIntAt(indexOffset(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    // buildLongFromIntsPD accepts higher address value, lower address value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    // in that order.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    return VM.getVM().buildLongFromIntsPD(oneHalf, otherHalf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  public double getDoubleAt(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    return Double.longBitsToDouble(getLongAt(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  public int getFieldOrMethodAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      System.err.print("ConstantPool.getFieldOrMethodAt(" + which + "): new index = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    int i = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    ConstantPoolCache cache = getCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    if (cache == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      i = which;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      // change byte-ordering and go via cache
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   196
      i = cache.getEntryAt(0xFFFF & which).getConstantPoolIndex();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      Assert.that(getTagAt(i).isFieldOrMethod(), "Corrupted constant pool");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      System.err.println(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    int res = getIntAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      System.err.println("ConstantPool.getFieldOrMethodAt(" + i + "): result = " + res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   211
  public int[] getNameAndTypeAt(int which) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    if (Assert.ASSERTS_ENABLED) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   213
      Assert.that(getTagAt(which).isNameAndType(), "Corrupted constant pool: " + which + " " + getTagAt(which));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    int i = getIntAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
      System.err.println("ConstantPool.getNameAndTypeAt(" + which + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   219
    return new int[] { extractLowShortFromInt(i), extractHighShortFromInt(i) };
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  public Symbol getNameRefAt(int which) {
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   223
    return implGetNameRefAt(which, false);
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   224
  }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   225
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   226
  public Symbol uncachedGetNameRefAt(int which) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   227
    return implGetNameRefAt(which, true);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   228
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   229
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   230
  private Symbol implGetNameRefAt(int which, boolean uncached) {
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   231
    int signatureIndex = getNameRefIndexAt(implNameAndTypeRefIndexAt(which, uncached));
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   232
    return getSymbolAt(signatureIndex);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  public Symbol getSignatureRefAt(int which) {
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   236
    return implGetSignatureRefAt(which, false);
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   237
  }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   238
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   239
  public Symbol uncachedGetSignatureRefAt(int which) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   240
    return implGetSignatureRefAt(which, true);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   241
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   242
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   243
  private Symbol implGetSignatureRefAt(int which, boolean uncached) {
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   244
    int signatureIndex = getSignatureRefIndexAt(implNameAndTypeRefIndexAt(which, uncached));
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   245
    return getSymbolAt(signatureIndex);
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   246
  }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   247
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   248
  public static boolean isInvokedynamicIndex(int i) { return (i < 0); }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   249
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   250
  public static int  decodeInvokedynamicIndex(int i) { Assert.that(isInvokedynamicIndex(i),  ""); return ~i; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   251
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   252
  // The invokedynamic points at the object index.  The object map points at
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   253
  // the cpCache index and the cpCache entry points at the original constant
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   254
  // pool index.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   255
  public int invokedynamicCPCacheIndex(int index) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   256
    Assert.that(isInvokedynamicIndex(index), "should be a invokedynamic index");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   257
    int rawIndex = decodeInvokedynamicIndex(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   258
    return referenceMap().at(rawIndex);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   259
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   260
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   261
  ConstantPoolCacheEntry invokedynamicCPCacheEntryAt(int index) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   262
    // decode index that invokedynamic points to.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   263
    int cpCacheIndex = invokedynamicCPCacheIndex(index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   264
    return getCache().getEntryAt(cpCacheIndex);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   265
  }
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   266
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   267
  private int implNameAndTypeRefIndexAt(int which, boolean uncached) {
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   268
    int i = which;
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   269
    if (!uncached && getCache() != null) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   270
      if (isInvokedynamicIndex(which)) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   271
        // Invokedynamic index is index into resolved_references
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   272
        int poolIndex = invokedynamicCPCacheEntryAt(which).getConstantPoolIndex();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   273
        poolIndex = invokeDynamicNameAndTypeRefIndexAt(poolIndex);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   274
        Assert.that(getTagAt(poolIndex).isNameAndType(), "");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   275
        return poolIndex;
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   276
      }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   277
      // change byte-ordering and go via cache
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   278
      i = remapInstructionOperandFromCache(which);
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   279
    } else {
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   280
      if (getTagAt(which).isInvokeDynamic()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   281
        int poolIndex = invokeDynamicNameAndTypeRefIndexAt(which);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   282
        Assert.that(getTagAt(poolIndex).isNameAndType(), "");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   283
        return poolIndex;
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   284
      }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   285
    }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   286
    // assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   287
    // assert(!tag_at(i).is_invoke_dynamic(), "Must be handled above");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   288
    int refIndex = getIntAt(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   289
    return extractHighShortFromInt(refIndex);
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   290
  }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   291
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   292
  private int remapInstructionOperandFromCache(int operand) {
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   293
    int cpc_index = operand;
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   294
    // DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG);
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   295
    // assert((int)(u2)cpc_index == cpc_index, "clean u2");
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   296
    int member_index = getCache().getEntryAt(cpc_index).getConstantPoolIndex();
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   297
    return member_index;
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   298
  }
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   299
42087
afd6ae4fec81 8164783: SA: jhsdb clhsdb 'printall' often throws "Corrupted constant pool" assertion failure
vtewari
parents: 35898
diff changeset
   300
  public int invokeDynamicNameAndTypeRefIndexAt(int which) {
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   301
    // assert(tag_at(which).is_invoke_dynamic(), "Corrupted constant pool");
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   302
    return extractHighShortFromInt(getIntAt(which));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  // returns null, if not resolved.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   306
  public Klass getKlassAt(int which) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    if( ! getTagAt(which).isKlass()) return null;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   308
    return (Klass)Metadata.instantiateWrapperFor(getAddressAtRaw(which));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   309
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   310
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   311
  public Symbol getKlassNameAt(int which) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   312
    CPSlot entry = getSlotAt(which);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   313
    if (entry.isResolved()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   314
      return entry.getKlass().getName();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   315
    } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   316
      return entry.getSymbol();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   317
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   318
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   319
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   320
  public Symbol getUnresolvedStringAt(int which) {
30295
d91d9c285139 8077832: SA's dumpreplaydata, dumpcfg and buildreplayjars are broken
roland
parents: 22536
diff changeset
   321
    return getSlotAt(which).getSymbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  public InstanceKlass getFieldOrMethodKlassRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    int refIndex = getFieldOrMethodAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    int klassIndex = extractLowShortFromInt(refIndex);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   328
    return (InstanceKlass) getKlassAt(klassIndex);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  public Method getMethodRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    InstanceKlass klass = getFieldOrMethodKlassRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    if (klass == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    Symbol name = getNameRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    Symbol sig  = getSignatureRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    return klass.findMethod(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  public Field getFieldRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    InstanceKlass klass = getFieldOrMethodKlassRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    if (klass == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    Symbol name = getNameRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    Symbol sig  = getSignatureRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    return klass.findField(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  public int getNameAndTypeRefIndexAt(int index) {
10251
71b8938a2821 7012081: JSR 292: SA-JDI can't read MH/MT/Indy ConstantPool entries
never
parents: 9124
diff changeset
   350
    return implNameAndTypeRefIndexAt(index, false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  /** Lookup for entries consisting of (name_index, signature_index) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  public int getNameRefIndexAt(int index) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   355
    int[] refIndex = getNameAndTypeAt(index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    if (DEBUG) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   357
      System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): refIndex = " + refIndex[0]+"/"+refIndex[1]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   359
    int i = refIndex[0];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  /** Lookup for entries consisting of (name_index, signature_index) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  public int getSignatureRefIndexAt(int index) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   368
    int[] refIndex = getNameAndTypeAt(index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    if (DEBUG) {
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   370
      System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): refIndex = " + refIndex[0]+"/"+refIndex[1]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   372
    int i = refIndex[1];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   379
  /** Lookup for MethodHandle entries. */
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   380
  public int getMethodHandleIndexAt(int i) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   381
    if (Assert.ASSERTS_ENABLED) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   382
      Assert.that(getTagAt(i).isMethodHandle(), "Corrupted constant pool");
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   383
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   384
    int res = extractHighShortFromInt(getIntAt(i));
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   385
    if (DEBUG) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   386
      System.err.println("ConstantPool.getMethodHandleIndexAt(" + i + "): result = " + res);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   387
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   388
    return res;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   389
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   390
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   391
  /** Lookup for MethodHandle entries. */
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   392
  public int getMethodHandleRefKindAt(int i) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   393
    if (Assert.ASSERTS_ENABLED) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   394
      Assert.that(getTagAt(i).isMethodHandle(), "Corrupted constant pool");
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   395
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   396
    int res = extractLowShortFromInt(getIntAt(i));
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   397
    if (DEBUG) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   398
      System.err.println("ConstantPool.getMethodHandleRefKindAt(" + i + "): result = " + res);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   399
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   400
    return res;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   401
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   402
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   403
  /** Lookup for MethodType entries. */
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   404
  public int getMethodTypeIndexAt(int i) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   405
    if (Assert.ASSERTS_ENABLED) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   406
      Assert.that(getTagAt(i).isMethodType(), "Corrupted constant pool");
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   407
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   408
    int res = getIntAt(i);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   409
    if (DEBUG) {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   410
      System.err.println("ConstantPool.getMethodHandleTypeAt(" + i + "): result = " + res);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   411
    }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   412
    return res;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   413
  }
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   414
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   415
  /** 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
   416
  public short[] getBootstrapSpecifierAt(int i) {
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   417
    if (Assert.ASSERTS_ENABLED) {
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   418
      Assert.that(getTagAt(i).isInvokeDynamic(), "Corrupted constant pool");
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   419
    }
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   420
    int bsmSpec = extractLowShortFromInt(this.getIntAt(i));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   421
    U2Array operands = getOperands();
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   422
    if (operands == null)  return null;  // safety first
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   423
    int basePos = VM.getVM().buildIntFromShorts(operands.at(bsmSpec * 2 + 0),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   424
                                                operands.at(bsmSpec * 2 + 1));
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   425
    int argv = basePos + INDY_ARGV_OFFSET;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   426
    int argc = operands.at(basePos + INDY_ARGC_OFFSET);
7436
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   427
    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
   428
    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
   429
    for (int j = 0; j < values.length; j++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   430
        values[j] = operands.at(basePos+j);
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   431
    }
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   432
    return values;
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   433
  }
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   434
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  final private static String[] nameForTag = new String[] {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  private String nameForTag(int tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    switch (tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    case JVM_CONSTANT_Utf8:               return "JVM_CONSTANT_Utf8";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    case JVM_CONSTANT_Unicode:            return "JVM_CONSTANT_Unicode";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    case JVM_CONSTANT_Integer:            return "JVM_CONSTANT_Integer";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    case JVM_CONSTANT_Float:              return "JVM_CONSTANT_Float";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    case JVM_CONSTANT_Long:               return "JVM_CONSTANT_Long";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    case JVM_CONSTANT_Double:             return "JVM_CONSTANT_Double";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    case JVM_CONSTANT_Class:              return "JVM_CONSTANT_Class";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    case JVM_CONSTANT_String:             return "JVM_CONSTANT_String";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    case JVM_CONSTANT_Fieldref:           return "JVM_CONSTANT_Fieldref";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    case JVM_CONSTANT_Methodref:          return "JVM_CONSTANT_Methodref";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    case JVM_CONSTANT_InterfaceMethodref: return "JVM_CONSTANT_InterfaceMethodref";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    case JVM_CONSTANT_NameAndType:        return "JVM_CONSTANT_NameAndType";
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   452
    case JVM_CONSTANT_MethodHandle:       return "JVM_CONSTANT_MethodHandle";
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   453
    case JVM_CONSTANT_MethodType:         return "JVM_CONSTANT_MethodType";
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   454
    case JVM_CONSTANT_InvokeDynamic:      return "JVM_CONSTANT_InvokeDynamic";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    case JVM_CONSTANT_Invalid:            return "JVM_CONSTANT_Invalid";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    case JVM_CONSTANT_UnresolvedClass:    return "JVM_CONSTANT_UnresolvedClass";
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   457
    case JVM_CONSTANT_ClassIndex:         return "JVM_CONSTANT_ClassIndex";
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   458
    case JVM_CONSTANT_StringIndex:        return "JVM_CONSTANT_StringIndex";
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   459
    case JVM_CONSTANT_UnresolvedClassInError:    return "JVM_CONSTANT_UnresolvedClassInError";
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   460
    case JVM_CONSTANT_MethodHandleInError:return "JVM_CONSTANT_MethodHandleInError";
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   461
    case JVM_CONSTANT_MethodTypeInError:  return "JVM_CONSTANT_MethodTypeInError";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    }
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   463
    throw new InternalError("Unknown tag: " + tag);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   466
  public void iterateFields(MetadataVisitor visitor) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   467
    super.iterateFields(visitor);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   468
    visitor.doMetadata(poolHolder, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      final int length = (int) getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
      // zero'th pool entry is always invalid. ignore it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
      for (int index = 1; index < length; index++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   473
      int ctag = (int) getTags().at((int) index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
        switch (ctag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
        case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
        case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
        case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
          visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
        case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
          visitor.doFloat(new FloatField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
        case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
          visitor.doLong(new LongField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
          // long entries occupy two slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
          index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
        case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
          visitor.doDouble(new DoubleField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
          // double entries occupy two slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
          index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   497
        case JVM_CONSTANT_UnresolvedClassInError:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
        case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
        case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
        case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
          visitor.doOop(new OopField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
        case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
        case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
        case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
        case JVM_CONSTANT_NameAndType:
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   508
        case JVM_CONSTANT_MethodHandle:
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   509
        case JVM_CONSTANT_MethodType:
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   510
        case JVM_CONSTANT_InvokeDynamic:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
          visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
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
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  public void writeBytes(OutputStream os) throws IOException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
          // Map between any modified UTF-8 and it's constant pool index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
          Map utf8ToIndex = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      DataOutputStream dos = new DataOutputStream(os);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   521
      U1Array tags = getTags();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
      int len = (int)getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
      int ci = 0; // constant pool index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
      // collect all modified UTF-8 Strings from Constant Pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      for (ci = 1; ci < len; ci++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   528
          int cpConstType = tags.at(ci);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
          if(cpConstType == JVM_CONSTANT_Utf8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
              Symbol sym = getSymbolAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
              utf8ToIndex.put(sym.asString(), new Short((short) ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
          else if(cpConstType == JVM_CONSTANT_Long ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
                  cpConstType == JVM_CONSTANT_Double) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
              ci++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
      for(ci = 1; ci < len; ci++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   541
          int cpConstType = tags.at(ci);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
          // write cp_info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
          // write constant type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
          switch(cpConstType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
              case JVM_CONSTANT_Utf8: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
                  Symbol sym = getSymbolAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
                  dos.writeShort((short)sym.getLength());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
                  dos.write(sym.asByteArray());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
                  if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
              case JVM_CONSTANT_Unicode:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
                  throw new IllegalArgumentException("Unicode constant!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
              case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
                  dos.writeInt(getIntAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
                  if (DEBUG) debugMessage("CP[" + ci + "] = int " + getIntAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
              case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
                  dos.writeFloat(getFloatAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
                  if (DEBUG) debugMessage("CP[" + ci + "] = float " + getFloatAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
              case JVM_CONSTANT_Long: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
                  long l = getLongAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
                  // long entries occupy two pool entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
                  ci++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
                  dos.writeLong(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
              case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
                  dos.writeDouble(getDoubleAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
                  // double entries occupy two pool entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
                  ci++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
              case JVM_CONSTANT_Class: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
                  dos.writeByte(cpConstType);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   587
                  // Klass already resolved. ConstantPool constains Klass*.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   588
                  Klass refKls = (Klass)Metadata.instantiateWrapperFor(getAddressAtRaw(ci));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
                  String klassName = refKls.getName().asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
                  Short s = (Short) utf8ToIndex.get(klassName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
                  if (DEBUG) debugMessage("CP[" + ci  + "] = class " + s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
              // case JVM_CONSTANT_ClassIndex:
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   597
              case JVM_CONSTANT_UnresolvedClassInError:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
              case JVM_CONSTANT_UnresolvedClass: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
                  dos.writeByte(JVM_CONSTANT_Class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
                  String klassName = getSymbolAt(ci).asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
                  Short s = (Short) utf8ToIndex.get(klassName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
                  if (DEBUG) debugMessage("CP[" + ci + "] = class " + s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
              case JVM_CONSTANT_String: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
                  dos.writeByte(cpConstType);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   609
                  String str = getUnresolvedStringAt(ci).asString();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
                  Short s = (Short) utf8ToIndex.get(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
                  if (DEBUG) debugMessage("CP[" + ci + "] = string " + s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
              // all external, internal method/field references
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
              case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
              case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
              case JVM_CONSTANT_InterfaceMethodref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
                  int value = getIntAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
                  short klassIndex = (short) extractLowShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
                  short nameAndTypeIndex = (short) extractHighShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
                  dos.writeShort(klassIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
                  dos.writeShort(nameAndTypeIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
                  if (DEBUG) debugMessage("CP[" + ci + "] = ref klass = " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
                                          klassIndex + ", N&T = " + nameAndTypeIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
              case JVM_CONSTANT_NameAndType: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
                  int value = getIntAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
                  short nameIndex = (short) extractLowShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
                  short signatureIndex = (short) extractHighShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
                  dos.writeShort(nameIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
                  dos.writeShort(signatureIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
                  if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
                                          + ", type = " + signatureIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
              }
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   642
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   643
              case JVM_CONSTANT_MethodHandle: {
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   644
                  dos.writeByte(cpConstType);
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   645
                  int value = getIntAt(ci);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   646
                  byte refKind = (byte) extractLowShortFromInt(value);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   647
                  short memberIndex = (short) extractHighShortFromInt(value);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   648
                  dos.writeByte(refKind);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   649
                  dos.writeShort(memberIndex);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   650
                  if (DEBUG) debugMessage("CP[" + ci + "] = MH kind = " +
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   651
                                          refKind + ", mem = " + memberIndex);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   652
                  break;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   653
              }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   654
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   655
              case JVM_CONSTANT_MethodType: {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   656
                  dos.writeByte(cpConstType);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   657
                  int value = getIntAt(ci);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   658
                  short refIndex = (short) value;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   659
                  dos.writeShort(refIndex);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   660
                  if (DEBUG) debugMessage("CP[" + ci + "] = MT index = " + refIndex);
5882
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   661
                  break;
6b2aecc4f7d8 6939203: JSR 292 needs method handle constants
jrose
parents: 5547
diff changeset
   662
              }
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   663
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   664
              case JVM_CONSTANT_InvokeDynamic: {
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   665
                  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
   666
                  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
   667
                  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
   668
                  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
   669
                  dos.writeShort(bsmIndex);
dbc43da3d512 7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents: 7114
diff changeset
   670
                  dos.writeShort(nameAndTypeIndex);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   671
                  if (DEBUG) debugMessage("CP[" + ci + "] = INDY bsm = " +
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   672
                                          bsmIndex + ", N&T = " + nameAndTypeIndex);
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   673
                  break;
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
   674
              }
7114
65d21c4c6337 6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents: 6062
diff changeset
   675
5341
290a02b4adb3 6945219: minor SA fixes
never
parents: 670
diff changeset
   676
              default:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   677
                  throw new InternalError("Unknown tag: " + cpConstType);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
          } // switch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
      dos.flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  public void printValueOn(PrintStream tty) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   685
    tty.print("ConstantPool for " + getPoolHolder().getName().asString());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   688
  public long getSize() {
35898
ddc274f0052f 8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents: 35217
diff changeset
   689
    return alignSize(headerSize + getLength());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  private static int extractHighShortFromInt(int val) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   697
    // must stay in sync with ConstantPool::name_and_type_at_put, method_at_put, etc.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
    return (val >> 16) & 0xFFFF;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  private static int extractLowShortFromInt(int val) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 11882
diff changeset
   702
    // must stay in sync with ConstantPool::name_and_type_at_put, method_at_put, etc.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
    return val & 0xFFFF;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
}