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; 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.ServiceLoader; import java.util.ServiceLoader;
@ -27,8 +22,11 @@ import org.teavm.backend.javascript.TeaVMJavaScriptHost;
import org.teavm.classlib.ReflectionSupplier; import org.teavm.classlib.ReflectionSupplier;
import org.teavm.classlib.impl.lambda.LambdaMetafactorySubstitutor; import org.teavm.classlib.impl.lambda.LambdaMetafactorySubstitutor;
import org.teavm.classlib.impl.unicode.CLDRReader; 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.classlib.java.lang.reflect.AnnotationDependencyListener;
import org.teavm.interop.PlatformMarker;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
import org.teavm.model.ValueType;
import org.teavm.platform.PlatformClass; import org.teavm.platform.PlatformClass;
import org.teavm.vm.spi.TeaVMHost; import org.teavm.vm.spi.TeaVMHost;
import org.teavm.vm.spi.TeaVMPlugin; import org.teavm.vm.spi.TeaVMPlugin;
@ -36,42 +34,65 @@ import org.teavm.vm.spi.TeaVMPlugin;
public class JCLPlugin implements TeaVMPlugin { public class JCLPlugin implements TeaVMPlugin {
@Override @Override
public void install(TeaVMHost host) { public void install(TeaVMHost host) {
ServiceLoaderSupport serviceLoaderSupp = new ServiceLoaderSupport(host.getClassLoader()); if (!isBootstrap()) {
host.add(serviceLoaderSupp); ServiceLoaderSupport serviceLoaderSupp = new ServiceLoaderSupport(host.getClassLoader());
MethodReference loadServicesMethod = new MethodReference(ServiceLoader.class, "loadServices", host.add(serviceLoaderSupp);
PlatformClass.class, Object[].class); MethodReference loadServicesMethod = new MethodReference(ServiceLoader.class, "loadServices",
TeaVMJavaScriptHost jsExtension = host.getExtension(TeaVMJavaScriptHost.class); PlatformClass.class, Object[].class);
if (jsExtension != null) { TeaVMJavaScriptHost jsExtension = host.getExtension(TeaVMJavaScriptHost.class);
jsExtension.add(loadServicesMethod, serviceLoaderSupp); if (jsExtension != null) {
jsExtension.add(loadServicesMethod, serviceLoaderSupp);
}
JavacSupport javacSupport = new JavacSupport();
host.add(javacSupport);
} }
JavacSupport javacSupport = new JavacSupport(); if (!isBootstrap()) {
host.add(javacSupport); 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()); host.add(new AnnotationDependencyListener());
LambdaMetafactorySubstitutor lms = new LambdaMetafactorySubstitutor(); LambdaMetafactorySubstitutor lms = new LambdaMetafactorySubstitutor();
host.add(new MethodReference(LambdaMetafactory.class, "metafactory", MethodHandles.Lookup.class, host.add(new MethodReference("java.lang.invoke.LambdaMetafactory", "metafactory",
String.class, MethodType.class, MethodType.class, MethodHandle.class, MethodType.class, ValueType.object("java.lang.invoke.MethodHandles$Lookup"), ValueType.object("java.lang.String"),
CallSite.class), lms); ValueType.object("java.lang.invoke.MethodType"), ValueType.object("java.lang.invoke.MethodType"),
host.add(new MethodReference(LambdaMetafactory.class, "altMetafactory", MethodHandles.Lookup.class, ValueType.object("java.lang.invoke.MethodHandle"), ValueType.object("java.lang.invoke.MethodType"),
String.class, MethodType.class, Object[].class, CallSite.class), lms); 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()); host.add(new NumericClassTransformer());
List<ReflectionSupplier> reflectionSuppliers = new ArrayList<>(); if (!isBootstrap()) {
for (ReflectionSupplier supplier : ServiceLoader.load(ReflectionSupplier.class, host.getClassLoader())) { List<ReflectionSupplier> reflectionSuppliers = new ArrayList<>();
reflectionSuppliers.add(supplier); for (ReflectionSupplier supplier : ServiceLoader.load(ReflectionSupplier.class, host.getClassLoader())) {
} reflectionSuppliers.add(supplier);
ReflectionDependencyListener reflection = new ReflectionDependencyListener(reflectionSuppliers); }
host.registerService(ReflectionDependencyListener.class, reflection); ReflectionDependencyListener reflection = new ReflectionDependencyListener(reflectionSuppliers);
host.add(reflection); 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); Allocator.moveMemoryBlock(srcAddress, destAddress, length * itemSize);
} }
@GeneratedBy(SystemNativeGenerator.class)
@DelegateTo("currentTimeMillisLowLevel") @DelegateTo("currentTimeMillisLowLevel")
public static native long currentTimeMillis(); 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.WasmIntrinsic;
import org.teavm.backend.wasm.intrinsics.WasmIntrinsicManager; import org.teavm.backend.wasm.intrinsics.WasmIntrinsicManager;
import org.teavm.backend.wasm.model.expression.WasmExpression; import org.teavm.backend.wasm.model.expression.WasmExpression;
import org.teavm.interop.PlatformMarker;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
import org.teavm.vm.spi.TeaVMHost; import org.teavm.vm.spi.TeaVMHost;
import org.teavm.vm.spi.TeaVMPlugin; import org.teavm.vm.spi.TeaVMPlugin;
@ -33,27 +34,29 @@ public class PlatformPlugin implements TeaVMPlugin {
host.add(new ResourceTransformer()); host.add(new ResourceTransformer());
host.add(new ResourceAccessorTransformer(host)); host.add(new ResourceAccessorTransformer(host));
host.add(new ResourceAccessorDependencyListener()); host.add(new ResourceAccessorDependencyListener());
} else { } else if (!isBootstrap()) {
host.add(new StringAmplifierTransformer()); host.add(new StringAmplifierTransformer());
} }
TeaVMWasmHost wasmHost = host.getExtension(TeaVMWasmHost.class); if (!isBootstrap()) {
if (wasmHost != null) { TeaVMWasmHost wasmHost = host.getExtension(TeaVMWasmHost.class);
wasmHost.add(ctx -> new MetadataIntrinsic(ctx.getClassSource(), ctx.getClassLoader(), ctx.getServices(), if (wasmHost != null) {
ctx.getProperties())); wasmHost.add(ctx -> new MetadataIntrinsic(ctx.getClassSource(), ctx.getClassLoader(), ctx.getServices(),
wasmHost.add(ctx -> new ResourceReadIntrinsic(ctx.getClassSource(), ctx.getClassLoader())); ctx.getProperties()));
wasmHost.add(ctx -> new ResourceReadIntrinsic(ctx.getClassSource(), ctx.getClassLoader()));
wasmHost.add(ctx -> new WasmIntrinsic() { wasmHost.add(ctx -> new WasmIntrinsic() {
@Override @Override
public boolean isApplicable(MethodReference methodReference) { public boolean isApplicable(MethodReference methodReference) {
return methodReference.getClassName().equals(StringAmplifier.class.getName()); return methodReference.getClassName().equals(StringAmplifier.class.getName());
} }
@Override @Override
public WasmExpression apply(InvocationExpr invocation, WasmIntrinsicManager manager) { public WasmExpression apply(InvocationExpr invocation, WasmIntrinsicManager manager) {
return manager.generate(invocation.getArguments().get(0)); return manager.generate(invocation.getArguments().get(0));
} }
}); });
}
} }
host.add(new AsyncMethodProcessor()); host.add(new AsyncMethodProcessor());
@ -63,4 +66,9 @@ public class PlatformPlugin implements TeaVMPlugin {
host.add(new AnnotationDependencySupport()); host.add(new AnnotationDependencySupport());
host.add(new PlatformDependencyListener()); host.add(new PlatformDependencyListener());
} }
@PlatformMarker
private static boolean isBootstrap() {
return false;
}
} }