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
Expand Up @@ -94,6 +94,7 @@ public class NativeImageAutoFeatureStep {
static final String RUNTIME_REFLECTION = RuntimeReflection.class.getName();
static final String JNI_RUNTIME_ACCESS = "com.oracle.svm.core.jni.JNIRuntimeAccess";
static final String BEFORE_ANALYSIS_ACCESS = Feature.BeforeAnalysisAccess.class.getName();
static final String DURING_SETUP_ACCESS = Feature.DuringSetupAccess.class.getName();
static final String DYNAMIC_PROXY_REGISTRY = "com.oracle.svm.core.jdk.proxy.DynamicProxyRegistry";
static final String LEGACY_LOCALIZATION_FEATURE = "com.oracle.svm.core.jdk.LocalizationFeature";
static final String LOCALIZATION_FEATURE = "com.oracle.svm.core.jdk.localization.LocalizationFeature";
Expand Down Expand Up @@ -143,7 +144,27 @@ public void write(String s, byte[] bytes) {
Object.class.getName(), Feature.class.getName());
file.addAnnotation("com.oracle.svm.core.annotate.AutomaticFeature");

//MethodCreator afterReg = file.getMethodCreator("afterRegistration", void.class, "org.graalvm.nativeimage.Feature$AfterRegistrationAccess");
MethodCreator duringSetup = file.getMethodCreator("duringSetup", "V", DURING_SETUP_ACCESS);
// Register Lambda Capturing Types
if (!lambdaCapturingTypeBuildItems.isEmpty()) {
ResultHandle runtimeSerializationSupportSingleton = duringSetup.invokeStaticMethod(IMAGE_SINGLETONS_LOOKUP,
duringSetup.loadClassFromTCCL("org.graalvm.nativeimage.impl.RuntimeSerializationSupport"));
ResultHandle configAlwaysTrue = duringSetup.invokeStaticMethod(CONFIGURATION_ALWAYS_TRUE);

for (LambdaCapturingTypeBuildItem i : lambdaCapturingTypeBuildItems) {
TryBlock tryBlock = duringSetup.tryBlock();

tryBlock.invokeInterfaceMethod(REGISTER_LAMBDA_CAPTURING_CLASS, runtimeSerializationSupportSingleton,
configAlwaysTrue,
tryBlock.load(i.getClassName()));

CatchBlockCreator catchBlock = tryBlock.addCatch(Throwable.class);
catchBlock.invokeVirtualMethod(ofMethod(Throwable.class, "printStackTrace", void.class),
catchBlock.getCaughtException());
}
}
duringSetup.returnValue(null);

MethodCreator beforeAn = file.getMethodCreator("beforeAnalysis", "V", BEFORE_ANALYSIS_ACCESS);
TryBlock overallCatch = beforeAn.tryBlock();
//TODO: at some point we are going to need to break this up, as if it get too big it will hit the method size limit
Expand Down Expand Up @@ -312,25 +333,6 @@ public void write(String s, byte[] bytes) {
overallCatch.load(i.serviceDescriptorFile()));
}

// Register Lambda Capturing Types
if (!lambdaCapturingTypeBuildItems.isEmpty()) {
ResultHandle runtimeSerializationSupportSingleton = overallCatch.invokeStaticMethod(IMAGE_SINGLETONS_LOOKUP,
overallCatch.loadClassFromTCCL("org.graalvm.nativeimage.impl.RuntimeSerializationSupport"));
ResultHandle configAlwaysTrue = overallCatch.invokeStaticMethod(CONFIGURATION_ALWAYS_TRUE);

for (LambdaCapturingTypeBuildItem i : lambdaCapturingTypeBuildItems) {
TryBlock tryBlock = overallCatch.tryBlock();

tryBlock.invokeInterfaceMethod(REGISTER_LAMBDA_CAPTURING_CLASS, runtimeSerializationSupportSingleton,
configAlwaysTrue,
tryBlock.load(i.getClassName()));

CatchBlockCreator catchBlock = tryBlock.addCatch(Throwable.class);
catchBlock.invokeVirtualMethod(ofMethod(Throwable.class, "printStackTrace", void.class),
catchBlock.getCaughtException());
}
}

if (!resourceBundles.isEmpty()) {
AssignableResultHandle registerMethod = overallCatch.createVariable(Method.class);
AssignableResultHandle locClass = overallCatch.createVariable(Class.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
package io.quarkus.it.rest;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.invoke.SerializedLambda;
import java.util.Comparator;

import io.quarkus.runtime.annotations.RegisterForReflection;

/**
* This class is registering itself for lambda capturing
* This class is registering for lambda capturing
*/
@RegisterForReflection(lambdaCapturingTypes = "java.util.Comparator", targets = {
SerializedLambda.class, SerializableDoubleFunction.class }, serialization = true)
public class ResourceLambda {
private static final String file = "target/serialized.txt";

public Class<?> getLambdaFuncClass(Integer n) throws IOException, ClassNotFoundException {
SerializableDoubleFunction func = new SerializableDoubleFunction(n);
Comparator<Integer> comp = Comparator.comparingDouble(func);
serializeObject(comp);
return deserializeObject().getClass();

ByteArrayOutputStream out = new ByteArrayOutputStream();
serializeObject(out, (Serializable) comp);
return deserializeObject(out).getClass();
}

private void serializeObject(Object o) throws IOException {
FileOutputStream out = new FileOutputStream(file);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(out);
private void serializeObject(ByteArrayOutputStream byteArrayOutputStream, Serializable o) throws IOException {
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(o);
objectOutputStream.close();
}

private Object deserializeObject() throws IOException, ClassNotFoundException {
FileInputStream in = new FileInputStream(file);
ObjectInputStream objectInputStream = new ObjectInputStream(in);
private Object deserializeObject(ByteArrayOutputStream byteArrayOutputStream) throws IOException, ClassNotFoundException {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
return objectInputStream.readObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ quarkus.native.resources.excludes = **/unwanted.*

quarkus.log.metrics.enabled=true

#quarkus.native.additional-build-args =-H:ReflectionConfigurationFiles=reflection-config.json,-H:SerializationConfigurationResources=serialization-config.json
quarkus.native.additional-build-args =-H:ReflectionConfigurationFiles=reflection-config.json
quarkus.class-loading.removed-resources."io.quarkus\:quarkus-integration-test-shared-library"=io/quarkus/it/shared/RemovedResource.class
quarkus.class-loading.removed-resources."io.quarkus\:quarkus-integration-test-main"=io/quarkus/it/rest/RemovedJaxRsApplication.class

This file was deleted.