Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,11 @@ public boolean equals(Object obj) {
public String toString() {
return CodeUtil.append(new StringBuilder(100), this).toString();
}

/**
* Returns a copy of the array describing the Java kinds in {@link #values}.
*/
public JavaKind[] getSlotKinds() {
Copy link
Member

Choose a reason for hiding this comment

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

Keep in mind that slotKinds is being converted to a List. In that context, can we return the list without making a copy? Or is the caller expected to be able to mutate the return value?

Copy link
Contributor Author

@pecimuth pecimuth Jul 7, 2025

Choose a reason for hiding this comment

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

Applied the changes provided by @mur47x111.

return (slotKinds == null) ? null : slotKinds.clone();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,18 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof VirtualObject) {
VirtualObject l = (VirtualObject) o;
if (!l.type.equals(type) || l.values.length != values.length) {
if (o instanceof VirtualObject that) {
int thatValuesLength = (that.values == null) ? 0 : that.values.length;
int valuesLength = (values == null) ? 0 : values.length;
if (!that.type.equals(type) || thatValuesLength != valuesLength) {
return false;
}
for (int i = 0; i < values.length; i++) {
for (int i = 0; i < valuesLength; i++) {
/*
* Virtual objects can form cycles. Calling equals() could therefore lead to
* infinite recursion.
*/
if (!same(values[i], l.values[i])) {
if (!same(values[i], that.values[i])) {
return false;
}
}
Expand All @@ -311,4 +312,11 @@ public boolean equals(Object o) {
private static boolean same(Object o1, Object o2) {
return o1 == o2;
}

/**
* Returns a copy of the array containing the Java kinds of the values stored in this virtual object.
*/
public JavaKind[] getSlotKinds() {
Copy link
Member

Choose a reason for hiding this comment

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

Same comments as for BytecodeFrame.getSlotKinds. This applies to all other non-primitive array return values added by this PR.

Copy link
Contributor Author

@pecimuth pecimuth Jul 7, 2025

Choose a reason for hiding this comment

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

I left Object[] as the return value of EncodedSpeculationReason#getReason since the array could contain null elements, preventing the use of an immutable list like everywhere else.

Edit: SharedSecrets.getJavaUtilCollectionAccess().listFromTrustedArrayNullsAllowed could work here.

return (slotKinds == null) ? null : slotKinds.clone();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public Site(int pos) {
}

@Override
public final int hashCode() {
throw new UnsupportedOperationException("hashCode");
public int hashCode() {
return 41 * pcOffset;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,88 @@ public int getOffset(ResolvedJavaField field) {
}
});
}

/**
* Returns a copy of the compiled machine code.
*/
public byte[] getTargetCode() {
return (targetCode == null) ? null : targetCode.clone();
}

/**
* Gets the size of the compiled machine code in bytes.
*/
public int getTargetCodeSize() {
return targetCodeSize;
}

/**
* Returns a copy of the code annotations describing special sites in {@link #targetCode}.
*/
public Site[] getSites() {
return (sites == null) ? null : sites.clone();
}

/**
* Returns an array copy of the assumptions this code relies on.
*/
public Assumption[] getAssumptions() {
return (assumptions == null) ? null : assumptions.clone();
}

/**
* Returns an array copy of the methods whose bytecodes were used as input to the compilation.
*/
public ResolvedJavaMethod[] getMethods() {
return (methods == null) ? null : methods.clone();
}

/**
* Returns an array copy of the comments that are included in code dumps.
*/
public Comment[] getComments() {
return (comments == null) ? null : comments.clone();
}

/**
* Returns a copy of the data section containing serialized constants for the emitted machine code.
*/
public byte[] getDataSection() {
return (dataSection == null) ? null : dataSection.clone();
}

/**
* Gets the minimum alignment of the data section.
*/
public int getDataSectionAlignment() {
return dataSectionAlignment;
}

/**
* Returns a copy of the {@link #dataSection} relocations.
*/
public DataPatch[] getDataSectionPatches() {
return (dataSectionPatches == null) ? null : dataSectionPatches.clone();
}

/**
* Checks if this compiled code is immutable and position independent.
*/
public boolean isImmutablePIC() {
return isImmutablePIC;
}

/**
* Gets the total size of the stack frame of this compiled method.
*/
public int getTotalFrameSize() {
return totalFrameSize;
}

/**
* Gets the deoptimization rescue slot associated with this compiled code.
*/
public StackSlot getDeoptRescueSlot() {
return deoptRescueSlot;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,44 @@ public boolean hasScopedAccess() {
return false;
}

/**
* Returns the method to which this compiled nmethod belongs.
*/
public HotSpotResolvedJavaMethod getMethod() {
return method;
}

/**
* Returns the bytecode index (BCI) in the {@link #getMethod() method} that is the beginning of this compiled
* nmethod. -1 denotes the beginning of the method.
*
* @return the entry BCI of this nmethod or -1 if the entry is the method's beginning
*/
public int getEntryBCI() {
return entryBCI;
}

/**
* Returns the identifier of the compilation request.
*/
public int getId() {
return id;
}

/**
* Returns the address of a native {@code JVMCICompileState} object associated with this compiled nmethod.
* If no such object exists, it returns 0L.
*
* @return the address of the native {@code JVMCICompileState} object or 0L if it does not exist
*/
public long getCompileState() {
return compileState;
}

/**
* Checks if this compiled nmethod has a memory access via the {@code Unsafe} class.
*/
public boolean hasUnsafeAccess() {
return hasUnsafeAccess;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public HotSpotJavaType(String name) {
}

@Override
public final String getName() {
public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
*/
package jdk.vm.ci.hotspot;

import java.lang.invoke.CallSite;
import java.util.Objects;

import jdk.vm.ci.meta.Assumptions;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.ResolvedJavaType;
import jdk.vm.ci.meta.VMConstant;

import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.util.Objects;

/**
* Represents a constant non-{@code null} object reference, within the compiler and across the
* compiler/runtime interface.
Expand Down Expand Up @@ -61,7 +62,26 @@ public interface HotSpotObjectConstant extends JavaConstant, HotSpotConstant, VM
* change
* @return {@code null} if this constant does not represent a {@link CallSite} object
*/
JavaConstant getCallSiteTarget(Assumptions assumptions);
default JavaConstant getCallSiteTarget(Assumptions assumptions) {
Assumptions.AssumptionResult<JavaConstant> result = getCallSiteTarget();
if (!result.canRecordTo(assumptions)) {
return null;
}
result.recordTo(assumptions);
return result.getResult();
}

/**
* Gets the result of {@link CallSite#getTarget()} for the {@link CallSite} object represented
* by this constant. The target is bound to an assumption if this is not a fully initialized
* {@link ConstantCallSite}.
*
* @return a call-site target (possibly bound to an assumption) or {@code null} if this constant
* does not represent a {@link CallSite} object
*/
default Assumptions.AssumptionResult<JavaConstant> getCallSiteTarget() {
throw new UnsupportedOperationException("getCallSiteTarget");
}

/**
* Determines if this constant represents an {@linkplain String#intern() interned} string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,15 @@ private HotSpotObjectConstantImpl readTarget() {
}

@Override
public JavaConstant getCallSiteTarget(Assumptions assumptions) {
public Assumptions.AssumptionResult<JavaConstant> getCallSiteTarget() {
if (runtime().getCallSite().isInstance(this)) {
// For ConstantCallSites, we need to read "isFrozen" before reading "target"
// isFullyInitializedConstantCallSite() reads "isFrozen"
if (isFullyInitializedConstantCallSite()) {
return readTarget();
}
if (assumptions == null) {
return null;
return new Assumptions.AssumptionResult<>(readTarget());
}
HotSpotObjectConstantImpl result = readTarget();
assumptions.record(new Assumptions.CallSiteTargetValue(this, result));
return result;
return new Assumptions.AssumptionResult<>(result, new Assumptions.CallSiteTargetValue(this, result));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,32 @@

public abstract class HotSpotResolvedJavaType extends HotSpotJavaType implements ResolvedJavaType {

HotSpotResolvedObjectTypeImpl arrayOfType;
HotSpotResolvedObjectType arrayOfType;

HotSpotResolvedJavaType(String name) {
protected HotSpotResolvedJavaType(String name) {
super(name);
}

@Override
public abstract boolean equals(Object obj);

@Override
public final int hashCode() {
public int hashCode() {
return getName().hashCode();
}

abstract JavaConstant getJavaMirror();
/**
* Gets the runtime representation of the {@link Class} object of this type.
*/
public abstract JavaConstant getJavaMirror();

abstract HotSpotResolvedObjectTypeImpl getArrayType();
/**
* Gets the array type of this type without caching the result.
*/
protected abstract HotSpotResolvedObjectType getArrayType();

@Override
public final HotSpotResolvedObjectType getArrayClass() {
public HotSpotResolvedObjectType getArrayClass() {
if (arrayOfType == null) {
arrayOfType = getArrayType();
}
Expand All @@ -63,7 +69,7 @@ public final HotSpotResolvedObjectType getArrayClass() {
*
* @return {@code true} if this type is being initialized
*/
abstract boolean isBeingInitialized();
protected abstract boolean isBeingInitialized();

static void checkIsAnnotation(ResolvedJavaType type) {
if (!type.isAnnotation()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ default JavaKind getJavaKind() {
@Override
AssumptionResult<ResolvedJavaMethod> findUniqueConcreteMethod(ResolvedJavaMethod method);

/**
* Gets the runtime representation of the {@link Class} object of this type.
*/
default JavaConstant getJavaMirror() {
throw new UnsupportedOperationException("getJavaMirror");
}

/**
* Performs a fast-path check that this type is resolved in the context of a given accessing
* class. A negative result does not mean this type is not resolved with respect to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,12 @@ public boolean equals(Object obj) {
}

@Override
JavaConstant getJavaMirror() {
public JavaConstant getJavaMirror() {
return mirror;
}

@Override
HotSpotResolvedObjectTypeImpl getArrayType() {
protected HotSpotResolvedObjectTypeImpl getArrayType() {
return runtime().compilerToVm.getArrayType((char) 0, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ private HotSpotResolvedPrimitiveType(JavaKind kind, HotSpotObjectConstantImpl mi
this.kind = kind;
}

static HotSpotResolvedPrimitiveType forKind(JavaKind kind) {
/**
* Returns a primitive type instance corresponding to the given {@link JavaKind}.
*
* @param kind the Java kind of the primitive type
* @return the primitive type instance for the given Java kind
*/
public static HotSpotResolvedPrimitiveType forKind(JavaKind kind) {
HotSpotResolvedPrimitiveType primitive = primitives[kind.getBasicType()];
assert primitive != null : kind;
return primitive;
Expand All @@ -84,7 +90,7 @@ public int getModifiers() {
}

@Override
HotSpotResolvedObjectTypeImpl getArrayType() {
protected HotSpotResolvedObjectType getArrayType() {
if (kind == JavaKind.Void) {
return null;
}
Expand Down Expand Up @@ -321,7 +327,7 @@ public boolean equals(Object obj) {
}

@Override
JavaConstant getJavaMirror() {
public JavaConstant getJavaMirror() {
return mirror;
}

Expand Down
Loading