Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .ci/common.libsonnet
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
# The JVMCI releases that can be built from this repo.
jvmci_releases:: [
self.JVMCIRelease(name='25.1', build='b10', jdk_version='25.0.1+8')
self.JVMCIRelease(name='25.1', build='b11', jdk_version='25.0.1+8')
],

# Specifies a JVMCI release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
*/
package jdk.vm.ci.hotspot;

import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;

import java.util.Objects;

import jdk.vm.ci.common.JVMCIError;
import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.ConstantReflectionProvider;
Expand All @@ -36,6 +32,10 @@
import jdk.vm.ci.meta.ResolvedJavaField;
import jdk.vm.ci.meta.ResolvedJavaType;

import java.util.Objects;

import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;

/**
* HotSpot implementation of {@link ConstantReflectionProvider}.
*/
Expand Down Expand Up @@ -190,4 +190,16 @@ public Constant asObjectHub(ResolvedJavaType type) {
throw JVMCIError.unimplemented();
}
}

@Override
public Integer identityHashCode(JavaConstant constant) {
JavaKind kind = Objects.requireNonNull(constant).getJavaKind();
if (kind != JavaKind.Object) {
throw new IllegalArgumentException("Constant has unexpected kind " + kind + ": " + constant);
} else if (constant.isNull()) {
/* System.identityHashCode is specified to return 0 when passed null. */
return 0;
}
return ((HotSpotObjectConstant) constant).getIdentityHashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
*/
package jdk.vm.ci.hotspot;

import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE;

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

import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime;
import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE;

/**
* Represents a constant non-{@code null} object reference, within the compiler and across the
* compiler/runtime interface.
Expand Down Expand Up @@ -57,20 +57,11 @@ public boolean isCompressible() {
return !compressed;
}

@Override
public abstract JavaConstant compress();

@Override
public abstract JavaConstant uncompress();

@Override
public HotSpotResolvedObjectType getType() {
return runtime().reflection.getType(this);
}

@Override
public abstract int getIdentityHashCode();

private boolean isFullyInitializedConstantCallSite() {
if (!runtime().getConstantCallSite().isInstance(this)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -71,15 +71,15 @@ public interface ConstantReflectionProvider {
/**
* Converts the given {@link JavaKind#isPrimitive() primitive} constant to a boxed
* {@link JavaKind#Object object} constant, according to the Java boxing rules. Returns
* {@code null} if the source is is not a primitive constant, or the boxed value is not
* {@code null} if the source is not a primitive constant, or the boxed value is not
* available at this point.
*/
JavaConstant boxPrimitive(JavaConstant source);

/**
* Converts the given {@link JavaKind#Object object} constant to a {@link JavaKind#isPrimitive()
* primitive} constant, according to the Java unboxing rules. Returns {@code null} if the source
* is is not an object constant that can be unboxed, or the unboxed value is not available at
* is not an object constant that can be unboxed, or the unboxed value is not available at
* this point.
*/
JavaConstant unboxPrimitive(JavaConstant source);
Expand Down Expand Up @@ -116,4 +116,15 @@ public interface ConstantReflectionProvider {
* type representation which is typically stored in the object header.
*/
Constant asObjectHub(ResolvedJavaType type);

/**
* Gets the identity hash code of the object value represented by {@code constant}.
* <p>
* For the {@link JavaConstant#isNull() null constant}, this method returns zero as specified by
* {@link System#identityHashCode(Object)}.
*
* @throws NullPointerException if {@code constant == null}
* @throws IllegalArgumentException if {@code constant.getJavaKind() != JavaKind.Object}
*/
Integer identityHashCode(JavaConstant constant);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@
import java.lang.reflect.Array;
import java.util.List;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* Tests for {@link ConstantReflectionProvider}. It assumes an implementation of the interface that
Expand Down Expand Up @@ -92,6 +98,31 @@ static class BoxedConstants {
static final Boolean BOOL_CONST = true;
}

@Test
public void identityHashCodeTest() {
try {
constantReflection.identityHashCode(null);
fail("Expected NullPointerException");
} catch (NullPointerException e) {
// Expected
}
assertEquals(Integer.valueOf(0), constantReflection.identityHashCode(JavaConstant.NULL_POINTER));
for (ConstantValue cv : constants()) {
if (cv.value.getJavaKind() != JavaKind.Object) {
try {
constantReflection.identityHashCode(cv.value);
fail("Expected IllegalArgumentException for " + cv);
} catch (IllegalArgumentException e) {
// Expected
}
} else if (cv.boxed != cv.value) {
int expect = System.identityHashCode(cv.boxed);
int actual = constantReflection.identityHashCode(cv.value);
assertEquals(cv.toString(), expect, actual);
}
}
}

@Test
public void boxTest() {
for (ConstantValue cv : constants()) {
Expand Down
Loading