Skip to content

Commit 07ff702

Browse files
committed
making acmp profile information available over jvmci
1 parent f4aef2b commit 07ff702

File tree

8 files changed

+232
-5
lines changed

8 files changed

+232
-5
lines changed

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ C2V_VMENTRY_NULL(jobject, getConstantPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(
431431
return JVMCIENV->get_jobject(result);
432432
}
433433

434-
C2V_VMENTRY_NULL(jobject, getResolvedJavaType0, (JNIEnv* env, jobject, jobject base, jlong offset, jboolean compressed))
434+
C2V_VMENTRY_NULL(jobject, getResolvedJavaType0, (JNIEnv* env, jobject, jobject base, jlong offset, jboolean compressed, jlong mask))
435435
JVMCIObject base_object = JVMCIENV->wrap(base);
436436
if (base_object.is_null()) {
437437
JVMCI_THROW_MSG_NULL(NullPointerException, "base object is null");
@@ -494,7 +494,7 @@ C2V_VMENTRY_NULL(jobject, getResolvedJavaType0, (JNIEnv* env, jobject, jobject b
494494
}
495495
} else if (JVMCIENV->isa_HotSpotMethodData(base_object)) {
496496
jlong base_address = (intptr_t) JVMCIENV->asMethodData(base_object);
497-
klass = *((Klass**) (intptr_t) (base_address + offset));
497+
klass = *((Klass**) (intptr_t) ((base_address + offset)&mask));
498498
if (klass == nullptr || !klass->is_loader_alive()) {
499499
// Klasses in methodData might be concurrently unloading so return null in that case.
500500
return nullptr;
@@ -3245,7 +3245,7 @@ JNINativeMethod CompilerToVM::methods[] = {
32453245
{CC "asResolvedJavaMethod", CC "(" EXECUTABLE ")" HS_METHOD, FN_PTR(asResolvedJavaMethod)},
32463246
{CC "getResolvedJavaMethod", CC "(" OBJECTCONSTANT "J)" HS_METHOD, FN_PTR(getResolvedJavaMethod)},
32473247
{CC "getConstantPool", CC "(" OBJECT "JZ)" HS_CONSTANT_POOL, FN_PTR(getConstantPool)},
3248-
{CC "getResolvedJavaType0", CC "(Ljava/lang/Object;JZ)" HS_KLASS, FN_PTR(getResolvedJavaType0)},
3248+
{CC "getResolvedJavaType0", CC "(Ljava/lang/Object;JZJ)" HS_KLASS, FN_PTR(getResolvedJavaType0)},
32493249
{CC "readConfiguration", CC "()[" OBJECT, FN_PTR(readConfiguration)},
32503250
{CC "installCode0", CC "(JJZ" HS_COMPILED_CODE "[" OBJECT INSTALLED_CODE "J[B)I", FN_PTR(installCode0)},
32513251
{CC "getInstallCodeFlags", CC "()I", FN_PTR(getInstallCodeFlags)},
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package jdk.vm.ci.hotspot;
2+
3+
public interface ACmpDataAccessor {
4+
public SingleTypeEntry getLeft();
5+
6+
public SingleTypeEntry getRight();
7+
8+
public static ACmpDataAccessor create(){
9+
return new HotSpotMethodData.ACmpData.ACmpDataAccessorImpl();
10+
}
11+
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/CompilerToVM.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,16 @@ HotSpotConstantPool getConstantPool(MetaspaceObject object) {
986986
* @return null or the resolved method for this location
987987
* @throws NullPointerException if {@code base == null}
988988
*/
989-
private native HotSpotResolvedObjectTypeImpl getResolvedJavaType0(Object base, long displacement, boolean compressed);
989+
990+
private native HotSpotResolvedObjectTypeImpl getResolvedJavaType0(Object base, long displacement, boolean compressed, long mask);
991+
992+
HotSpotResolvedObjectTypeImpl getResolvedJavaType0(Object base, long displacement, boolean compressed){
993+
return getResolvedJavaType0(base, displacement, compressed, -1);
994+
}
995+
996+
HotSpotResolvedObjectTypeImpl getResolvedJavaType(Object base, long displacement, long mask){
997+
return getResolvedJavaType0(base, displacement, false, mask);
998+
}
990999

9911000
HotSpotResolvedObjectTypeImpl getResolvedJavaType(HotSpotConstantPool base, long displacement) {
9921001
return getResolvedJavaType0(base, displacement, false);

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotMethodData.java

Lines changed: 151 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ static final class VMState {
7777
final int branchDataSize = cellIndexToOffset(3);
7878
final int notTakenCountOffset = cellIndexToOffset(config.branchDataNotTakenOffset);
7979

80+
// inherits from branch and two cells for types
81+
final int acmpDataSize = branchDataSize+ cellsToBytes(1)*2;
82+
final int leftOperandOffset = cellIndexToOffset(3);
83+
final int rightOperandOffset = cellIndexToOffset(4);
84+
final int leftInlineTypeFlag = 1;
85+
final int rightInlineTypeFlag = 1<<1;
86+
8087
final int arrayDataLengthOffset = cellIndexToOffset(config.arrayDataArrayLenOffset);
8188
final int arrayDataStartOffset = cellIndexToOffset(config.arrayDataArrayStartOffset);
8289

@@ -107,7 +114,7 @@ static final class VMState {
107114
new UnknownProfileData(this, config.dataLayoutSpeculativeTrapDataTag),
108115
new UnknownProfileData(this, config.dataLayoutArrayStoreDataTag),
109116
new UnknownProfileData(this, config.dataLayoutArrayLoadDataTag),
110-
new UnknownProfileData(this, config.dataLayoutACmpDataTag),
117+
new ACmpData(this, config.dataLayoutACmpDataTag),
111118
};
112119
// @formatter:on
113120

@@ -291,6 +298,11 @@ private int readUnsignedIntAsSignedInt(int position, int offsetInBytes) {
291298
return VMState.truncateLongToInt(value);
292299
}
293300

301+
private long readPointer(int position, int offsetInBytes) {
302+
long fullOffsetInBytes = state.computeFullOffset(position, offsetInBytes);
303+
return UNSAFE.getAddress(methodDataPointer + fullOffsetInBytes);
304+
}
305+
294306
/**
295307
* Since the values are stored in cells (platform words) this method uses
296308
* {@link Unsafe#getAddress} to read the right value on both little and big endian machines.
@@ -693,6 +705,10 @@ static class BranchData extends JumpData {
693705
super(state, tag, state.branchDataSize);
694706
}
695707

708+
protected BranchData(VMState state, int tag, int staticSize) {
709+
super(state, tag, staticSize);
710+
}
711+
696712
@Override
697713
public double getBranchTakenProbability(HotSpotMethodData data, int position) {
698714
long takenCount = data.readUnsignedInt(position, state.takenCountOffset);
@@ -717,6 +733,140 @@ public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos)
717733
}
718734
}
719735

736+
static class ACmpData extends BranchData {
737+
738+
static class SingleTypeEntryImpl implements SingleTypeEntry {
739+
final long value;
740+
final boolean inlineType;
741+
final HotSpotMethodData data;
742+
final int offset;
743+
HotSpotResolvedObjectType validType;
744+
745+
final static long nullSeen =1;
746+
final static long typeMask = ~nullSeen;
747+
final static long typeUnknown = 2;
748+
final static long statusBits = nullSeen | typeUnknown;
749+
final static long typeKlassMask = ~statusBits;
750+
751+
SingleTypeEntryImpl(long value, boolean inlineType, HotSpotMethodData data, int offset) {
752+
this.value = value;
753+
this.inlineType = inlineType;
754+
this.data = data;
755+
this.offset = offset;
756+
this.validType = computeValidType();
757+
}
758+
759+
760+
@Override
761+
public boolean isTypeNone(){
762+
return (value & typeMask) == 0;
763+
}
764+
765+
@Override
766+
public boolean isTypeUnknown(){
767+
return (value & typeUnknown) != 0;
768+
}
769+
770+
@Override
771+
public boolean wasNullSeen(){
772+
return (value & nullSeen) != 0;
773+
}
774+
775+
@Override
776+
public long klassPart(){
777+
return value & typeKlassMask;
778+
}
779+
780+
private HotSpotResolvedObjectType computeValidType(){
781+
if(!isTypeNone() && ! isTypeUnknown()){
782+
return compilerToVM().getResolvedJavaType(data, offset, typeKlassMask);
783+
}else{
784+
return null;
785+
}
786+
787+
}
788+
789+
@Override
790+
public HotSpotResolvedObjectType getValidType(){
791+
return validType;
792+
}
793+
794+
@Override
795+
public boolean maybeNull(){
796+
return wasNullSeen() && isTypeNone();
797+
}
798+
799+
@Override
800+
public boolean neverNull(){
801+
return wasNullSeen();
802+
}
803+
804+
@Override
805+
public boolean alwaysNull(){
806+
return maybeNull();
807+
}
808+
809+
@Override
810+
public boolean inlineType(){
811+
return inlineType;
812+
}
813+
814+
}
815+
816+
static class ACmpDataAccessorImpl implements ACmpDataAccessor{
817+
818+
private final SingleTypeEntry left;
819+
private final SingleTypeEntry right;
820+
821+
ACmpDataAccessorImpl(ACmpData aCmpData, HotSpotMethodData data, int position){
822+
left = aCmpData.getLeft(data, position);
823+
right = aCmpData.getRight(data, position);
824+
}
825+
826+
ACmpDataAccessorImpl(){
827+
// left = new SingleTypeEntryImpl(1, true, null, 0);
828+
// right = new SingleTypeEntryImpl(1, false, null, 0);
829+
left = null;
830+
right = null;
831+
}
832+
833+
@Override
834+
public SingleTypeEntry getLeft() {
835+
return left;
836+
}
837+
838+
@Override
839+
public SingleTypeEntry getRight() {
840+
return right;
841+
}
842+
}
843+
844+
845+
ACmpData(VMState state, int tag) {
846+
super(state, tag, state.acmpDataSize);
847+
}
848+
849+
private SingleTypeEntry getLeft(HotSpotMethodData data, int position) {
850+
return new SingleTypeEntryImpl(data.readPointer(position, state.leftOperandOffset), inlineType(data, position, true), data, state.computeFullOffset(position, state.leftOperandOffset));
851+
}
852+
853+
private SingleTypeEntry getRight(HotSpotMethodData data, int position) {
854+
return new SingleTypeEntryImpl(data.readPointer(position, state.rightOperandOffset), inlineType(data, position, false), data, state.computeFullOffset(position, state.rightOperandOffset));
855+
}
856+
857+
private boolean inlineType(HotSpotMethodData data, int position, boolean left){
858+
if(left){
859+
return (getFlags(data, position) & state.leftInlineTypeFlag) !=0;
860+
}
861+
return (getFlags(data, position) & state.rightInlineTypeFlag) !=0;
862+
}
863+
864+
public ACmpDataAccessor getACmpAccessor(HotSpotMethodData data, int position){
865+
return new ACmpDataAccessorImpl(this, data, position);
866+
}
867+
868+
}
869+
720870
static class ArrayData extends HotSpotMethodDataAccessor {
721871

722872
ArrayData(VMState state, int tag, int staticSize) {

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotProfilingInfo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ public TriState getExceptionSeen(int bci) {
124124
return dataAccessor.getExceptionSeen(methodData, position);
125125
}
126126

127+
@Override
128+
public ACmpDataAccessor getAcmpData(int bci) {
129+
// if (!isMature) {
130+
// return null;
131+
// }
132+
findBCI(bci);
133+
if(dataAccessor instanceof HotSpotMethodData.ACmpData aCmpData){
134+
return aCmpData.getACmpAccessor(methodData, position);
135+
}
136+
return null;
137+
}
138+
127139
@Override
128140
public TriState getNullSeen(int bci) {
129141
findBCI(bci);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package jdk.vm.ci.hotspot;
2+
3+
public interface SingleTypeEntry{
4+
5+
6+
boolean isTypeNone();
7+
8+
boolean isTypeUnknown();
9+
10+
boolean wasNullSeen();
11+
12+
long klassPart();
13+
14+
HotSpotResolvedObjectType getValidType();
15+
16+
boolean maybeNull();
17+
18+
boolean neverNull();
19+
20+
boolean alwaysNull();
21+
22+
boolean inlineType();
23+
24+
}

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/DefaultProfilingInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
package jdk.vm.ci.meta;
2424

25+
import jdk.vm.ci.hotspot.ACmpDataAccessor;
26+
2527
/**
2628
* An implementation of {@link ProfilingInfo} that can used in the absence of real profile
2729
* information.
@@ -67,6 +69,12 @@ public TriState getExceptionSeen(int bci) {
6769
return exceptionSeen;
6870
}
6971

72+
@Override
73+
public ACmpDataAccessor getAcmpData(int bci) {
74+
//return ACmpDataAccessor.create();
75+
return null;
76+
}
77+
7078
@Override
7179
public TriState getNullSeen(int bci) {
7280
return TriState.UNKNOWN;

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/ProfilingInfo.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
package jdk.vm.ci.meta;
2424

25+
import jdk.vm.ci.hotspot.ACmpDataAccessor;
26+
2527
/**
2628
* Provides access to the profiling information of one specific method. Every accessor method
2729
* returns the information that is available at the time of invocation. If a method is invoked
@@ -75,6 +77,13 @@ public interface ProfilingInfo {
7577
*/
7678
TriState getExceptionSeen(int bci);
7779

80+
/**
81+
* Returns the AcmpProfile for the given BCI.
82+
*
83+
* @return Returns a AcmpData object, or null if not available.
84+
*/
85+
ACmpDataAccessor getAcmpData(int bci);
86+
7887
/**
7988
* Returns information if null was ever seen for the given BCI. This information is collected
8089
* for the aastore, checkcast and instanceof bytecodes.
@@ -171,6 +180,10 @@ default String toString(ResolvedJavaMethod method, String sep) {
171180
buf.append(String.format("nullSeen@%d: %s%s", i, getNullSeen(i).name(), sep));
172181
}
173182

183+
if (getAcmpData(i) != null) {
184+
buf.append("acmp_found\n");
185+
}
186+
174187
JavaTypeProfile typeProfile = getTypeProfile(i);
175188
MetaUtil.appendProfile(buf, typeProfile, i, "types", sep);
176189

0 commit comments

Comments
 (0)