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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, 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 @@ -105,6 +105,11 @@ public static boolean is32bit(long x) {
return -0x80000000L <= x && x < 0x80000000L;
}

public static byte safeToUByte(int v) {
assert isUByte(v);
return (byte) v;
}

public static byte safeToByte(int v) {
assert isByte(v);
return (byte) v;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ private static boolean getDeclaredClasses(JNIEnvironment jni, Breakpoint bp, Int
return handleGetClasses(jni, bp, state);
}

private static boolean getPermittedSubclasses(JNIEnvironment jni, Breakpoint bp, InterceptedState state) {
return handleGetClasses(jni, bp, state);
}

private static boolean handleGetClasses(JNIEnvironment jni, Breakpoint bp, InterceptedState state) {
JNIObjectHandle callerClass = state.getDirectCallerClass();
JNIObjectHandle self = getObjectArgument(0);
Expand Down Expand Up @@ -1520,7 +1524,9 @@ private interface BreakpointHandler {
BreakpointInterceptor::constantBootstrapGetStaticFinal),
optionalBrk("java/lang/invoke/MethodType", "fromMethodDescriptorString",
"(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/lang/invoke/MethodType;",
BreakpointInterceptor::methodTypeFromDescriptor)
BreakpointInterceptor::methodTypeFromDescriptor),
optionalBrk("java/lang/Class", "getPermittedSubclasses", "()[Ljava/lang/Class;",
BreakpointInterceptor::getPermittedSubclasses)
};

