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 @@ -26,9 +26,9 @@
package oracle.code.onnx;

import java.lang.foreign.ValueLayout;
import jdk.incubator.code.CodeReflection;
import java.util.List;
import java.util.Optional;
import jdk.incubator.code.Quotable;
import oracle.code.onnx.ir.OnnxOps;

class ExplicitOnnxOperators {
Expand Down Expand Up @@ -80,7 +80,8 @@ public static Tensor<Integer> Constant(
// @@@ Constants for value - TENSOR and sparse_value - SPARSE_TENSOR


public interface IfBody<T> extends Quotable {
@CodeReflection
public interface IfBody<T> {
T invoke();
}

Expand All @@ -89,7 +90,9 @@ public static <T> T If(Tensor<Boolean> cond, IfBody<T> thenBody, IfBody<T> elseB
}

public record LoopResult<T>(Tensor<Boolean> cond, T output) {}
public interface LoopBody<T> extends Quotable {

@CodeReflection
public interface LoopBody<T> {
LoopResult<T> invoke(Tensor<Long> i, Tensor<Boolean> cond, T input);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ private void checkStatus(MemorySegment status) {
}

@FunctionalInterface
public interface OnnxFunction<T> extends Supplier<T>, Quotable {
@CodeReflection
public interface OnnxFunction<T> extends Supplier<T> {
}

record SessionWithReturnType(Session session, TypeElement returnType) {
Expand Down
5 changes: 3 additions & 2 deletions hat/core/src/main/java/hat/Accelerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;

import jdk.incubator.code.CodeReflection;
import jdk.incubator.code.Op;
import jdk.incubator.code.Quotable;
import jdk.incubator.code.Quoted;
import jdk.incubator.code.dialect.java.JavaOp;

Expand Down Expand Up @@ -164,7 +164,8 @@ public void postAccess(Buffer b) {
* );
* </pre>
*/
public interface QuotableComputeContextConsumer extends Quotable, Consumer<ComputeContext> {
@CodeReflection
public interface QuotableComputeContextConsumer extends Consumer<ComputeContext> {
}
// convenience
public Config config(){
Expand Down
5 changes: 3 additions & 2 deletions hat/core/src/main/java/hat/ComputeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import hat.ifacemapper.BoundSchema;
import hat.ifacemapper.SegmentMapper;
import hat.optools.OpTk;
import jdk.incubator.code.CodeReflection;
import jdk.incubator.code.Op;
import jdk.incubator.code.Quotable;
import jdk.incubator.code.Quoted;
import jdk.incubator.code.dialect.java.JavaOp;
import jdk.incubator.code.dialect.java.MethodRef;
Expand Down Expand Up @@ -173,6 +173,7 @@ public <T extends Buffer> T allocate(SegmentMapper<T> segmentMapper, BoundSchema
return accelerator.allocate(segmentMapper, boundSchema);
}

public interface QuotableKernelContextConsumer extends Quotable, Consumer<KernelContext> { }
@CodeReflection
public interface QuotableKernelContextConsumer extends Consumer<KernelContext> { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
package experiments;


import jdk.incubator.code.CodeReflection;
import jdk.incubator.code.Op;
import jdk.incubator.code.Quotable;
import jdk.incubator.code.Quoted;
import jdk.incubator.code.Value;
import jdk.incubator.code.dialect.core.CoreOp;
Expand All @@ -46,13 +46,16 @@
public class TestQuoted {
public static class TestLambdaMethodRef {

interface QuotableIntUnaryOperator extends IntUnaryOperator, Quotable {
@CodeReflection
interface QuotableIntUnaryOperator extends IntUnaryOperator {
}

interface QuotableFunction<T, R> extends Function<T, R>, Quotable {
@CodeReflection
interface QuotableFunction<T, R> extends Function<T, R> {
}

interface QuotableBiFunction<T, U, R> extends BiFunction<T, U, R>, Quotable {
@CodeReflection
interface QuotableBiFunction<T, U, R> extends BiFunction<T, U, R> {
}

// @Test
Expand Down Expand Up @@ -132,7 +135,7 @@ public void test() {
isMethodRef(f6);
}

static void isMethodRef(Quotable q) {
static void isMethodRef(Object q) {
Quoted quoted = Op.ofQuotable(q).orElseThrow();;
JavaOp.LambdaOp op = (JavaOp.LambdaOp) quoted.op();
System.out.println(isMethodRef(op));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
*/
package experiments.spirv;

import jdk.incubator.code.CodeReflection;
import jdk.incubator.code.Op;
import jdk.incubator.code.Quotable;
import jdk.incubator.code.Quoted;
import java.util.function.Consumer;

public class Bad {
public static class AcceleratorProxy {
public interface QuotableComputeConsumer extends Quotable, Consumer<ComputeClosureProxy> {
@CodeReflection
public interface QuotableComputeConsumer extends Consumer<ComputeClosureProxy> {
}

public static class ComputeClosureProxy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ private void generateQuotedFieldInitializer(CodeBuilder cob) {

static class CodeReflectionSupport {
static final Class<?> QUOTED_CLASS;
static final Class<?> QUOTABLE_CLASS;
static final MethodHandle QUOTED_EXTRACT_OP_MH;
static final Class<?> FUNC_OP_CLASS;

Expand All @@ -507,7 +506,6 @@ static class CodeReflectionSupport {
ModuleLayer layer = codeLayer();
ClassLoader cl = layer.findLoader("jdk.incubator.code");
QUOTED_CLASS = cl.loadClass("jdk.incubator.code.Quoted");
QUOTABLE_CLASS = cl.loadClass("jdk.incubator.code.Quotable");
FUNC_OP_CLASS = cl.loadClass("jdk.incubator.code.dialect.core.CoreOp$FuncOp");
QUOTED_EXTRACT_OP_MH = Lookup.IMPL_LOOKUP.findStatic(QUOTED_CLASS, "extractOp",
MethodType.methodType(QUOTED_CLASS, FUNC_OP_CLASS, Object[].class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private LambdaMetafactory() {}
public static final int FLAG_BRIDGES = 1 << 2;

/** Flag for {@link #altMetafactory} indicating the lambda object
* must be a {@code Quotable} object, inspectable using code reflection. */
* must be inspectable using code reflection. */
public static final int FLAG_QUOTABLE = 1 << 3;

private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
Expand Down Expand Up @@ -445,9 +445,6 @@ public static CallSite metafactory(MethodHandles.Lookup caller,
* {@code caller} class must have an appropriate {@code $deserializeLambda$}
* method, as described in {@link SerializedLambda}.
*
* <p>When FLAG_QUOTABLE is set in {@code flags}, the function objects
* will implement {@code Quotable}.
*
* <p>When the target of the {@code CallSite} returned from this method is
* invoked, the resulting function objects are instances of a class with
* the following properties:
Expand Down Expand Up @@ -537,8 +534,6 @@ public static CallSite altMetafactory(MethodHandles.Lookup caller,
}
if ((flags & FLAG_QUOTABLE) != 0) {
quotableOpGetter = extractArg(args, argIndex++, MethodHandle.class);
altInterfaces = Arrays.copyOf(altInterfaces, altInterfaces.length + 1);
altInterfaces[altInterfaces.length-1] = InnerClassLambdaMetafactory.CodeReflectionSupport.QUOTABLE_CLASS;
}
if (argIndex < args.length) {
throw new IllegalArgumentException("too many arguments");
Expand Down
15 changes: 0 additions & 15 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -5412,19 +5412,4 @@ public void newRound() {
membersCache._map.clear();
closureCache.clear();
}

// code reflection

// The predicates below do not use a predefined symbol in Symtab.
// This is deliberate, as we cannot initialize symbols in modules
// other than java.base at startup.

public boolean isQuotable(Type type) {
Symbol s = type.tsym;
return s != null &&
s.kind == TYP &&
s.name.equals(names.quotable) &&
s.packge().fullname.equals(names.jdk_incubator_code) &&
s.packge().modle.name.equals(names.jdk_incubator_code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ private Env<AttrContext> attribToTree(JCTree root, Env<AttrContext> env, JCTree
public <R> R runWithAttributedMethod(Env<AttrContext> env, JCMethodDecl tree, Function<JCBlock, R> attributedAction) {
JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile);
try {
annotate.queueScanTreeAndTypeAnnotate(tree.body, env, tree.sym);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some adjustments were needed to make sure the type annotations were initialized correctly up to this point. I verified with our annotation processor in crExamples and everything still works.

annotate.flush();
JCBlock dupTree = (JCBlock)deferredAttr.attribSpeculative(tree.body, env, statInfo,
null, DeferredAttr.AttributionMode.ATTRIB_TO_TREE,
argumentAttr.withLocalCacheContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public interface CodeReflectionTransformer {
/**
* Analyze the code in the provided class, generating code models for the following program elements:
* <li>methods annotated with {@code CodeReflection};
* <li>lambdas or method references whose target type is {@code Quoted}; and
* <li>lambdas or method references whose target is an intersection type that contains {@code Quotable}.
* <li>lambdas or method references whose target type is a functional interface annotated with {@code CodeReflection}; and
* <li>lambdas or method references whose target is a cast that contains the {@code CodeReflection} annotation.
* @param context the compiler context
* @param tree the tree to analyze
* @param make the tree maker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,6 @@ private JCExpression makeMetafactoryIndyCall(JCFunctionalExpression tree,
for (Type t : targets) {
t = types.erasure(t);
if (t.tsym != syms.serializableType.tsym &&
!types.isQuotable(t) &&
t.tsym != tree.type.tsym &&
t.tsym != syms.objectType.tsym) {
markers.append(t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ public static Names instance(Context context) {

// code reflection
public final Name jdk_incubator_code;
public final Name quotable;

// special annotation names
public final Name requiresIdentityInternal;
Expand Down Expand Up @@ -422,7 +421,6 @@ record = fromString("record");

// code reflection
jdk_incubator_code = fromString("jdk.incubator.code");
quotable = fromString("Quotable");

// special annotations:
requiresIdentityInternal = fromString("jdk.internal.RequiresIdentity+Annotation");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* Enables code reflection for a method annotated with this annotation.
*/
@Target({ElementType.METHOD})
@Target({ElementType.METHOD, ElementType.TYPE_USE, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface CodeReflection {
}
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public final String toText() {
* returns an empty optional.
* @since 99
*/
public static Optional<Quoted> ofQuotable(Quotable q) {
public static Optional<Quoted> ofQuotable(Object q) {
Object oq = q;
if (Proxy.isProxyClass(oq.getClass())) {
// @@@ The interpreter implements interpretation of
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
*/
public class CodeReflectionSymbols {
public final Type quotedType;
public final Type quotableType;
public final Type codeReflectionType;
public final Type opType;
public final Type funcOpType;
Expand All @@ -57,7 +56,6 @@ public class CodeReflectionSymbols {
ModuleSymbol jdk_incubator_code = syms.enterModule(names.jdk_incubator_code);
codeReflectionType = syms.enterClass(jdk_incubator_code, "jdk.incubator.code.CodeReflection");
quotedType = syms.enterClass(jdk_incubator_code, "jdk.incubator.code.Quoted");
quotableType = syms.enterClass(jdk_incubator_code, "jdk.incubator.code.Quotable");
opType = syms.enterClass(jdk_incubator_code, "jdk.incubator.code.Op");
funcOpType = syms.enterClass(jdk_incubator_code, "jdk.incubator.code.dialect.core.CoreOp$FuncOp");
quotedExtractOp = new MethodSymbol(PUBLIC | STATIC | VARARGS,
Expand All @@ -66,6 +64,5 @@ public class CodeReflectionSymbols {
List.nil(), syms.methodClass),
quotedType.tsym);
syms.synthesizeEmptyInterfaceIfMissing(quotedType);
syms.synthesizeEmptyInterfaceIfMissing(quotableType);
}
}
Loading