Skip to content

Commit

Permalink
Merge pull request #19629 from gsmet/2.2.0-backports-2
Browse files Browse the repository at this point in the history
2.2.0 backports 2
  • Loading branch information
gsmet authored Aug 25, 2021
2 parents ce433b4 + c4aec6e commit 4c6554f
Show file tree
Hide file tree
Showing 175 changed files with 3,038 additions and 1,050 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<microprofile-jwt.version>1.2</microprofile-jwt.version>
<microprofile-lra.version>1.0</microprofile-lra.version>
<smallrye-common.version>1.6.0</smallrye-common.version>
<smallrye-config.version>2.4.3</smallrye-config.version>
<smallrye-config.version>2.4.4</smallrye-config.version>
<smallrye-health.version>3.1.1</smallrye-health.version>
<smallrye-metrics.version>3.0.1</smallrye-metrics.version>
<smallrye-open-api.version>2.1.10</smallrye-open-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ private void setupPausedConsole() {
public void run() {
if (lastResults == null) {
testsStatusOutput.setMessage(BLUE + "Starting tests" + RESET);
} else {
testsStatusOutput.setMessage(null);
}
setupTestsRunningConsole();
TestSupport.instance().get().start();
}
}));
Expand All @@ -103,8 +106,10 @@ private void setupFirstRunConsole() {
} else {
testsStatusOutput.setMessage(BLUE + "Running tests for the first time" + RESET);
}
consoleContext.reset();
addTestOutput();
if (firstRun) {
consoleContext.reset();
addTestOutput();
}
}

void addTestOutput() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,21 +538,61 @@ private MethodDescriptor createRegisterSerializationForClassMethod(ClassCreator
ofMethod(Thread.class, "getContextClassLoader", ClassLoader.class),
currentThread);

ResultHandle objectClass = tc.invokeStaticMethod(
ofMethod(Class.class, "forName", Class.class, String.class, boolean.class, ClassLoader.class),
tc.load("java.lang.Object"), tc.load(false), tccl);
MethodDescriptor forNameMethodDescriptor = ofMethod(Class.class, "forName", Class.class, String.class, boolean.class,
ClassLoader.class);

MethodDescriptor lookupMethod = ofMethod("com.oracle.svm.util.ReflectionUtil", "lookupMethod", Method.class,
Class.class, String.class,
Class[].class);
MethodDescriptor invokeMethodDescriptor = ofMethod(Method.class, "invoke", Object.class, Object.class,
Object[].class);

BranchResult graalVm21_3Test = tc.ifGreaterEqualZero(
tc.invokeVirtualMethod(VERSION_COMPARE_TO, tc.invokeStaticMethod(VERSION_CURRENT),
tc.marshalAsArray(int.class, tc.load(21), tc.load(3))));

BytecodeCreator greaterThan21_3 = graalVm21_3Test.trueBranch();
ResultHandle runtimeSerializationClass = greaterThan21_3.invokeStaticMethod(forNameMethodDescriptor,
greaterThan21_3.load("org.graalvm.nativeimage.hosted.RuntimeSerialization"),
greaterThan21_3.load(false), tccl);
ResultHandle registerArgTypes = greaterThan21_3.newArray(Class.class, greaterThan21_3.load(1));
greaterThan21_3.writeArrayValue(registerArgTypes, 0, greaterThan21_3.loadClass(Class[].class));
ResultHandle registerLookupMethod = greaterThan21_3.invokeStaticMethod(lookupMethod, runtimeSerializationClass,
greaterThan21_3.load("register"), registerArgTypes);
ResultHandle registerArgs = greaterThan21_3.newArray(Object.class, greaterThan21_3.load(1));
ResultHandle classesToRegister = greaterThan21_3.newArray(Class.class, greaterThan21_3.load(1));
greaterThan21_3.writeArrayValue(classesToRegister, 0, clazz);
greaterThan21_3.writeArrayValue(registerArgs, 0, classesToRegister);
greaterThan21_3.invokeVirtualMethod(invokeMethodDescriptor, registerLookupMethod,
greaterThan21_3.loadNull(), registerArgs);
greaterThan21_3.returnValue(null);

