-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable partial missing metadata exceptions
- Loading branch information
Showing
11 changed files
with
389 additions
and
113 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/MissingRegistrationSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2023, 2023, 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; | ||
|
||
import org.graalvm.compiler.api.replacements.Fold; | ||
import org.graalvm.nativeimage.ImageSingletons; | ||
import org.graalvm.nativeimage.Platform; | ||
import org.graalvm.nativeimage.Platforms; | ||
|
||
import com.oracle.svm.core.option.OptionClassFilter; | ||
|
||
public class MissingRegistrationSupport { | ||
|
||
private final OptionClassFilter classFilter; | ||
|
||
@Platforms(Platform.HOSTED_ONLY.class) | ||
public MissingRegistrationSupport(OptionClassFilter classFilter) { | ||
this.classFilter = classFilter; | ||
} | ||
|
||
@Fold | ||
public static MissingRegistrationSupport singleton() { | ||
return ImageSingletons.lookup(MissingRegistrationSupport.class); | ||
} | ||
|
||
public boolean reportMissingRegistrationErrors(StackTraceElement responsibleClass) { | ||
return classFilter.isIncluded(responsibleClass.getModuleName(), getPackageName(responsibleClass.getClassName()), responsibleClass.getClassName()) != null; | ||
} | ||
|
||
private static String getPackageName(String className) { | ||
int lastDot = className.lastIndexOf('.'); | ||
return (lastDot != -1) ? className.substring(0, lastDot) : ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...evm/src/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/MissingRegistrationHelp.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Throw Native Image-specific errors when trying to access an element that has not been registered. | ||
This can happen on reflection and serialization queries, and resource access. | ||
If used without args, the errors will be thrown when calling the corresponding query from any class in scope of the option. | ||
|
||
Using -H:ThrowMissingRegistrationErrors without arguments is only allowed on command line or when embedded in a | ||
native-image.properties file of some zip/jar file on the module-path (but not on class-path). | ||
|
||
In the module path case, the option will cause all classes of the module to trigger missing registration errors. | ||
If used without arguments on command line all classes will trigger missing registration errors. | ||
|
||
Using -H:ThrowMissingRegistrationErrors with arguments is allowed in every scope: | ||
|
||
1. On command line | ||
2. Embedded in a native-image.properties file of some zip/jar file on module-path | ||
3. Embedded in a native-image.properties file of some zip/jar file on class-path | ||
|
||
If the option is embedded in native-image.properties file in some zip/jar file all class-names | ||
and package-names passed to the option have to be found in the zip/jar files the option is embedded | ||
in. Using -H:ThrowMissingRegistrationErrors with arguments on command line does not have that restriction. |
11 changes: 11 additions & 0 deletions
11
...rc/com.oracle.svm.core/src/com/oracle/svm/core/doc-files/MissingRegistrationPathsHelp.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Trigger missing registration errors from all types in the given class or module-path entries. | ||
|
||
This option requires arguments that are of the same type as the | ||
arguments passed via -p (--module-path) or -cp (--class-path): | ||
|
||
-H:ThrowMissingRegistrationErrorsPaths <class search path of directories and zip/jar files> | ||
|
||
The given entries are searched and all classes inside are registered as -H:ThrowMissingRegistrationErrorsPaths classes. | ||
|
||
This option is only allowed to be used on command line. I.e. the option will be rejected if it is provided | ||
by Args of a native-image.properties file embedded in a zip/jar file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/option/OptionClassFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2023, 2023, 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.option; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class OptionClassFilter { | ||
private final Set<OptionOrigin> reasonCommandLine = Collections.singleton(OptionOrigin.commandLineOptionOriginSingleton); | ||
|
||
private final Map<String, Set<OptionOrigin>> requireCompletePackageOrClass; | ||
private final Set<Module> requireCompleteModules; | ||
private boolean requireCompleteAll; | ||
|
||
public OptionClassFilter(Map<String, Set<OptionOrigin>> requireCompletePackageOrClass, Set<Module> requireCompleteModules, boolean requireCompleteAll) { | ||
this.requireCompletePackageOrClass = requireCompletePackageOrClass; | ||
this.requireCompleteModules = requireCompleteModules; | ||
this.requireCompleteAll = requireCompleteAll; | ||
} | ||
|
||
public Object isIncluded(Class<?> clazz) { | ||
Module module = clazz.getModule(); | ||
return isIncluded(module.isNamed() ? module.getName() : null, clazz.getPackageName(), clazz.getName()); | ||
} | ||
|
||
public Object isIncluded(String moduleName, String packageName, String className) { | ||
if (requireCompleteAll) { | ||
return reasonCommandLine; | ||
} | ||
|
||
if (moduleName != null) { | ||
for (Module module : requireCompleteModules) { | ||
if (module.getName().equals(moduleName)) { | ||
return module.toString(); | ||
} | ||
} | ||
} | ||
|
||
Set<OptionOrigin> origins = requireCompletePackageOrClass.get(className); | ||
if (origins != null) { | ||
return origins; | ||
} | ||
return requireCompletePackageOrClass.get(packageName); | ||
} | ||
|
||
public void addPackageOrClass(String packageOrClass, Set<OptionOrigin> reason) { | ||
requireCompletePackageOrClass.put(packageOrClass, reason); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.