Skip to content

Commit

Permalink
8309673: Refactor ref_at methods in SA ConstantPool
Browse files Browse the repository at this point in the history
Reviewed-by: coleenp, fparain, iklam
  • Loading branch information
Matias Saavedra Silva committed Jun 9, 2023
1 parent 7a970b2 commit 7d6f97d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Symbol name() {
if (isInvokedynamic()) {
return cp.uncachedGetNameRefAt(indexForFieldOrMethod());
}
return cp.getNameRefAt(index());
return cp.getNameRefAt(index(), adjustedInvokeCode());
}

// returns the signature of the invoked method
Expand All @@ -66,11 +66,11 @@ public Symbol signature() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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.*;
Expand Down Expand Up @@ -252,6 +253,31 @@ public int getFieldOrMethodAt(int which) {
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));
Expand All @@ -263,29 +289,23 @@ public int[] getNameAndTypeAt(int which) {
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);
}

Expand All @@ -307,31 +327,22 @@ ConstantPoolCacheEntry invokedynamicCPCacheEntryAt(int index) {
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);
Expand Down Expand Up @@ -370,11 +381,11 @@ public Klass getFieldOrMethodKlassRefAt(int which) {
}

// 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();
Expand All @@ -383,18 +394,14 @@ public Method getMethodRefAt(int which) {
}

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1374,16 +1374,16 @@ void interp1 (BytecodeStream itr) {
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;
Expand Down Expand Up @@ -1688,10 +1688,10 @@ void doJsr (int targBCI) {
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);

Expand Down Expand Up @@ -1724,10 +1724,10 @@ void doField (boolean is_get, boolean is_static, in
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);
Expand Down

1 comment on commit 7d6f97d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.