ResultHandle objectClass = tc.invokeStaticMethod(forNameMethodDescriptor, tc.load("java.lang.Object"),
tc.load(false), tccl);
ResultHandle serializationRegistryClass = tc.invokeStaticMethod(forNameMethodDescriptor,
tc.load("com.oracle.svm.core.jdk.serialize.SerializationRegistry"),
tc.load(false), tccl);
ResultHandle addReflectionsClass = tc.invokeStaticMethod(forNameMethodDescriptor,
tc.load("com.oracle.svm.reflect.serialize.hosted.SerializationFeature"),
tc.load(false), tccl);

ResultHandle serializationSupport = tc.invokeStaticMethod(
IMAGE_SINGLETONS_LOOKUP,
tc.loadClass("com.oracle.svm.core.jdk.serialize.SerializationRegistry"));
serializationRegistryClass);

ResultHandle addReflectionsLookupArgs = tc.newArray(Class.class, tc.load(2));
tc.writeArrayValue(addReflectionsLookupArgs, 0, tc.loadClass(Class.class));
tc.writeArrayValue(addReflectionsLookupArgs, 1, tc.loadClass(Class.class));
ResultHandle addReflectionsLookupMethod = tc.invokeStaticMethod(lookupMethod, addReflectionsClass,
tc.load("addReflections"), addReflectionsLookupArgs);

ResultHandle reflectionFactory = tc.invokeStaticMethod(
ofMethod("sun.reflect.ReflectionFactory", "getReflectionFactory", "sun.reflect.ReflectionFactory"));

AssignableResultHandle newSerializationConstructor = tc.createVariable(Constructor.class);

ResultHandle externalizableClass = tc.invokeStaticMethod(
ofMethod(Class.class, "forName", Class.class, String.class, boolean.class, ClassLoader.class),
forNameMethodDescriptor,
tc.load("java.io.Externalizable"), tc.load(false), tccl);

BranchResult isExternalizable = tc
Expand All @@ -562,32 +602,30 @@ private MethodDescriptor createRegisterSerializationForClassMethod(ClassCreator

ResultHandle array1 = ifIsExternalizable.newArray(Class.class, tc.load(1));
ResultHandle classClass = ifIsExternalizable.invokeStaticMethod(
ofMethod(Class.class, "forName", Class.class, String.class, boolean.class, ClassLoader.class),
forNameMethodDescriptor,
ifIsExternalizable.load("java.lang.Class"), ifIsExternalizable.load(false), tccl);
ifIsExternalizable.writeArrayValue(array1, 0, classClass);

ResultHandle externalizableLookupMethod = ifIsExternalizable.invokeStaticMethod(
ofMethod("com.oracle.svm.util.ReflectionUtil", "lookupMethod", Method.class, Class.class, String.class,
Class[].class),
lookupMethod,
ifIsExternalizable.loadClass(ObjectStreamClass.class), ifIsExternalizable.load("getExternalizableConstructor"),
array1);

ResultHandle array2 = ifIsExternalizable.newArray(Object.class, tc.load(1));
ifIsExternalizable.writeArrayValue(array2, 0, clazz);

ResultHandle externalizableConstructor = ifIsExternalizable.invokeVirtualMethod(
ofMethod(Method.class, "invoke", Object.class, Object.class,
Object[].class),
externalizableLookupMethod, ifIsExternalizable.loadNull(), array2);
invokeMethodDescriptor, externalizableLookupMethod, ifIsExternalizable.loadNull(), array2);

ResultHandle externalizableConstructorClass = ifIsExternalizable.invokeVirtualMethod(
ofMethod(Constructor.class, "getDeclaringClass", Class.class),
externalizableConstructor);

