Minor fixes for bootstrapping TeaVM

This commit is contained in:
Alexey Andreev 2017-11-20 02:00:25 +03:00
parent 256814a60a
commit 42be95959b
3 changed files with 75 additions and 47 deletions

View File

@ -15,11 +15,6 @@
*/
package org.teavm.classlib.impl;
import java.lang.invoke.CallSite;
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
@ -27,8 +22,11 @@ import org.teavm.backend.javascript.TeaVMJavaScriptHost;
import org.teavm.classlib.ReflectionSupplier;
import org.teavm.classlib.impl.lambda.LambdaMetafactorySubstitutor;
import org.teavm.classlib.impl.unicode.CLDRReader;
import org.teavm.classlib.java.lang.SystemNativeGenerator;
import org.teavm.classlib.java.lang.reflect.AnnotationDependencyListener;
import org.teavm.interop.PlatformMarker;
import org.teavm.model.MethodReference;
import org.teavm.model.ValueType;
import org.teavm.platform.PlatformClass;
import org.teavm.vm.spi.TeaVMHost;
import org.teavm.vm.spi.TeaVMPlugin;
@ -36,42 +34,65 @@ import org.teavm.vm.spi.TeaVMPlugin;
public class JCLPlugin implements TeaVMPlugin {
@Override
public void install(TeaVMHost host) {
ServiceLoaderSupport serviceLoaderSupp = new ServiceLoaderSupport(host.getClassLoader());
host.add(serviceLoaderSupp);
MethodReference loadServicesMethod = new MethodReference(ServiceLoader.class, "loadServices",
PlatformClass.class, Object[].class);
TeaVMJavaScriptHost jsExtension = host.getExtension(TeaVMJavaScriptHost.class);
if (jsExtension != null) {
jsExtension.add(loadServicesMethod, serviceLoaderSupp);
if (!isBootstrap()) {
ServiceLoaderSupport serviceLoaderSupp = new ServiceLoaderSupport(host.getClassLoader());
host.add(serviceLoaderSupp);
MethodReference loadServicesMethod = new MethodReference(ServiceLoader.class, "loadServices",
PlatformClass.class, Object[].class);
TeaVMJavaScriptHost jsExtension = host.getExtension(TeaVMJavaScriptHost.class);
if (jsExtension != null) {
jsExtension.add(loadServicesMethod, serviceLoaderSupp);
}
JavacSupport javacSupport = new JavacSupport();
host.add(javacSupport);
}
JavacSupport javacSupport = new JavacSupport();
host.add(javacSupport);
if (!isBootstrap()) {
host.registerService(CLDRReader.class, CLDRReader.getInstance(host.getProperties(), host.getClassLoader()));
host.registerService(CLDRReader.class, CLDRReader.getInstance(host.getProperties(), host.getClassLoader()));
host.add(new ClassForNameTransformer());
}
host.add(new ClassForNameTransformer());
host.add(new AnnotationDependencyListener());
LambdaMetafactorySubstitutor lms = new LambdaMetafactorySubstitutor();
host.add(new MethodReference(LambdaMetafactory.class, "metafactory", MethodHandles.Lookup.class,
String.class, MethodType.class, MethodType.class, MethodHandle.class, MethodType.class,
CallSite.class), lms);
host.add(new MethodReference(LambdaMetafactory.class, "altMetafactory", MethodHandles.Lookup.class,
String.class, MethodType.class, Object[].class, CallSite.class), lms);
host.add(new MethodReference("java.lang.invoke.LambdaMetafactory", "metafactory",
ValueType.object("java.lang.invoke.MethodHandles$Lookup"), ValueType.object("java.lang.String"),
ValueType.object("java.lang.invoke.MethodType"), ValueType.object("java.lang.invoke.MethodType"),
ValueType.object("java.lang.invoke.MethodHandle"), ValueType.object("java.lang.invoke.MethodType"),
ValueType.object("java.lang.invoke.CallSite")), lms);
host.add(new MethodReference("java.lang.invoke.LambdaMetafactory", "altMetafactory",
ValueType.object("java.lang.invoke.MethodHandles$Lookup"),
ValueType.object("java.lang.String"), ValueType.object("java.lang.invoke.MethodType"),
ValueType.arrayOf(ValueType.object("java.lang.Object")),
ValueType.object("java.lang.invoke.CallSite")), lms);
host.add(new ScalaHacks());
if (!isBootstrap()) {
host.add(new ScalaHacks());
}
host.add(new NumericClassTransformer());
List<ReflectionSupplier> reflectionSuppliers = new ArrayList<>();
for (ReflectionSupplier supplier : ServiceLoader.load(ReflectionSupplier.class, host.getClassLoader())) {
reflectionSuppliers.add(supplier);
}
ReflectionDependencyListener reflection = new ReflectionDependencyListener(reflectionSuppliers);
host.registerService(ReflectionDependencyListener.class, reflection);
host.add(reflection);
if (!isBootstrap()) {
List<ReflectionSupplier> reflectionSuppliers = new ArrayList<>();
for (ReflectionSupplier supplier : ServiceLoader.load(ReflectionSupplier.class, host.getClassLoader())) {
reflectionSuppliers.add(supplier);
}
ReflectionDependencyListener reflection = new ReflectionDependencyListener(reflectionSuppliers);
host.registerService(ReflectionDependencyListener.class, reflection);
host.add(reflection);
host.add(new PlatformMarkerSupport());
host.add(new PlatformMarkerSupport());
}
TeaVMJavaScriptHost jsHost = host.getExtension(TeaVMJavaScriptHost.class);
jsHost.add(new MethodReference("java.lang.System", "currentTimeMillis", ValueType.LONG),
new SystemNativeGenerator());
}
@PlatformMarker
private static boolean isBootstrap() {
return false;
}
}

View File

@ -101,7 +101,6 @@ public final class TSystem extends TObject {
Allocator.moveMemoryBlock(srcAddress, destAddress, length * itemSize);
}
@GeneratedBy(SystemNativeGenerator.class)
@DelegateTo("currentTimeMillisLowLevel")
public static native long currentTimeMillis();

View File

@ -21,6 +21,7 @@ import org.teavm.backend.wasm.TeaVMWasmHost;
import org.teavm.backend.wasm.intrinsics.WasmIntrinsic;
import org.teavm.backend.wasm.intrinsics.WasmIntrinsicManager;
import org.teavm.backend.wasm.model.expression.WasmExpression;
import org.teavm.interop.PlatformMarker;
import org.teavm.model.MethodReference;
import org.teavm.vm.spi.TeaVMHost;
import org.teavm.vm.spi.TeaVMPlugin;
@ -33,27 +34,29 @@ public class PlatformPlugin implements TeaVMPlugin {
host.add(new ResourceTransformer());
host.add(new ResourceAccessorTransformer(host));
host.add(new ResourceAccessorDependencyListener());
} else {
} else if (!isBootstrap()) {
host.add(new StringAmplifierTransformer());
}
TeaVMWasmHost wasmHost = host.getExtension(TeaVMWasmHost.class);
if (wasmHost != null) {
wasmHost.add(ctx -> new MetadataIntrinsic(ctx.getClassSource(), ctx.getClassLoader(), ctx.getServices(),
ctx.getProperties()));
wasmHost.add(ctx -> new ResourceReadIntrinsic(ctx.getClassSource(), ctx.getClassLoader()));
if (!isBootstrap()) {
TeaVMWasmHost wasmHost = host.getExtension(TeaVMWasmHost.class);
if (wasmHost != null) {
wasmHost.add(ctx -> new MetadataIntrinsic(ctx.getClassSource(), ctx.getClassLoader(), ctx.getServices(),
ctx.getProperties()));
wasmHost.add(ctx -> new ResourceReadIntrinsic(ctx.getClassSource(), ctx.getClassLoader()));
wasmHost.add(ctx -> new WasmIntrinsic() {
@Override
public boolean isApplicable(MethodReference methodReference) {
return methodReference.getClassName().equals(StringAmplifier.class.getName());
}
wasmHost.add(ctx -> new WasmIntrinsic() {
@Override
public boolean isApplicable(MethodReference methodReference) {
return methodReference.getClassName().equals(StringAmplifier.class.getName());
}
@Override
public WasmExpression apply(InvocationExpr invocation, WasmIntrinsicManager manager) {
return manager.generate(invocation.getArguments().get(0));
}
});
@Override
public WasmExpression apply(InvocationExpr invocation, WasmIntrinsicManager manager) {
return manager.generate(invocation.getArguments().get(0));
}
});
}
}
host.add(new AsyncMethodProcessor());
@ -63,4 +66,9 @@ public class PlatformPlugin implements TeaVMPlugin {
host.add(new AnnotationDependencySupport());
host.add(new PlatformDependencyListener());
}
@PlatformMarker
private static boolean isBootstrap() {
return false;
}
}