private static final BreakpointSpecification CLASSLOADER_LOAD_CLASS_BREAKPOINT_SPECIFICATION = optionalBrk("java/lang/ClassLoader", "loadClass",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, 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 @@ -74,6 +74,7 @@ static ConfigurationType copyAndSubtract(ConfigurationType type, ConfigurationTy
private Map<ConfigurationMethod, ConfigurationMemberInfo> methods;

private boolean allDeclaredClasses;
private boolean allPermittedSubclasses;
private boolean allPublicClasses;
private boolean allDeclaredFields;
private boolean allPublicFields;
Expand Down Expand Up @@ -211,6 +212,7 @@ private void removeMethods(ConfigurationType other) {
private void setFlagsFromOther(ConfigurationType other, BiPredicate<Boolean, Boolean> flagPredicate,
BiFunction<ConfigurationMemberAccessibility, ConfigurationMemberAccessibility, ConfigurationMemberAccessibility> accessCombiner) {
allDeclaredClasses = flagPredicate.test(allDeclaredClasses, other.allDeclaredClasses);
allPermittedSubclasses = flagPredicate.test(allPermittedSubclasses, other.allPermittedSubclasses);
allPublicClasses = flagPredicate.test(allPublicClasses, other.allPublicClasses);
allDeclaredFields = flagPredicate.test(allDeclaredFields, other.allDeclaredFields);
allPublicFields = flagPredicate.test(allPublicFields, other.allPublicFields);
Expand All @@ -225,7 +227,7 @@ private boolean isEmpty() {
}

private boolean allFlagsFalse() {
return !(allDeclaredClasses || allPublicClasses || allDeclaredFields || allPublicFields ||
return !(allDeclaredClasses || allPermittedSubclasses || allPublicClasses || allDeclaredFields || allPublicFields ||
allDeclaredMethodsAccess != ConfigurationMemberAccessibility.NONE || allPublicMethodsAccess != ConfigurationMemberAccessibility.NONE ||
allDeclaredConstructorsAccess != ConfigurationMemberAccessibility.NONE || allPublicConstructorsAccess != ConfigurationMemberAccessibility.NONE);
}
Expand Down Expand Up @@ -310,6 +312,10 @@ public synchronized void setAllDeclaredClasses() {
allDeclaredClasses = true;
}

public synchronized void setAllPermittedSubclasses() {
allPermittedSubclasses = true;
}

public synchronized void setAllPublicClasses() {
allPublicClasses = true;
}
Expand Down Expand Up @@ -365,6 +371,7 @@ public synchronized void printJson(JsonWriter writer) throws IOException {
optionallyPrintJsonBoolean(writer, allDeclaredConstructorsAccess == ConfigurationMemberAccessibility.ACCESSED, "allDeclaredConstructors");
optionallyPrintJsonBoolean(writer, allPublicConstructorsAccess == ConfigurationMemberAccessibility.ACCESSED, "allPublicConstructors");
optionallyPrintJsonBoolean(writer, allDeclaredClasses, "allDeclaredClasses");
optionallyPrintJsonBoolean(writer, allPermittedSubclasses, "allPermittedSubclasses");
optionallyPrintJsonBoolean(writer, allPublicClasses, "allPublicClasses");
optionallyPrintJsonBoolean(writer, allDeclaredMethodsAccess == ConfigurationMemberAccessibility.QUERIED, "queryAllDeclaredMethods");
optionallyPrintJsonBoolean(writer, allPublicMethodsAccess == ConfigurationMemberAccessibility.QUERIED, "queryAllPublicMethods");
Expand Down Expand Up @@ -393,7 +400,7 @@ public synchronized void printJson(JsonWriter writer) throws IOException {
}
}

writer.append('}').unindent().newline();
writer.unindent().newline().append('}');
}

private Set<ConfigurationMethod> getMethodsByAccessibility(ConfigurationMemberAccessibility accessibility) {
Expand Down Expand Up @@ -463,6 +470,10 @@ public static boolean haveAllDeclaredClasses(ConfigurationType type) {
return type.allDeclaredClasses;
}

public static boolean haveAllPermittedSubclasses(ConfigurationType type) {
return type.allPermittedSubclasses;
}

public static boolean haveAllPublicClasses(ConfigurationType type) {
return type.allPublicClasses;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, 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 @@ -98,6 +98,11 @@ public void registerDeclaredClasses(ConfigurationType type) {
type.setAllDeclaredClasses();
}

@Override
public void registerPermittedSubclasses(ConfigurationType type) {
type.setAllPermittedSubclasses();
}

@Override
public void registerPublicFields(ConfigurationType type) {
type.setAllPublicFields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public void processEntry(Map<String, ?> entry) {
configuration.getOrCreateType(condition, clazz).setAllDeclaredClasses();
break;
}
case "getPermittedSubclasses": {
configuration.getOrCreateType(condition, clazz).setAllPermittedSubclasses();
break;
}
case "getClasses": {
configuration.getOrCreateType(condition, clazz).setAllPublicClasses();
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2021, 2021, 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.jdk17;

// Checkstyle: allow reflection

import com.oracle.svm.core.annotate.AutomaticFeature;
import com.oracle.svm.core.jdk.SealedClassSupport;
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.hosted.Feature;

final class SealedClassSupportJDK17OrLater extends SealedClassSupport {

@Override
public boolean isSealed(Class<?> clazz) {
return clazz.isSealed();
}

@Override
public Class<?>[] getPermittedSubclasses(Class<?> clazz) {
return clazz.getPermittedSubclasses();
}
}

@AutomaticFeature
final class SealedClassFeatureJDK17OrLater implements Feature {

@Override
public boolean isInConfiguration(IsInConfigurationAccess access) {
return JavaVersionUtil.JAVA_SPEC >= 17;
}

@Override
public void afterRegistration(AfterRegistrationAccess access) {
ImageSingletons.add(SealedClassSupport.class, new SealedClassSupportJDK17OrLater());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, 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 @@ -52,7 +52,7 @@ public final class ReflectionConfigurationParser<T> extends ConfigurationParser
private final boolean allowIncompleteClasspath;
private static final List<String> OPTIONAL_REFLECT_CONFIG_OBJECT_ATTRS = Arrays.asList("allDeclaredConstructors", "allPublicConstructors",
"allDeclaredMethods", "allPublicMethods", "allDeclaredFields", "allPublicFields",
"allDeclaredClasses", "allPublicClasses", "methods", "queriedMethods", "fields", CONDITIONAL_KEY,
"allDeclaredClasses", "allPermittedSubclasses", "allPublicClasses", "methods", "queriedMethods", "fields", CONDITIONAL_KEY,
"queryAllDeclaredConstructors", "queryAllPublicConstructors", "queryAllDeclaredMethods", "queryAllPublicMethods");

public ReflectionConfigurationParser(ReflectionConfigurationParserDelegate<T> delegate) {
Expand Down Expand Up @@ -139,6 +139,11 @@ private void parseClass(Map<String, Object> data) {
delegate.registerDeclaredClasses(clazz);
}
break;
case "allPermittedSubclasses":
if (asBoolean(value, "allPermittedSubclasses")) {
delegate.registerPermittedSubclasses(clazz);
}
break;
case "allPublicClasses":
if (asBoolean(value, "allPublicClasses")) {
delegate.registerPublicClasses(clazz);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, 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 @@ -42,6 +42,8 @@ public interface ReflectionConfigurationParserDelegate<T> {

void registerDeclaredClasses(T type);

void registerPermittedSubclasses(T type);

void registerPublicFields(T type);

void registerDeclaredFields(T type);
Expand Down
Loading