ifIsExternalizable.invokeStaticMethod(
ofMethod("com.oracle.svm.reflect.serialize.hosted.SerializationFeature", "addReflections", void.class,
Class.class, Class.class),
clazz, externalizableConstructorClass);
ResultHandle addReflectionsArgs1 = ifIsExternalizable.newArray(Class.class, tc.load(2));
ifIsExternalizable.writeArrayValue(addReflectionsArgs1, 0, clazz);
ifIsExternalizable.writeArrayValue(addReflectionsArgs1, 1, externalizableConstructorClass);
ifIsExternalizable.invokeVirtualMethod(invokeMethodDescriptor, addReflectionsLookupMethod,
ifIsExternalizable.loadNull(), addReflectionsArgs1);

ifIsExternalizable.returnValue(null);

Expand Down Expand Up @@ -618,26 +656,22 @@ private MethodDescriptor createRegisterSerializationForClassMethod(ClassCreator
ofMethod(Constructor.class, "getDeclaringClass", Class.class),
newSerializationConstructor);

ResultHandle lookupMethod = tc.invokeStaticMethod(
ofMethod("com.oracle.svm.util.ReflectionUtil", "lookupMethod", Method.class, Class.class, String.class,
Class[].class),
tc.loadClass(Constructor.class), tc.load("getConstructorAccessor"),
ResultHandle getConstructorAccessor = tc.invokeStaticMethod(
lookupMethod, tc.loadClass(Constructor.class), tc.load("getConstructorAccessor"),
tc.newArray(Class.class, tc.load(0)));

ResultHandle accessor = tc.invokeVirtualMethod(
ofMethod(Method.class, "invoke", Object.class, Object.class,
Object[].class),
lookupMethod, newSerializationConstructor,
invokeMethodDescriptor, getConstructorAccessor, newSerializationConstructor,
tc.newArray(Object.class, tc.load(0)));

tc.invokeVirtualMethod(
ofMethod("com.oracle.svm.reflect.serialize.SerializationSupport", "addConstructorAccessor",
Object.class, Class.class, Class.class, Object.class),
serializationSupport, clazz, newSerializationConstructorClass, accessor);
tc.invokeStaticMethod(
ofMethod("com.oracle.svm.reflect.serialize.hosted.SerializationFeature", "addReflections", void.class,
Class.class, Class.class),
clazz, objectClass);
ResultHandle addReflectionsArgs2 = tc.newArray(Class.class, tc.load(2));
tc.writeArrayValue(addReflectionsArgs2, 0, clazz);
tc.writeArrayValue(addReflectionsArgs2, 1, objectClass);
tc.invokeVirtualMethod(invokeMethodDescriptor, addReflectionsLookupMethod, tc.loadNull(), addReflectionsArgs2);

addSerializationForClass.returnValue(null);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.quarkus.deployment.util;

import java.lang.reflect.Array;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -377,55 +376,4 @@ public ClassNotIndexedException(DotName dotName) {
}
}

public static Class<?> loadRawType(Type type) {
switch (type.kind()) {
case VOID:
return void.class;
case PRIMITIVE:
switch (type.asPrimitiveType().primitive()) {
case BOOLEAN:
return boolean.class;
case CHAR:
return char.class;
case BYTE:
return byte.class;
case SHORT:
return short.class;
case INT:
return int.class;
case LONG:
return long.class;
case FLOAT:
return float.class;
case DOUBLE:
return double.class;
default:
throw new IllegalArgumentException("Unknown primitive type: " + type);
}
case CLASS:
return load(type.asClassType().name());
case PARAMETERIZED_TYPE:
return load(type.asParameterizedType().name());
case ARRAY:
Class<?> component = loadRawType(type.asArrayType().component());
int dimensions = type.asArrayType().dimensions();
return Array.newInstance(component, new int[dimensions]).getClass();
case WILDCARD_TYPE:
return loadRawType(type.asWildcardType().extendsBound());
case TYPE_VARIABLE:
return load(type.asTypeVariable().name());
case UNRESOLVED_TYPE_VARIABLE:
return Object.class; // can't do better here
default:
throw new IllegalArgumentException("Unknown type: " + type);
}
}

