8283416: Update java.lang.invoke.MethodHandle to use sealed classes

Reviewed-by: sundar, mchung
This commit is contained in:
Joe Darcy 2022-03-24 19:08:23 +00:00
parent 90750decb4
commit f16244509d
6 changed files with 23 additions and 17 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2022, 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
@ -49,7 +49,7 @@ import static java.lang.invoke.MethodHandleStatics.uncaughtException;
* All bound arguments are encapsulated in dedicated species.
*/
/*non-public*/
abstract class BoundMethodHandle extends MethodHandle {
abstract non-sealed class BoundMethodHandle extends MethodHandle {
/*non-public*/
BoundMethodHandle(MethodType type, LambdaForm form) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2022, 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
@ -37,7 +37,11 @@ import static java.lang.invoke.MethodHandleStatics.*;
* @author jrose
*/
/*non-public*/
abstract class DelegatingMethodHandle extends MethodHandle {
abstract sealed class DelegatingMethodHandle extends MethodHandle
permits MethodHandleImpl.AsVarargsCollector,
MethodHandleImpl.WrappedMember,
MethodHandleImpl.IntrinsicMethodHandle,
MethodHandleImpl.CountingWrapper {
protected DelegatingMethodHandle(MethodHandle target) {
this(target.type(), target);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2022, 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
@ -49,7 +49,7 @@ import static java.lang.invoke.MethodTypeForm.*;
* to a class member.
* @author jrose
*/
class DirectMethodHandle extends MethodHandle {
sealed class DirectMethodHandle extends MethodHandle {
final MemberName member;
final boolean crackable;
@ -395,7 +395,7 @@ class DirectMethodHandle extends MethodHandle {
}
/** This subclass represents invokespecial instructions. */
static class Special extends DirectMethodHandle {
static final class Special extends DirectMethodHandle {
private final Class<?> caller;
private Special(MethodType mtype, LambdaForm form, MemberName member, boolean crackable, Class<?> caller) {
super(mtype, form, member, crackable);
@ -425,7 +425,7 @@ class DirectMethodHandle extends MethodHandle {
}
/** This subclass represents invokeinterface instructions. */
static class Interface extends DirectMethodHandle {
static final class Interface extends DirectMethodHandle {
private final Class<?> refc;
private Interface(MethodType mtype, LambdaForm form, MemberName member, boolean crackable, Class<?> refc) {
super(mtype, form, member, crackable);
@ -458,7 +458,7 @@ class DirectMethodHandle extends MethodHandle {
}
/** This subclass handles constructor references. */
static class Constructor extends DirectMethodHandle {
static final class Constructor extends DirectMethodHandle {
final MemberName initMethod;
final Class<?> instanceClass;
@ -493,7 +493,7 @@ class DirectMethodHandle extends MethodHandle {
}
/** This subclass handles non-static field references. */
static class Accessor extends DirectMethodHandle {
static final class Accessor extends DirectMethodHandle {
final Class<?> fieldType;
final int fieldOffset;
private Accessor(MethodType mtype, LambdaForm form, MemberName member,
@ -539,7 +539,7 @@ class DirectMethodHandle extends MethodHandle {
}
/** This subclass handles static field references. */
static class StaticAccessor extends DirectMethodHandle {
static final class StaticAccessor extends DirectMethodHandle {
private final Class<?> fieldType;
private final Object staticBase;
private final long staticOffset;

View File

@ -440,7 +440,9 @@ mh.invokeExact(System.out, "Hello, world.");
* @author John Rose, JSR 292 EG
* @since 1.7
*/
public abstract class MethodHandle implements Constable {
public abstract sealed class MethodHandle implements Constable
permits NativeMethodHandle, DirectMethodHandle,
DelegatingMethodHandle, BoundMethodHandle {
/**
* Internal marker interface which distinguishes (to the Java compiler)

View File

@ -448,7 +448,7 @@ abstract class MethodHandleImpl {
return new AsVarargsCollector(target, arrayType);
}
private static final class AsVarargsCollector extends DelegatingMethodHandle {
static final class AsVarargsCollector extends DelegatingMethodHandle {
private final MethodHandle target;
private final Class<?> arrayType;
private @Stable MethodHandle asCollectorCache;
@ -705,7 +705,7 @@ abstract class MethodHandleImpl {
* Behavior in counting and non-counting states is determined by lambda forms produced by
* countingFormProducer & nonCountingFormProducer respectively.
*/
static class CountingWrapper extends DelegatingMethodHandle {
static final class CountingWrapper extends DelegatingMethodHandle {
private final MethodHandle target;
private int count;
private Function<MethodHandle, LambdaForm> countingFormProducer;
@ -1299,7 +1299,7 @@ abstract class MethodHandleImpl {
}
/** This subclass allows a wrapped method handle to be re-associated with an arbitrary member name. */
private static final class WrappedMember extends DelegatingMethodHandle {
static final class WrappedMember extends DelegatingMethodHandle {
private final MethodHandle target;
private final MemberName member;
private final Class<?> callerClass;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2022, 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
@ -39,7 +39,7 @@ import static java.lang.invoke.MethodHandleStatics.newInternalError;
* or whether a native transition is required) and a <em>fallback</em> method handle, which can be used
* when intrinsification of this method handle is not possible.
*/
/*non-public*/ class NativeMethodHandle extends MethodHandle {
/*non-public*/ final class NativeMethodHandle extends MethodHandle {
final NativeEntryPoint nep;
final MethodHandle fallback;