8309673: Refactor ref_at methods in SA ConstantPool

Reviewed-by: coleenp, fparain, iklam
This commit is contained in:
Matias Saavedra Silva 2023-06-09 19:08:38 +00:00
parent 7a970b251d
commit 7d6f97d04d
4 changed files with 70 additions and 63 deletions
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot

@ -37,17 +37,17 @@ public abstract class BytecodeGetPut extends BytecodeWithCPIndex {
// returns the name of the accessed field
public Symbol name() {
ConstantPool cp = method().getConstants();
return cp.getNameRefAt(index());
return cp.getNameRefAt(index(), javaCode());
}
// returns the signature of the accessed field
public Symbol signature() {
ConstantPool cp = method().getConstants();
return cp.getSignatureRefAt(index());
return cp.getSignatureRefAt(index(), javaCode());
}
public Field getField() {
return method().getConstants().getFieldRefAt(index());
return method().getConstants().getFieldRefAt(index(), javaCode());
}
public String toString() {

@ -57,7 +57,7 @@ public class BytecodeInvoke extends BytecodeWithCPIndex {
if (isInvokedynamic()) {
return cp.uncachedGetNameRefAt(indexForFieldOrMethod());
}
return cp.getNameRefAt(index());
return cp.getNameRefAt(index(), adjustedInvokeCode());
}
// returns the signature of the invoked method
@ -66,11 +66,11 @@ public class BytecodeInvoke extends BytecodeWithCPIndex {
if (isInvokedynamic()) {
return cp.uncachedGetSignatureRefAt(indexForFieldOrMethod());
}
return cp.getSignatureRefAt(index());
return cp.getSignatureRefAt(index(), adjustedInvokeCode());
}
public Method getInvokedMethod() {
return method().getConstants().getMethodRefAt(index());
return method().getConstants().getMethodRefAt(index(), adjustedInvokeCode());
}
// returns the result type (see BasicType.java) of the invoke

@ -27,6 +27,7 @@ package sun.jvm.hotspot.oops;
import java.io.*;
import java.util.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.interpreter.Bytecodes;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.utilities.*;
@ -252,6 +253,31 @@ public class ConstantPool extends Metadata implements ClassConstants {
return res;
}
// Translate index, which could be CPCache index or Indy index, to a constant pool index
public int to_cp_index(int index, int code) {
Assert.that(getCache() != null, "'index' is a rewritten index so this class must have been rewritten");
switch(code) {
case Bytecodes._invokedynamic:
int poolIndex = getCache().getIndyEntryAt(index).getConstantPoolIndex();
return invokeDynamicNameAndTypeRefIndexAt(poolIndex);
case Bytecodes._getfield:
case Bytecodes._getstatic:
case Bytecodes._putfield:
case Bytecodes._putstatic:
// TODO: handle resolved field entries with new structure
// i = ....
case Bytecodes._invokeinterface:
case Bytecodes._invokehandle:
case Bytecodes._invokespecial:
case Bytecodes._invokestatic:
case Bytecodes._invokevirtual:
// TODO: handle resolved method entries with new structure
default:
// change byte-ordering and go via cache
return remapInstructionOperandFromCache(index);
}
}
public int[] getNameAndTypeAt(int which) {
if (Assert.ASSERTS_ENABLED) {
Assert.that(getTagAt(which).isNameAndType(), "Corrupted constant pool: " + which + " " + getTagAt(which));
@ -263,29 +289,23 @@ public class ConstantPool extends Metadata implements ClassConstants {
return new int[] { extractLowShortFromInt(i), extractHighShortFromInt(i) };
}
public Symbol getNameRefAt(int which) {
return implGetNameRefAt(which, false);
public Symbol getNameRefAt(int which, int code) {
int name_index = getNameRefIndexAt(getNameAndTypeRefIndexAt(which, code));
return getSymbolAt(name_index);
}
public Symbol uncachedGetNameRefAt(int which) {
return implGetNameRefAt(which, true);
public Symbol uncachedGetNameRefAt(int cp_index) {
int name_index = getNameRefIndexAt(uncachedGetNameAndTypeRefIndexAt(cp_index));
return getSymbolAt(name_index);
}
private Symbol implGetNameRefAt(int which, boolean uncached) {
int signatureIndex = getNameRefIndexAt(implNameAndTypeRefIndexAt(which, uncached));
public Symbol getSignatureRefAt(int which, int code) {
int signatureIndex = getSignatureRefIndexAt(getNameAndTypeRefIndexAt(which, code));
return getSymbolAt(signatureIndex);
}
public Symbol getSignatureRefAt(int which) {
return implGetSignatureRefAt(which, false);
}
public Symbol uncachedGetSignatureRefAt(int which) {
return implGetSignatureRefAt(which, true);
}
private Symbol implGetSignatureRefAt(int which, boolean uncached) {
int signatureIndex = getSignatureRefIndexAt(implNameAndTypeRefIndexAt(which, uncached));
public Symbol uncachedGetSignatureRefAt(int cp_index) {
int signatureIndex = getSignatureRefIndexAt(uncachedGetNameAndTypeRefIndexAt(cp_index));
return getSymbolAt(signatureIndex);
}
@ -307,31 +327,22 @@ public class ConstantPool extends Metadata implements ClassConstants {
return getCache().getEntryAt(cpCacheIndex);
}
private int implNameAndTypeRefIndexAt(int which, boolean uncached) {
int i = which;
if (!uncached && getCache() != null) {
if (isInvokedynamicIndex(which)) {
// Invokedynamic index is index into resolved_references
int poolIndex = getCache().getIndyEntryAt(which).getConstantPoolIndex();
poolIndex = invokeDynamicNameAndTypeRefIndexAt(poolIndex);
Assert.that(getTagAt(poolIndex).isNameAndType(), "");
return poolIndex;
}
// change byte-ordering and go via cache
i = remapInstructionOperandFromCache(which);
} else {
if (getTagAt(which).isInvokeDynamic() || getTagAt(which).isDynamicConstant()) {
int poolIndex = invokeDynamicNameAndTypeRefIndexAt(which);
Assert.that(getTagAt(poolIndex).isNameAndType(), "");
return poolIndex;
}
public int uncachedGetNameAndTypeRefIndexAt(int cp_index) {
if (getTagAt(cp_index).isInvokeDynamic() || getTagAt(cp_index).isDynamicConstant()) {
int poolIndex = invokeDynamicNameAndTypeRefIndexAt(cp_index);
Assert.that(getTagAt(poolIndex).isNameAndType(), "");
return poolIndex;
}
// assert(tag_at(i).is_field_or_method(), "Corrupted constant pool");
// assert(!tag_at(i).is_invoke_dynamic(), "Must be handled above");
int refIndex = getIntAt(i);
int refIndex = getIntAt(cp_index);
return extractHighShortFromInt(refIndex);
}
public int getNameAndTypeRefIndexAt(int index, int code) {
return uncachedGetNameAndTypeRefIndexAt(to_cp_index(index, code));
}
private int remapInstructionOperandFromCache(int operand) {
int cpc_index = operand;
// DEBUG_ONLY(cpc_index -= CPCACHE_INDEX_TAG);
@ -370,11 +381,11 @@ public class ConstantPool extends Metadata implements ClassConstants {
}
// returns null, if not resolved.
public Method getMethodRefAt(int which) {
public Method getMethodRefAt(int which, int code) {
Klass klass = getFieldOrMethodKlassRefAt(which);
if (klass == null) return null;
Symbol name = getNameRefAt(which);
Symbol sig = getSignatureRefAt(which);
Symbol name = getNameRefAt(which, code);
Symbol sig = getSignatureRefAt(which, code);
// Consider the super class for arrays. (java.lang.Object)
if (klass.isArrayKlass()) {
klass = klass.getJavaSuper();
@ -383,18 +394,14 @@ public class ConstantPool extends Metadata implements ClassConstants {
}
// returns null, if not resolved.
public Field getFieldRefAt(int which) {
public Field getFieldRefAt(int which, int code) {
InstanceKlass klass = (InstanceKlass)getFieldOrMethodKlassRefAt(which);
if (klass == null) return null;
Symbol name = getNameRefAt(which);
Symbol sig = getSignatureRefAt(which);
Symbol name = getNameRefAt(which, code);
Symbol sig = getSignatureRefAt(which, code);
return klass.findField(name.asString(), sig.asString());
}
public int getNameAndTypeRefIndexAt(int index) {
return implNameAndTypeRefIndexAt(index, false);
}
/** Lookup for entries consisting of (name_index, signature_index) */
public int getNameRefIndexAt(int index) {
int[] refIndex = getNameAndTypeAt(index);

@ -1374,16 +1374,16 @@ public class GenerateOopMap {
case Bytecodes._jsr: doJsr(itr.dest()); break;
case Bytecodes._jsr_w: doJsr(itr.dest_w()); break;
case Bytecodes._getstatic: doField(true, true, itr.getIndexU2Cpcache(), itr.bci()); break;
case Bytecodes._putstatic: doField(false, true, itr.getIndexU2Cpcache(), itr.bci()); break;
case Bytecodes._getfield: doField(true, false, itr.getIndexU2Cpcache(), itr.bci()); break;
case Bytecodes._putfield: doField(false, false, itr.getIndexU2Cpcache(), itr.bci()); break;
case Bytecodes._getstatic: doField(true, true, itr.getIndexU2Cpcache(), itr.bci(), itr.code()); break;
case Bytecodes._putstatic: doField(false, true, itr.getIndexU2Cpcache(), itr.bci(), itr.code()); break;
case Bytecodes._getfield: doField(true, false, itr.getIndexU2Cpcache(), itr.bci(), itr.code()); break;
case Bytecodes._putfield: doField(false, false, itr.getIndexU2Cpcache(), itr.bci(), itr.code()); break;
case Bytecodes._invokevirtual:
case Bytecodes._invokespecial: doMethod(false, false, itr.getIndexU2Cpcache(), itr.bci()); break;
case Bytecodes._invokestatic: doMethod(true, false, itr.getIndexU2Cpcache(), itr.bci()); break;
case Bytecodes._invokedynamic: doMethod(true, false, itr.getIndexU4(), itr.bci()); break;
case Bytecodes._invokeinterface: doMethod(false, true, itr.getIndexU2Cpcache(), itr.bci()); break;
case Bytecodes._invokespecial: doMethod(false, false, itr.getIndexU2Cpcache(), itr.bci(), itr.code()); break;
case Bytecodes._invokestatic: doMethod(true, false, itr.getIndexU2Cpcache(), itr.bci(), itr.code()); break;
case Bytecodes._invokedynamic: doMethod(true, false, itr.getIndexU4(), itr.bci(), itr.code()); break;
case Bytecodes._invokeinterface: doMethod(false, true, itr.getIndexU2Cpcache(), itr.bci(), itr.code()); break;
case Bytecodes._newarray:
case Bytecodes._anewarray: ppNewRef(vCTS, itr.bci()); break;
case Bytecodes._checkcast: doCheckcast(); break;
@ -1688,10 +1688,10 @@ public class GenerateOopMap {
push(CellTypeState.makeAddr(targBCI));
}
void doField (boolean is_get, boolean is_static, int idx, int bci) {
void doField (boolean is_get, boolean is_static, int idx, int bci, int bc) {
// Dig up signature for field in constant pool
ConstantPool cp = method().getConstants();
int nameAndTypeIdx = cp.getNameAndTypeRefIndexAt(idx);
int nameAndTypeIdx = cp.getNameAndTypeRefIndexAt(idx, bc);
int signatureIdx = cp.getSignatureRefIndexAt(nameAndTypeIdx);
Symbol signature = cp.getSymbolAt(signatureIdx);
@ -1724,10 +1724,10 @@ public class GenerateOopMap {
pp(in, out);
}
void doMethod (boolean is_static, boolean is_interface, int idx, int bci) {
void doMethod (boolean is_static, boolean is_interface, int idx, int bci, int bc) {
// Dig up signature for field in constant pool
ConstantPool cp = _method.getConstants();
Symbol signature = cp.getSignatureRefAt(idx);
Symbol signature = cp.getSignatureRefAt(idx, bc);
// Parse method signature
CellTypeStateList out = new CellTypeStateList(4);