Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-57998] Remove ComputedValueField and ReadableJavaField. #9634

Closed
wants to merge 1 commit into from
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 @@ -24,11 +24,12 @@
*/
package com.oracle.svm.core.foreign;

import org.graalvm.nativeimage.hosted.FieldValueTransformer;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.config.ConfigurationValues;
import com.oracle.svm.core.fieldvaluetransformer.FieldValueTransformerWithAvailability;
import com.oracle.svm.core.util.VMError;

import jdk.internal.foreign.Utils;
Expand All @@ -41,12 +42,7 @@ final class Target_jdk_internal_foreign_Utils_BaseAndScale {
int base;
}

final class BaseFieldRecomputer implements FieldValueTransformerWithAvailability {

@Override
public ValueAvailability valueAvailability() {
return ValueAvailability.BeforeAnalysis;
}
final class BaseFieldRecomputer implements FieldValueTransformer {

@Override
public Object transform(Object receiver, Object originalValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@

import org.graalvm.nativeimage.hosted.FieldValueTransformer;

import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
import com.oracle.svm.core.config.ConfigurationValues;

import jdk.vm.ci.meta.JavaKind;

public final class ArrayBaseOffsetFieldValueTransformer extends BoxingTransformer implements FieldValueTransformer {
private final Class<?> targetClass;

public ArrayBaseOffsetFieldValueTransformer(Class<?> targetClass, JavaKind returnKind) {
super(returnKind);
this.targetClass = targetClass;
}
/**
* Implements the field value transformation semantics of {@link Kind#ArrayBaseOffset}.
*/
public record ArrayBaseOffsetFieldValueTransformer(Class<?> targetClass, JavaKind returnKind) implements FieldValueTransformer {

@Override
public Object transform(Object receiver, Object originalValue) {
return box(ConfigurationValues.getObjectLayout().getArrayBaseOffset(JavaKind.fromJavaClass(targetClass.getComponentType())));
return FieldOffsetFieldValueTransformer.box(returnKind, ConfigurationValues.getObjectLayout().getArrayBaseOffset(JavaKind.fromJavaClass(targetClass.getComponentType())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@

import org.graalvm.nativeimage.hosted.FieldValueTransformer;

import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
import com.oracle.svm.core.config.ConfigurationValues;

import jdk.vm.ci.meta.JavaKind;

public final class ArrayIndexScaleFieldValueTransformer extends BoxingTransformer implements FieldValueTransformer {
private final Class<?> targetClass;

public ArrayIndexScaleFieldValueTransformer(Class<?> targetClass, JavaKind returnKind) {
super(returnKind);
this.targetClass = targetClass;
}
/**
* Implements the field value transformation semantics of {@link Kind#ArrayIndexScale}.
*/
public record ArrayIndexScaleFieldValueTransformer(Class<?> targetClass, JavaKind returnKind) implements FieldValueTransformer {

@Override
public Object transform(Object receiver, Object originalValue) {
return box(ConfigurationValues.getObjectLayout().getArrayIndexScale(JavaKind.fromJavaClass(targetClass.getComponentType())));
return FieldOffsetFieldValueTransformer.box(returnKind, ConfigurationValues.getObjectLayout().getArrayIndexScale(JavaKind.fromJavaClass(targetClass.getComponentType())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@

import org.graalvm.nativeimage.hosted.FieldValueTransformer;

import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
import com.oracle.svm.core.config.ConfigurationValues;

import jdk.vm.ci.meta.JavaKind;

public final class ArrayIndexShiftFieldValueTransformer extends BoxingTransformer implements FieldValueTransformer {
private final Class<?> targetClass;

public ArrayIndexShiftFieldValueTransformer(Class<?> targetClass, JavaKind returnKind) {
super(returnKind);
this.targetClass = targetClass;
}
/**
* Implements the field value transformation semantics of {@link Kind#ArrayIndexShift}.
*/
public record ArrayIndexShiftFieldValueTransformer(Class<?> targetClass, JavaKind returnKind) implements FieldValueTransformer {

@Override
public Object transform(Object receiver, Object originalValue) {
return box(ConfigurationValues.getObjectLayout().getArrayIndexShift(JavaKind.fromJavaClass(targetClass.getComponentType())));
return FieldOffsetFieldValueTransformer.box(returnKind, ConfigurationValues.getObjectLayout().getArrayIndexShift(JavaKind.fromJavaClass(targetClass.getComponentType())));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2024, 2024, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.fieldvaluetransformer;

import org.graalvm.nativeimage.hosted.FieldValueTransformer;

import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
import com.oracle.svm.core.util.VMError;

import jdk.vm.ci.meta.ResolvedJavaField;

/**
* Sets the field to the provided constant value.
*
* When that value is the {@link #defaultValueForField default value for the field}, this
* transformer implements the field value transformation semantics of {@link Kind#Reset}.
*/
public record ConstantValueFieldValueTransformer(Object value) implements FieldValueTransformer {

public static FieldValueTransformer defaultValueForField(ResolvedJavaField field) {
return new ConstantValueFieldValueTransformer(switch (field.getType().getJavaKind()) {
case Byte -> Byte.valueOf((byte) 0);
case Boolean -> Boolean.valueOf(false);
case Short -> Short.valueOf((short) 0);
case Char -> Character.valueOf((char) 0);
case Int -> Integer.valueOf(0);
case Long -> Long.valueOf(0);
case Float -> Float.valueOf(0);
case Double -> Double.valueOf(0);
case Object -> null;
default -> throw VMError.shouldNotReachHere(String.valueOf(field));
});
}

@Override
public Object transform(Object receiver, Object originalValue) {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import java.lang.reflect.Field;

import com.oracle.svm.core.BuildPhaseProvider;
import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
import com.oracle.svm.core.graal.nodes.FieldOffsetNode;
import com.oracle.svm.core.reflect.target.ReflectionSubstitutionSupport;
import com.oracle.svm.core.util.VMError;
Expand All @@ -35,17 +37,14 @@
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;

public final class FieldOffsetFieldValueTransformer extends BoxingTransformer implements FieldValueTransformerWithAvailability {
private final Field targetField;

public FieldOffsetFieldValueTransformer(Field targetField, JavaKind returnKind) {
super(returnKind);
this.targetField = targetField;
}
/**
* Implements the field value transformation semantics of {@link Kind#FieldOffset}.
*/
public record FieldOffsetFieldValueTransformer(Field targetField, JavaKind returnKind) implements FieldValueTransformerWithAvailability {

@Override
public ValueAvailability valueAvailability() {
return ValueAvailability.AfterAnalysis;
public boolean isAvailable() {
return BuildPhaseProvider.isHostedUniverseBuilt();
}

@Override
Expand All @@ -54,7 +53,18 @@ public Object transform(Object receiver, Object originalValue) {
if (offset <= 0) {
throw VMError.shouldNotReachHere("Field is not marked as unsafe accessed: " + targetField);
}
return box(offset);
return box(returnKind, offset);
}

static Object box(JavaKind returnKind, int value) {
switch (returnKind) {
case Int:
return Integer.valueOf(value);
case Long:
return Long.valueOf(value);
default:
throw VMError.shouldNotReachHere("Unexpected kind: " + returnKind);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,9 @@
public interface FieldValueTransformerWithAvailability extends FieldValueTransformer {

/**
* Controls when the transformed value is available at image build time.
* Returns true when the value for this custom computation is available.
*/
enum ValueAvailability {
/**
* The value is available without time constraints, i.e., it is independent of static
* analysis or compilation.
*/
BeforeAnalysis,

/**
* The value depends on data computed by the static analysis and is therefore not yet
* available to the static analysis. The value still might be constant folded during
* compilation.
*/
AfterAnalysis,

/**
* Value depends on data computed during compilation and is therefore available only when
* writing out the image heap into the native image. Such a value is never available for
* constant folding.
*/
AfterCompilation
}

/**
* Returns information about when the value for this custom computation is available.
*/
ValueAvailability valueAvailability();
boolean isAvailable();

/**
* Optionally provide a Graal IR node to intrinsify the field access before the static analysis.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024, 2024, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.fieldvaluetransformer;

import org.graalvm.nativeimage.hosted.FieldValueTransformer;

import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
import com.oracle.svm.util.ReflectionUtil;

/**
* Implements the field value transformation semantics of {@link Kind#NewInstance} and
* {@link Kind#NewInstanceWhenNotNull}.
*/
public record NewInstanceOfFixedClassFieldValueTransformer(Class<?> clazz, boolean onlyIfOriginalNotNull) implements FieldValueTransformer {

@Override
public Object transform(Object receiver, Object originalValue) {
if (onlyIfOriginalNotNull && originalValue == null) {
return null;
}
return ReflectionUtil.newInstance(clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@

import java.lang.reflect.Field;

import com.oracle.svm.core.BuildPhaseProvider;
import com.oracle.svm.core.StaticFieldsSupport;
import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;

import jdk.graal.compiler.nodes.ValueNode;
import jdk.graal.compiler.nodes.spi.CoreProviders;
import jdk.vm.ci.meta.JavaConstant;

public final class StaticFieldBaseFieldValueTransformer implements FieldValueTransformerWithAvailability {
private final Field targetField;

public StaticFieldBaseFieldValueTransformer(Field targetField) {
this.targetField = targetField;
}
/**
* Implements the field value transformation semantics of {@link Kind#StaticFieldBase}.
*/
public record StaticFieldBaseFieldValueTransformer(Field targetField) implements FieldValueTransformerWithAvailability {

@Override
public ValueAvailability valueAvailability() {
return ValueAvailability.AfterAnalysis;
public boolean isAvailable() {
return BuildPhaseProvider.isHostedUniverseBuilt();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
import org.graalvm.nativeimage.impl.InternalPlatform;

import com.oracle.svm.core.BuildPhaseProvider;
import com.oracle.svm.core.NeverInline;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.SubstrateUtil;
Expand Down Expand Up @@ -579,13 +580,13 @@ public Object transform(Object receiver, Object originalValue) {
return map;
}

/*
* We want to wait to constant fold this value until all possible HotSpot initialization code
* has run.
*/
@Override
public ValueAvailability valueAvailability() {
/*
* We want to wait to constant fold this value until all possible HotSpot initialization
* code has run.
*/
return ValueAvailability.AfterAnalysis;
public boolean isAvailable() {
return BuildPhaseProvider.isHostedUniverseBuilt();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.BuildPhaseProvider;
import com.oracle.svm.core.StaticFieldsSupport;
import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
Expand Down Expand Up @@ -63,8 +64,8 @@ abstract class VarHandleFieldOffsetComputer implements FieldValueTransformerWith
}

@Override
public ValueAvailability valueAvailability() {
return ValueAvailability.AfterAnalysis;
public boolean isAvailable() {
return BuildPhaseProvider.isHostedUniverseBuilt();
}

@Override
Expand Down Expand Up @@ -110,8 +111,8 @@ class VarHandleFieldOffsetAsLongComputer extends VarHandleFieldOffsetComputer {

class VarHandleStaticBaseComputer implements FieldValueTransformerWithAvailability {
@Override
public ValueAvailability valueAvailability() {
return ValueAvailability.AfterAnalysis;
public boolean isAvailable() {
return BuildPhaseProvider.isHostedUniverseBuilt();
}

@Override
Expand Down
Loading