hotspot/agent/src/share/classes/sun/jvm/hotspot/oops/ConstantPoolCache.java
changeset 10251 71b8938a2821
parent 7662 5f31baaff55b
child 13728 882756847a04
equal deleted inserted replaced
10250:0794cd144834 10251:71b8938a2821
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    70   public long getObjectSize() {
    70   public long getObjectSize() {
    71     return alignObjectSize(baseOffset + getLength() * elementSize);
    71     return alignObjectSize(baseOffset + getLength() * elementSize);
    72   }
    72   }
    73 
    73 
    74   public ConstantPoolCacheEntry getEntryAt(int i) {
    74   public ConstantPoolCacheEntry getEntryAt(int i) {
    75     if (Assert.ASSERTS_ENABLED) {
    75     if (i < 0 || i >= getLength()) throw new IndexOutOfBoundsException(i + " " + getLength());
    76       Assert.that(0 <= i && i < getLength(), "index out of bounds");
       
    77     }
       
    78     return new ConstantPoolCacheEntry(this, i);
    76     return new ConstantPoolCacheEntry(this, i);
    79   }
    77   }
    80 
    78 
    81   public static boolean isSecondaryIndex(int i)     { return (i < 0); }
    79   public static boolean isSecondaryIndex(int i)     { return (i < 0); }
    82   public static int     decodeSecondaryIndex(int i) { return  isSecondaryIndex(i) ? ~i : i; }
    80   public static int     decodeSecondaryIndex(int i) { return  isSecondaryIndex(i) ? ~i : i; }
    83   public static int     encodeSecondaryIndex(int i) { return !isSecondaryIndex(i) ? ~i : i; }
    81   public static int     encodeSecondaryIndex(int i) { return !isSecondaryIndex(i) ? ~i : i; }
    84 
    82 
    85   // secondary entries hold invokedynamic call site bindings
    83   // secondary entries hold invokedynamic call site bindings
    86   public ConstantPoolCacheEntry getSecondaryEntryAt(int i) {
    84   public ConstantPoolCacheEntry getSecondaryEntryAt(int i) {
    87     ConstantPoolCacheEntry e = new ConstantPoolCacheEntry(this, decodeSecondaryIndex(i));
    85     int rawIndex = i;
       
    86     if (isSecondaryIndex(i)) {
       
    87       rawIndex = decodeSecondaryIndex(i);
       
    88     }
       
    89     ConstantPoolCacheEntry e = getEntryAt(rawIndex);
    88     if (Assert.ASSERTS_ENABLED) {
    90     if (Assert.ASSERTS_ENABLED) {
    89       Assert.that(e.isSecondaryEntry(), "must be a secondary entry");
    91       Assert.that(e.isSecondaryEntry(), "must be a secondary entry:" + rawIndex);
    90     }
    92     }
    91     return e;
    93     return e;
    92   }
    94   }
    93 
    95 
    94   public ConstantPoolCacheEntry getMainEntryAt(int i) {
    96   public ConstantPoolCacheEntry getMainEntryAt(int i) {
       
    97     int primaryIndex = i;
    95     if (isSecondaryIndex(i)) {
    98     if (isSecondaryIndex(i)) {
    96       // run through an extra level of indirection:
    99       // run through an extra level of indirection:
    97       i = getSecondaryEntryAt(i).getMainEntryIndex();
   100       int rawIndex = decodeSecondaryIndex(i);
       
   101       primaryIndex = getEntryAt(rawIndex).getMainEntryIndex();
    98     }
   102     }
    99     ConstantPoolCacheEntry e = new ConstantPoolCacheEntry(this, i);
   103     ConstantPoolCacheEntry e = getEntryAt(primaryIndex);
   100     if (Assert.ASSERTS_ENABLED) {
   104     if (Assert.ASSERTS_ENABLED) {
   101       Assert.that(!e.isSecondaryEntry(), "must not be a secondary entry");
   105       Assert.that(!e.isSecondaryEntry(), "must not be a secondary entry:" + primaryIndex);
   102     }
   106     }
   103     return e;
   107     return e;
   104   }
   108   }
   105 
   109 
   106   public int getIntAt(int entry, int fld) {
   110   public int getIntAt(int entry, int fld) {