hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPool.java
author xdono
Wed, 02 Jul 2008 12:55:16 -0700
changeset 670 ddf3e9583f2f
parent 360 21d113ecbf6a
child 5341 290a02b4adb3
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
670
ddf3e9583f2f 6719955: Update copyright year
xdono
parents: 360
diff changeset
     2
 * Copyright 2000-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.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 {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // Used for debugging this code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  private static final boolean DEBUG = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  protected void debugMessage(String message) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    System.out.println(message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    Type type   = db.lookupType("constantPoolOopDesc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    tags        = new OopField(type.getOopField("_tags"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    cache       = new OopField(type.getOopField("_cache"), 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    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
    58
    length      = new CIntField(type.getCIntegerField("_length"), 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    headerSize  = type.getSize();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    60
    elementSize = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  ConstantPool(OopHandle handle, ObjectHeap heap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    super(handle, heap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  public boolean isConstantPool()      { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  private static OopField tags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  private static OopField cache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  private static OopField poolHolder;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    72
  private static CIntField length; // number of elements in oop
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  private static long headerSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  private static long elementSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  public TypeArray         getTags()       { return (TypeArray)         tags.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  public ConstantPoolCache getCache()      { return (ConstantPoolCache) cache.getValue(this); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  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
    80
  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
    81
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    82
  private long getElementSize() {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    83
    if (elementSize !=0 ) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    84
      return elementSize;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    85
    } else {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    86
      elementSize = VM.getVM().getOopSize();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    87
    }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    88
    return elementSize;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    89
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  private long indexOffset(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    if (Assert.ASSERTS_ENABLED) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    93
      Assert.that(index > 0 && index < getLength(),  "invalid cp index " + index + " " + getLength());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    95
    return (index * getElementSize()) + headerSize;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  public ConstantTag getTagAt(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    return new ConstantTag(getTags().getByteAt((int) index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  public Oop getObjAt(long index){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    return getHeap().newOop(getHandle().getOopHandleAt(indexOffset(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  public Symbol getSymbolAt(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    return (Symbol) getObjAt(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  public int getIntAt(long index){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    return getHandle().getJIntAt(indexOffset(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  public float getFloatAt(long index){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    return getHandle().getJFloatAt(indexOffset(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  public long getLongAt(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    int oneHalf = getHandle().getJIntAt(indexOffset(index + 1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    int otherHalf   = getHandle().getJIntAt(indexOffset(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    // buildLongFromIntsPD accepts higher address value, lower address value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    // in that order.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    return VM.getVM().buildLongFromIntsPD(oneHalf, otherHalf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  public double getDoubleAt(long index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    return Double.longBitsToDouble(getLongAt(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  public int getFieldOrMethodAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      System.err.print("ConstantPool.getFieldOrMethodAt(" + which + "): new index = ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    int i = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    ConstantPoolCache cache = getCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    if (cache == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      i = which;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      // change byte-ordering and go via cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      i = cache.getEntryAt(0xFFFF & VM.getVM().getBytes().swapShort((short) which)).getConstantPoolIndex();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      Assert.that(getTagAt(i).isFieldOrMethod(), "Corrupted constant pool");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      System.err.println(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    int res = getIntAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      System.err.println("ConstantPool.getFieldOrMethodAt(" + i + "): result = " + res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  public int getNameAndTypeAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      Assert.that(getTagAt(which).isNameAndType(), "Corrupted constant pool");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    int i = getIntAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      System.err.println("ConstantPool.getNameAndTypeAt(" + which + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    return i;
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 Symbol getNameRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    int refIndex = getNameAndTypeAt(getNameAndTypeRefIndexAt(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    int nameIndex = extractLowShortFromInt(refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    return getSymbolAt(nameIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  public Symbol getSignatureRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    int refIndex = getNameAndTypeAt(getNameAndTypeRefIndexAt(which));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    int sigIndex = extractHighShortFromInt(refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    return getSymbolAt(sigIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  public Klass getKlassRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    if( ! getTagAt(which).isKlass()) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    return (Klass) getObjAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  public InstanceKlass getFieldOrMethodKlassRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    int refIndex = getFieldOrMethodAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    int klassIndex = extractLowShortFromInt(refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    return (InstanceKlass) getKlassRefAt(klassIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  public Method getMethodRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    InstanceKlass klass = getFieldOrMethodKlassRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    if (klass == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    Symbol name = getNameRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    Symbol sig  = getSignatureRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    return klass.findMethod(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  // returns null, if not resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  public Field getFieldRefAt(int which) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    InstanceKlass klass = getFieldOrMethodKlassRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    if (klass == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    Symbol name = getNameRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    Symbol sig  = getSignatureRefAt(which);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    return klass.findField(name, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  public int getNameAndTypeRefIndexAt(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    int refIndex = getFieldOrMethodAt(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      System.err.println("ConstantPool.getNameAndTypeRefIndexAt(" + index + "): refIndex = " + refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    int i = extractHighShortFromInt(refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      System.err.println("ConstantPool.getNameAndTypeRefIndexAt(" + index + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  /** Lookup for entries consisting of (name_index, signature_index) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  public int getNameRefIndexAt(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    int refIndex = getNameAndTypeAt(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): refIndex = " + refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    int i = extractLowShortFromInt(refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      System.err.println("ConstantPool.getNameRefIndexAt(" + index + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  /** Lookup for entries consisting of (name_index, signature_index) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  public int getSignatureRefIndexAt(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    int refIndex = getNameAndTypeAt(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): refIndex = " + refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    int i = extractHighShortFromInt(refIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      System.err.println("ConstantPool.getSignatureRefIndexAt(" + index + "): result = " + i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  final private static String[] nameForTag = new String[] {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  private String nameForTag(int tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    switch (tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    case JVM_CONSTANT_Utf8:               return "JVM_CONSTANT_Utf8";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    case JVM_CONSTANT_Unicode:            return "JVM_CONSTANT_Unicode";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    case JVM_CONSTANT_Integer:            return "JVM_CONSTANT_Integer";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    case JVM_CONSTANT_Float:              return "JVM_CONSTANT_Float";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    case JVM_CONSTANT_Long:               return "JVM_CONSTANT_Long";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    case JVM_CONSTANT_Double:             return "JVM_CONSTANT_Double";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    case JVM_CONSTANT_Class:              return "JVM_CONSTANT_Class";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    case JVM_CONSTANT_String:             return "JVM_CONSTANT_String";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    case JVM_CONSTANT_Fieldref:           return "JVM_CONSTANT_Fieldref";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    case JVM_CONSTANT_Methodref:          return "JVM_CONSTANT_Methodref";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    case JVM_CONSTANT_InterfaceMethodref: return "JVM_CONSTANT_InterfaceMethodref";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    case JVM_CONSTANT_NameAndType:        return "JVM_CONSTANT_NameAndType";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    case JVM_CONSTANT_Invalid:            return "JVM_CONSTANT_Invalid";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    case JVM_CONSTANT_UnresolvedClass:    return "JVM_CONSTANT_UnresolvedClass";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    case JVM_CONSTANT_ClassIndex:         return "JVM_CONSTANT_ClassIndex";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    case JVM_CONSTANT_UnresolvedString:   return "JVM_CONSTANT_UnresolvedString";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    case JVM_CONSTANT_StringIndex:        return "JVM_CONSTANT_StringIndex";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    throw new InternalError("unknown tag");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  public void iterateFields(OopVisitor visitor, boolean doVMFields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    super.iterateFields(visitor, doVMFields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    if (doVMFields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      visitor.doOop(tags, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      visitor.doOop(cache, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      visitor.doOop(poolHolder, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      final int length = (int) getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      // zero'th pool entry is always invalid. ignore it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      for (int index = 1; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
        int ctag = (int) getTags().getByteAt((int) index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
        switch (ctag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
        case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
        case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
          visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
        case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
          visitor.doFloat(new FloatField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
        case JVM_CONSTANT_Long:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
          visitor.doLong(new LongField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
          // long entries occupy two slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
          index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
        case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
          visitor.doDouble(new DoubleField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
          // double entries occupy two slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
          index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
        case JVM_CONSTANT_UnresolvedClass:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
        case JVM_CONSTANT_Class:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
        case JVM_CONSTANT_UnresolvedString:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
        case JVM_CONSTANT_Utf8:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
          visitor.doOop(new OopField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
        case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
        case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
        case JVM_CONSTANT_InterfaceMethodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
        case JVM_CONSTANT_NameAndType:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
          visitor.doInt(new IntField(new NamedFieldIdentifier(nameForTag(ctag)), indexOffset(index), true), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    int length = getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    for (int index = 0; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      long offset = baseOffset + (index + typeDataBase.getOopSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      visitor.doOop(new IndexableField(index, offset, false), getObjAt(index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  public void writeBytes(OutputStream os) throws IOException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
          // Map between any modified UTF-8 and it's constant pool index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
          Map utf8ToIndex = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      DataOutputStream dos = new DataOutputStream(os);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
      TypeArray tags = getTags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      int len = (int)getLength();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
      int ci = 0; // constant pool index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
      // collect all modified UTF-8 Strings from Constant Pool
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
      for (ci = 1; ci < len; ci++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
          byte cpConstType = tags.getByteAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
          if(cpConstType == JVM_CONSTANT_Utf8) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
              Symbol sym = getSymbolAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
              utf8ToIndex.put(sym.asString(), new Short((short) ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
          else if(cpConstType == JVM_CONSTANT_Long ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
                  cpConstType == JVM_CONSTANT_Double) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
              ci++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      for(ci = 1; ci < len; ci++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
          int cpConstType = (int)tags.getByteAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
          // write cp_info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
          // write constant type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
          switch(cpConstType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
              case JVM_CONSTANT_Utf8: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
                  Symbol sym = getSymbolAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
                  dos.writeShort((short)sym.getLength());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
                  dos.write(sym.asByteArray());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
                  if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
              case JVM_CONSTANT_Unicode:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
                  throw new IllegalArgumentException("Unicode constant!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
              case JVM_CONSTANT_Integer:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
                  dos.writeInt(getIntAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
                  if (DEBUG) debugMessage("CP[" + ci + "] = int " + getIntAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
              case JVM_CONSTANT_Float:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
                  dos.writeFloat(getFloatAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
                  if (DEBUG) debugMessage("CP[" + ci + "] = float " + getFloatAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
              case JVM_CONSTANT_Long: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
                  long l = getLongAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
                  // long entries occupy two pool entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
                  ci++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
                  dos.writeLong(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
              case JVM_CONSTANT_Double:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
                  dos.writeDouble(getDoubleAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
                  // double entries occupy two pool entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
                  ci++;
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_Class: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
                  // Klass already resolved. ConstantPool constains klassOop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
                  Klass refKls = (Klass) getObjAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
                  String klassName = refKls.getName().asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
                  Short s = (Short) utf8ToIndex.get(klassName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
                  if (DEBUG) debugMessage("CP[" + ci  + "] = class " + s);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
              // case JVM_CONSTANT_ClassIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
              case JVM_CONSTANT_UnresolvedClass: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
                  dos.writeByte(JVM_CONSTANT_Class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
                  String klassName = getSymbolAt(ci).asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
                  Short s = (Short) utf8ToIndex.get(klassName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
                  if (DEBUG) debugMessage("CP[" + ci + "] = class " + s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
              case JVM_CONSTANT_String: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
                  String str = OopUtilities.stringOopToString(getObjAt(ci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
                  Short s = (Short) utf8ToIndex.get(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
                  if (DEBUG) debugMessage("CP[" + ci + "] = string " + s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
                  // case JVM_CONSTANT_StringIndex:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
              case JVM_CONSTANT_UnresolvedString: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
                  dos.writeByte(JVM_CONSTANT_String);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
                  String val = getSymbolAt(ci).asString();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
                  Short s = (Short) utf8ToIndex.get(val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
                  dos.writeShort(s.shortValue());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
                  if (DEBUG) debugMessage("CP[" + ci + "] = string " + s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
              // all external, internal method/field references
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
              case JVM_CONSTANT_Fieldref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
              case JVM_CONSTANT_Methodref:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
              case JVM_CONSTANT_InterfaceMethodref: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
                  int value = getIntAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
                  short klassIndex = (short) extractLowShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
                  short nameAndTypeIndex = (short) extractHighShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
                  dos.writeShort(klassIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
                  dos.writeShort(nameAndTypeIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
                  if (DEBUG) debugMessage("CP[" + ci + "] = ref klass = " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
                                          klassIndex + ", N&T = " + nameAndTypeIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
              case JVM_CONSTANT_NameAndType: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
                  dos.writeByte(cpConstType);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
                  int value = getIntAt(ci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
                  short nameIndex = (short) extractLowShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
                  short signatureIndex = (short) extractHighShortFromInt(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
                  dos.writeShort(nameIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
                  dos.writeShort(signatureIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
                  if (DEBUG) debugMessage("CP[" + ci + "] = N&T name = " + nameIndex
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
                                          + ", type = " + signatureIndex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
                  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
          } // switch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      dos.flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  public void printValueOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    tty.print("ConstantPool for " + getPoolHolder().getName().asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  public long getObjectSize() {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   478
    return alignObjectSize(headerSize + (getLength() * getElementSize()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  //----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  private static int extractHighShortFromInt(int val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    return (val >> 16) & 0xFFFF;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  private static int extractLowShortFromInt(int val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    return val & 0xFFFF;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
}