private static Class<?> load(DotName name) {
try {
return Thread.currentThread().getContextClassLoader().loadClass(name.toString());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.jboss.jandex.Indexer;
Expand Down Expand Up @@ -305,72 +302,6 @@ public static class MultiBoundedRepo<X extends A & B> implements Repo<X> {
public static class ErasedRepo2 extends MultiBoundedRepo {
}

@Test
public void testLoadRawType() {
Index index = index(TestMethods.class);
ClassInfo clazz = index.getClassByName(DotName.createSimple(TestMethods.class.getName()));

assertEquals(void.class, JandexUtil.loadRawType(clazz.method("aaa").returnType()));
assertEquals(int.class, JandexUtil.loadRawType(clazz.method("bbb").returnType()));
assertEquals(String.class, JandexUtil.loadRawType(clazz.method("ccc").returnType()));
assertEquals(List.class, JandexUtil.loadRawType(clazz.method("ddd").returnType()));
assertEquals(String[][].class, JandexUtil.loadRawType(clazz.method("eee").returnType()));
assertEquals(Object.class, JandexUtil.loadRawType(clazz.method("fff").returnType()));
assertEquals(Number.class, JandexUtil.loadRawType(clazz.method("ggg").returnType()));
assertEquals(Number.class, JandexUtil.loadRawType(clazz.method("hhh").returnType()));
assertEquals(Comparable.class, JandexUtil.loadRawType(clazz.method("iii").returnType()));
assertEquals(Comparable.class, JandexUtil.loadRawType(clazz.method("jjj").returnType()));
assertEquals(Serializable.class, JandexUtil.loadRawType(clazz.method("kkk").returnType()));
assertEquals(Object.class, JandexUtil.loadRawType(clazz.method("lll").returnType()
.asParameterizedType().arguments().get(0)));
assertEquals(Number.class, JandexUtil.loadRawType(clazz.method("mmm").returnType()
.asParameterizedType().arguments().get(0)));
assertEquals(Object.class, JandexUtil.loadRawType(clazz.method("nnn").returnType()
.asParameterizedType().arguments().get(0)));
assertEquals(Object.class, JandexUtil.loadRawType(clazz.method("ooo").returnType()
.asParameterizedType().arguments().get(0)));
assertEquals(Number.class, JandexUtil.loadRawType(clazz.method("ppp").returnType()
.asParameterizedType().arguments().get(0)));
assertEquals(Object.class, JandexUtil.loadRawType(clazz.method("qqq").returnType()
.asParameterizedType().arguments().get(0)));
}

public interface TestMethods<X> {
void aaa();

int bbb();

String ccc();

List<String> ddd();

String[][] eee();

X fff();

<Y extends Number> Y ggg();

<Y extends Number & Comparable<Y>> Y hhh();

<Y extends Comparable<Y>> Y iii();

<Y extends Comparable<Y> & Serializable> Y jjj();

<Y extends Serializable & Comparable<Y>> Y kkk();

List<?> lll();

List<? extends Number> mmm();

List<? super String> nnn();

List<? extends X> ooo();

<Y extends Number> List<? extends Y> ppp();

<Y extends Number> List<? super Y> qqq();
}

private static Index index(Class<?>... classes) {
Indexer indexer = new Indexer();
for (Class<?> clazz : classes) {
Expand Down
4 changes: 3 additions & 1 deletion devtools/cli/src/main/java/io/quarkus/cli/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import picocli.CommandLine.Unmatched;

@CommandLine.Command(name = "registry", sortOptions = false, mixinStandardHelpOptions = false, header = "Manage extension registries.", subcommands = {
RegistryListCommand.class }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "%nOptions:%n")
RegistryAddCommand.class,
RegistryListCommand.class,
RegistryRemoveCommand.class }, headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "%nOptions:%n")
public class Registry extends BaseRegistryCommand {

@Unmatched // avoids throwing errors for unmatched arguments
Expand Down
Loading

0 comments on commit 4c6554f

Please sign in to comment.