mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Update Java version to 11
This commit is contained in:
parent
4a025f2605
commit
1b6acc9eb1
|
@ -27,7 +27,6 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -48,7 +47,6 @@ import org.teavm.backend.wasm.generate.WasmNameProvider;
|
||||||
import org.teavm.backend.wasm.generate.WasmSpecialFunctionGenerator;
|
import org.teavm.backend.wasm.generate.WasmSpecialFunctionGenerator;
|
||||||
import org.teavm.backend.wasm.generate.WasmStringPool;
|
import org.teavm.backend.wasm.generate.WasmStringPool;
|
||||||
import org.teavm.backend.wasm.generators.ArrayGenerator;
|
import org.teavm.backend.wasm.generators.ArrayGenerator;
|
||||||
import org.teavm.backend.wasm.generators.WasmMethodGenerator;
|
|
||||||
import org.teavm.backend.wasm.generators.WasmMethodGeneratorContext;
|
import org.teavm.backend.wasm.generators.WasmMethodGeneratorContext;
|
||||||
import org.teavm.backend.wasm.intrinsics.AddressIntrinsic;
|
import org.teavm.backend.wasm.intrinsics.AddressIntrinsic;
|
||||||
import org.teavm.backend.wasm.intrinsics.AllocatorIntrinsic;
|
import org.teavm.backend.wasm.intrinsics.AllocatorIntrinsic;
|
||||||
|
@ -110,7 +108,6 @@ import org.teavm.backend.wasm.transformation.MemoryAccessTraceTransformation;
|
||||||
import org.teavm.backend.wasm.transformation.WasiFileSystemProviderTransformer;
|
import org.teavm.backend.wasm.transformation.WasiFileSystemProviderTransformer;
|
||||||
import org.teavm.backend.wasm.transformation.WasiSupportClassTransformer;
|
import org.teavm.backend.wasm.transformation.WasiSupportClassTransformer;
|
||||||
import org.teavm.common.ServiceRepository;
|
import org.teavm.common.ServiceRepository;
|
||||||
import org.teavm.dependency.ClassDependency;
|
|
||||||
import org.teavm.dependency.DependencyAnalyzer;
|
import org.teavm.dependency.DependencyAnalyzer;
|
||||||
import org.teavm.dependency.DependencyListener;
|
import org.teavm.dependency.DependencyListener;
|
||||||
import org.teavm.diagnostics.Diagnostics;
|
import org.teavm.diagnostics.Diagnostics;
|
||||||
|
@ -128,7 +125,6 @@ import org.teavm.model.ClassHolderTransformer;
|
||||||
import org.teavm.model.ClassReader;
|
import org.teavm.model.ClassReader;
|
||||||
import org.teavm.model.ClassReaderSource;
|
import org.teavm.model.ClassReaderSource;
|
||||||
import org.teavm.model.ElementModifier;
|
import org.teavm.model.ElementModifier;
|
||||||
import org.teavm.model.FieldReader;
|
|
||||||
import org.teavm.model.FieldReference;
|
import org.teavm.model.FieldReference;
|
||||||
import org.teavm.model.Instruction;
|
import org.teavm.model.Instruction;
|
||||||
import org.teavm.model.ListableClassHolderSource;
|
import org.teavm.model.ListableClassHolderSource;
|
||||||
|
@ -311,11 +307,11 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
@Override
|
@Override
|
||||||
public void contributeDependencies(DependencyAnalyzer dependencyAnalyzer) {
|
public void contributeDependencies(DependencyAnalyzer dependencyAnalyzer) {
|
||||||
for (Class<?> type : Arrays.asList(int.class, long.class, float.class, double.class)) {
|
for (Class<?> type : Arrays.asList(int.class, long.class, float.class, double.class)) {
|
||||||
MethodReference method = new MethodReference(WasmRuntime.class, "compare", type, type, int.class);
|
var method = new MethodReference(WasmRuntime.class, "compare", type, type, int.class);
|
||||||
dependencyAnalyzer.linkMethod(method).use();
|
dependencyAnalyzer.linkMethod(method).use();
|
||||||
}
|
}
|
||||||
for (Class<?> type : Arrays.asList(float.class, double.class)) {
|
for (Class<?> type : Arrays.asList(float.class, double.class)) {
|
||||||
MethodReference method = new MethodReference(WasmRuntime.class, "remainder", type, type, type);
|
var method = new MethodReference(WasmRuntime.class, "remainder", type, type, type);
|
||||||
dependencyAnalyzer.linkMethod(method).use();
|
dependencyAnalyzer.linkMethod(method).use();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,11 +369,11 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
dependencyAnalyzer.linkMethod(new MethodReference(String.class, "allocate", int.class, String.class))
|
dependencyAnalyzer.linkMethod(new MethodReference(String.class, "allocate", int.class, String.class))
|
||||||
.use();
|
.use();
|
||||||
|
|
||||||
ClassDependency runtimeClassDep = dependencyAnalyzer.linkClass(RuntimeClass.class.getName());
|
var runtimeClassDep = dependencyAnalyzer.linkClass(RuntimeClass.class.getName());
|
||||||
ClassDependency runtimeObjectDep = dependencyAnalyzer.linkClass(RuntimeObject.class.getName());
|
var runtimeObjectDep = dependencyAnalyzer.linkClass(RuntimeObject.class.getName());
|
||||||
ClassDependency runtimeArrayDep = dependencyAnalyzer.linkClass(RuntimeArray.class.getName());
|
var runtimeArrayDep = dependencyAnalyzer.linkClass(RuntimeArray.class.getName());
|
||||||
for (ClassDependency classDep : Arrays.asList(runtimeClassDep, runtimeObjectDep, runtimeArrayDep)) {
|
for (var classDep : Arrays.asList(runtimeClassDep, runtimeObjectDep, runtimeArrayDep)) {
|
||||||
for (FieldReader field : classDep.getClassReader().getFields()) {
|
for (var field : classDep.getClassReader().getFields()) {
|
||||||
dependencyAnalyzer.linkField(field.getReference());
|
dependencyAnalyzer.linkField(field.getReference());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,7 +388,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
void.class)).use();
|
void.class)).use();
|
||||||
dependencyAnalyzer.linkMethod(new MethodReference(WasmSupport.class, "getArgs", String[].class)).use();
|
dependencyAnalyzer.linkMethod(new MethodReference(WasmSupport.class, "getArgs", String[].class)).use();
|
||||||
|
|
||||||
ClassReader fiberClass = dependencyAnalyzer.getClassSource().get(Fiber.class.getName());
|
var fiberClass = dependencyAnalyzer.getClassSource().get(Fiber.class.getName());
|
||||||
for (MethodReader method : fiberClass.getMethods()) {
|
for (MethodReader method : fiberClass.getMethods()) {
|
||||||
if (method.getName().startsWith("pop") || method.getName().equals("push")) {
|
if (method.getName().startsWith("pop") || method.getName().equals("push")) {
|
||||||
dependencyAnalyzer.linkMethod(method.getReference()).use();
|
dependencyAnalyzer.linkMethod(method.getReference()).use();
|
||||||
|
@ -404,7 +400,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void analyzeBeforeOptimizations(ListableClassReaderSource classSource) {
|
public void analyzeBeforeOptimizations(ListableClassReaderSource classSource) {
|
||||||
AsyncMethodFinder asyncFinder = new AsyncMethodFinder(controller.getDependencyInfo().getCallGraph(),
|
var asyncFinder = new AsyncMethodFinder(controller.getDependencyInfo().getCallGraph(),
|
||||||
controller.getDependencyInfo());
|
controller.getDependencyInfo());
|
||||||
asyncFinder.find(classSource);
|
asyncFinder.find(classSource);
|
||||||
asyncMethods = new HashSet<>(asyncFinder.getAsyncMethods());
|
asyncMethods = new HashSet<>(asyncFinder.getAsyncMethods());
|
||||||
|
@ -435,26 +431,25 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
WasmModule module = new WasmModule();
|
WasmModule module = new WasmModule();
|
||||||
WasmFunction initFunction = new WasmFunction("__start__");
|
WasmFunction initFunction = new WasmFunction("__start__");
|
||||||
|
|
||||||
VirtualTableProvider vtableProvider = createVirtualTableProvider(classes);
|
var vtableProvider = createVirtualTableProvider(classes);
|
||||||
ClassHierarchy hierarchy = new ClassHierarchy(classes);
|
ClassHierarchy hierarchy = new ClassHierarchy(classes);
|
||||||
TagRegistry tagRegistry = new TagRegistry(classes, hierarchy);
|
TagRegistry tagRegistry = new TagRegistry(classes, hierarchy);
|
||||||
BinaryWriter binaryWriter = new BinaryWriter(256);
|
BinaryWriter binaryWriter = new BinaryWriter(256);
|
||||||
NameProvider names = new NameProviderWithSpecialNames(new WasmNameProvider(),
|
var names = new NameProviderWithSpecialNames(new WasmNameProvider(), controller.getUnprocessedClassSource());
|
||||||
controller.getUnprocessedClassSource());
|
var metadataRequirements = new ClassMetadataRequirements(controller.getDependencyInfo());
|
||||||
ClassMetadataRequirements metadataRequirements = new ClassMetadataRequirements(controller.getDependencyInfo());
|
var classGenerator = new WasmClassGenerator(classes, controller.getUnprocessedClassSource(),
|
||||||
WasmClassGenerator classGenerator = new WasmClassGenerator(classes, controller.getUnprocessedClassSource(),
|
|
||||||
vtableProvider, tagRegistry, binaryWriter, names, metadataRequirements,
|
vtableProvider, tagRegistry, binaryWriter, names, metadataRequirements,
|
||||||
controller.getClassInitializerInfo(), characteristics);
|
controller.getClassInitializerInfo(), characteristics);
|
||||||
|
|
||||||
Decompiler decompiler = new Decompiler(classes, new HashSet<>(), false);
|
Decompiler decompiler = new Decompiler(classes, new HashSet<>(), false);
|
||||||
WasmStringPool stringPool = classGenerator.getStringPool();
|
var stringPool = classGenerator.getStringPool();
|
||||||
WasmGenerationContext context = new WasmGenerationContext(classes, module, controller.getDiagnostics(),
|
var context = new WasmGenerationContext(classes, module, controller.getDiagnostics(),
|
||||||
vtableProvider, tagRegistry, stringPool, names);
|
vtableProvider, tagRegistry, stringPool, names);
|
||||||
|
|
||||||
context.addIntrinsic(new AddressIntrinsic(classGenerator));
|
context.addIntrinsic(new AddressIntrinsic(classGenerator));
|
||||||
context.addIntrinsic(new StructureIntrinsic(classes, classGenerator));
|
context.addIntrinsic(new StructureIntrinsic(classes, classGenerator));
|
||||||
context.addIntrinsic(new FunctionIntrinsic(classGenerator));
|
context.addIntrinsic(new FunctionIntrinsic(classGenerator));
|
||||||
WasmRuntimeIntrinsic wasmRuntimeIntrinsic = new WasmRuntimeIntrinsic();
|
var wasmRuntimeIntrinsic = new WasmRuntimeIntrinsic();
|
||||||
context.addIntrinsic(wasmRuntimeIntrinsic);
|
context.addIntrinsic(wasmRuntimeIntrinsic);
|
||||||
context.addIntrinsic(new AllocatorIntrinsic(classGenerator));
|
context.addIntrinsic(new AllocatorIntrinsic(classGenerator));
|
||||||
context.addIntrinsic(new PlatformIntrinsic());
|
context.addIntrinsic(new PlatformIntrinsic());
|
||||||
|
@ -477,7 +472,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
context.addIntrinsic(new WasmHeapIntrinsic(vmAssertions));
|
context.addIntrinsic(new WasmHeapIntrinsic(vmAssertions));
|
||||||
context.addIntrinsic(new FiberIntrinsic());
|
context.addIntrinsic(new FiberIntrinsic());
|
||||||
|
|
||||||
IntrinsicFactoryContext intrinsicFactoryContext = new IntrinsicFactoryContext();
|
var intrinsicFactoryContext = new IntrinsicFactoryContext();
|
||||||
for (WasmIntrinsicFactory additionalIntrinsicFactory : additionalIntrinsics) {
|
for (WasmIntrinsicFactory additionalIntrinsicFactory : additionalIntrinsics) {
|
||||||
context.addIntrinsic(additionalIntrinsicFactory.create(intrinsicFactoryContext));
|
context.addIntrinsic(additionalIntrinsicFactory.create(intrinsicFactoryContext));
|
||||||
}
|
}
|
||||||
|
@ -487,11 +482,11 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
MutatorIntrinsic mutatorIntrinsic = new MutatorIntrinsic();
|
MutatorIntrinsic mutatorIntrinsic = new MutatorIntrinsic();
|
||||||
context.addIntrinsic(mutatorIntrinsic);
|
context.addIntrinsic(mutatorIntrinsic);
|
||||||
context.addIntrinsic(new ShadowStackIntrinsic());
|
context.addIntrinsic(new ShadowStackIntrinsic());
|
||||||
ExceptionHandlingIntrinsic exceptionHandlingIntrinsic = new ExceptionHandlingIntrinsic(binaryWriter,
|
var exceptionHandlingIntrinsic = new ExceptionHandlingIntrinsic(binaryWriter,
|
||||||
classGenerator, stringPool, obfuscated);
|
classGenerator, stringPool, obfuscated);
|
||||||
context.addIntrinsic(exceptionHandlingIntrinsic);
|
context.addIntrinsic(exceptionHandlingIntrinsic);
|
||||||
|
|
||||||
WasmGenerator generator = new WasmGenerator(decompiler, classes, context, classGenerator, binaryWriter,
|
var generator = new WasmGenerator(decompiler, classes, context, classGenerator, binaryWriter,
|
||||||
asyncMethods::contains);
|
asyncMethods::contains);
|
||||||
|
|
||||||
generateMethods(classes, context, generator, classGenerator, binaryWriter, module);
|
generateMethods(classes, context, generator, classGenerator, binaryWriter, module);
|
||||||
|
@ -505,7 +500,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
mutatorIntrinsic.setClassesAddress(classGenerator.getClassesAddress());
|
mutatorIntrinsic.setClassesAddress(classGenerator.getClassesAddress());
|
||||||
mutatorIntrinsic.setClassCount(classGenerator.getClassCount());
|
mutatorIntrinsic.setClassCount(classGenerator.getClassCount());
|
||||||
|
|
||||||
WasmMemorySegment dataSegment = new WasmMemorySegment();
|
var dataSegment = new WasmMemorySegment();
|
||||||
dataSegment.setData(binaryWriter.getData());
|
dataSegment.setData(binaryWriter.getData());
|
||||||
dataSegment.setOffset(256);
|
dataSegment.setOffset(256);
|
||||||
module.getSegments().add(dataSegment);
|
module.getSegments().add(dataSegment);
|
||||||
|
@ -537,8 +532,8 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
new IndirectCallTraceTransformation(module).apply();
|
new IndirectCallTraceTransformation(module).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
WasmBinaryWriter writer = new WasmBinaryWriter();
|
var writer = new WasmBinaryWriter();
|
||||||
WasmBinaryRenderer renderer = new WasmBinaryRenderer(writer, version, obfuscated);
|
var renderer = new WasmBinaryRenderer(writer, version, obfuscated);
|
||||||
renderer.render(module);
|
renderer.render(module);
|
||||||
|
|
||||||
try (OutputStream output = buildTarget.createResource(outputName)) {
|
try (OutputStream output = buildTarget.createResource(outputName)) {
|
||||||
|
@ -559,14 +554,14 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
private WasmFunction createStartFunction(NameProvider names) {
|
private WasmFunction createStartFunction(NameProvider names) {
|
||||||
WasmFunction function = new WasmFunction("teavm_start");
|
var function = new WasmFunction("teavm_start");
|
||||||
function.setExportName("start");
|
function.setExportName("start");
|
||||||
function.getParameters().add(WasmType.INT32);
|
function.getParameters().add(WasmType.INT32);
|
||||||
|
|
||||||
WasmLocal local = new WasmLocal(WasmType.INT32, "args");
|
var local = new WasmLocal(WasmType.INT32, "args");
|
||||||
function.add(local);
|
function.add(local);
|
||||||
|
|
||||||
WasmCall call = new WasmCall(names.forMethod(new MethodReference(Fiber.class, "startMain", String[].class,
|
var call = new WasmCall(names.forMethod(new MethodReference(Fiber.class, "startMain", String[].class,
|
||||||
void.class)));
|
void.class)));
|
||||||
call.getArguments().add(new WasmGetLocal(local));
|
call.getArguments().add(new WasmGetLocal(local));
|
||||||
function.getBody().add(call);
|
function.getBody().add(call);
|
||||||
|
@ -710,7 +705,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodGeneratorContextImpl methodGeneratorContext = new MethodGeneratorContextImpl(binaryWriter,
|
var methodGeneratorContext = new MethodGeneratorContextImpl(binaryWriter,
|
||||||
context.getStringPool(), context.getDiagnostics(), context.names, classGenerator, classes);
|
context.getStringPool(), context.getDiagnostics(), context.names, classGenerator, classes);
|
||||||
|
|
||||||
for (MethodHolder method : methods) {
|
for (MethodHolder method : methods) {
|
||||||
|
@ -736,7 +731,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (implementor.hasModifier(ElementModifier.NATIVE)) {
|
if (implementor.hasModifier(ElementModifier.NATIVE)) {
|
||||||
WasmMethodGenerator methodGenerator = context.getGenerator(method.getReference());
|
var methodGenerator = context.getGenerator(method.getReference());
|
||||||
if (methodGenerator != null) {
|
if (methodGenerator != null) {
|
||||||
WasmFunction function = context.getFunction(context.names.forMethod(method.getReference()));
|
WasmFunction function = context.getFunction(context.names.forMethod(method.getReference()));
|
||||||
methodGenerator.apply(method.getReference(), function, methodGeneratorContext);
|
methodGenerator.apply(method.getReference(), function, methodGeneratorContext);
|
||||||
|
@ -807,7 +802,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
|
|
||||||
private void generateIsClass(WasmLocal subtypeVar, WasmClassGenerator classGenerator, TagRegistry tagRegistry,
|
private void generateIsClass(WasmLocal subtypeVar, WasmClassGenerator classGenerator, TagRegistry tagRegistry,
|
||||||
String className, List<WasmExpression> body) {
|
String className, List<WasmExpression> body) {
|
||||||
List<TagRegistry.Range> ranges = tagRegistry.getRanges(className);
|
var ranges = tagRegistry.getRanges(className);
|
||||||
if (ranges.isEmpty()) {
|
if (ranges.isEmpty()) {
|
||||||
body.add(new WasmReturn(new WasmInt32Constant(0)));
|
body.add(new WasmReturn(new WasmInt32Constant(0)));
|
||||||
return;
|
return;
|
||||||
|
@ -965,14 +960,14 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
private VirtualTableProvider createVirtualTableProvider(ListableClassHolderSource classes) {
|
private VirtualTableProvider createVirtualTableProvider(ListableClassHolderSource classes) {
|
||||||
VirtualTableBuilder builder = new VirtualTableBuilder(classes);
|
var builder = new VirtualTableBuilder(classes);
|
||||||
builder.setMethodsUsedAtCallSites(getMethodsUsedOnCallSites(classes));
|
builder.setMethodsUsedAtCallSites(getMethodsUsedOnCallSites(classes));
|
||||||
builder.setMethodCalledVirtually(controller::isVirtual);
|
builder.setMethodCalledVirtually(controller::isVirtual);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<MethodReference> getMethodsUsedOnCallSites(ListableClassHolderSource classes) {
|
private Set<MethodReference> getMethodsUsedOnCallSites(ListableClassHolderSource classes) {
|
||||||
Set<MethodReference> virtualMethods = new HashSet<>();
|
var virtualMethods = new HashSet<MethodReference>();
|
||||||
|
|
||||||
for (String className : classes.getClassNames()) {
|
for (String className : classes.getClassNames()) {
|
||||||
ClassHolder cls = classes.get(className);
|
ClassHolder cls = classes.get(className);
|
||||||
|
@ -1085,8 +1080,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
public WasmExpression apply(InvocationExpr invocation, WasmIntrinsicManager manager) {
|
public WasmExpression apply(InvocationExpr invocation, WasmIntrinsicManager manager) {
|
||||||
switch (invocation.getMethod().getName()) {
|
switch (invocation.getMethod().getName()) {
|
||||||
case "runMain": {
|
case "runMain": {
|
||||||
Iterator<? extends TeaVMEntryPoint> entryPointIter = controller.getEntryPoints().values()
|
var entryPointIter = controller.getEntryPoints().values().iterator();
|
||||||
.iterator();
|
|
||||||
if (entryPointIter.hasNext()) {
|
if (entryPointIter.hasNext()) {
|
||||||
TeaVMEntryPoint entryPoint = entryPointIter.next();
|
TeaVMEntryPoint entryPoint = entryPointIter.next();
|
||||||
String name = manager.getNames().forMethod(entryPoint.getMethod());
|
String name = manager.getNames().forMethod(entryPoint.getMethod());
|
||||||
|
@ -1095,7 +1089,7 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost {
|
||||||
call.setLocation(invocation.getLocation());
|
call.setLocation(invocation.getLocation());
|
||||||
return call;
|
return call;
|
||||||
} else {
|
} else {
|
||||||
WasmUnreachable unreachable = new WasmUnreachable();
|
var unreachable = new WasmUnreachable();
|
||||||
unreachable.setLocation(invocation.getLocation());
|
unreachable.setLocation(invocation.getLocation());
|
||||||
return unreachable;
|
return unreachable;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ import org.teavm.dependency.DependencyInfo;
|
||||||
import org.teavm.dependency.DependencyListener;
|
import org.teavm.dependency.DependencyListener;
|
||||||
import org.teavm.dependency.DependencyPlugin;
|
import org.teavm.dependency.DependencyPlugin;
|
||||||
import org.teavm.dependency.Linker;
|
import org.teavm.dependency.Linker;
|
||||||
import org.teavm.dependency.MethodDependency;
|
|
||||||
import org.teavm.dependency.MethodDependencyInfo;
|
import org.teavm.dependency.MethodDependencyInfo;
|
||||||
import org.teavm.diagnostics.AccumulationDiagnostics;
|
import org.teavm.diagnostics.AccumulationDiagnostics;
|
||||||
import org.teavm.diagnostics.Diagnostics;
|
import org.teavm.diagnostics.Diagnostics;
|
||||||
|
@ -291,7 +290,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
+ "for class " + className);
|
+ "for class " + className);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassReader cls = dependencyAnalyzer.getClassSource().get(className);
|
var cls = dependencyAnalyzer.getClassSource().get(className);
|
||||||
if (cls == null) {
|
if (cls == null) {
|
||||||
diagnostics.error(null, "There's no main class: '{{c0}}'", className);
|
diagnostics.error(null, "There's no main class: '{{c0}}'", className);
|
||||||
return;
|
return;
|
||||||
|
@ -303,10 +302,10 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodDependency mainMethod = dependencyAnalyzer.linkMethod(new MethodReference(className,
|
var mainMethod = dependencyAnalyzer.linkMethod(new MethodReference(className,
|
||||||
"main", ValueType.parse(String[].class), ValueType.VOID));
|
"main", ValueType.parse(String[].class), ValueType.VOID));
|
||||||
|
|
||||||
TeaVMEntryPoint entryPoint = new TeaVMEntryPoint(name, mainMethod);
|
var entryPoint = new TeaVMEntryPoint(name, mainMethod);
|
||||||
dependencyAnalyzer.defer(() -> {
|
dependencyAnalyzer.defer(() -> {
|
||||||
dependencyAnalyzer.linkClass(className).initClass(null);
|
dependencyAnalyzer.linkClass(className).initClass(null);
|
||||||
mainMethod.getVariable(1).propagate(dependencyAnalyzer.getType("[Ljava/lang/String;"));
|
mainMethod.getVariable(1).propagate(dependencyAnalyzer.getType("[Ljava/lang/String;"));
|
||||||
|
@ -440,7 +439,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
compileProgressLimit *= 2;
|
compileProgressLimit *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
ListableClassHolderSource classSet = link(dependencyAnalyzer);
|
var classSet = link(dependencyAnalyzer);
|
||||||
writtenClasses = classSet;
|
writtenClasses = classSet;
|
||||||
if (wasCancelled()) {
|
if (wasCancelled()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -452,7 +451,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassInitializerAnalysis classInitializerAnalysis = new ClassInitializerAnalysis(classSet,
|
var classInitializerAnalysis = new ClassInitializerAnalysis(classSet,
|
||||||
dependencyAnalyzer.getClassHierarchy());
|
dependencyAnalyzer.getClassHierarchy());
|
||||||
classInitializerAnalysis.analyze(dependencyAnalyzer);
|
classInitializerAnalysis.analyze(dependencyAnalyzer);
|
||||||
classInitializerInfo = classInitializerAnalysis;
|
classInitializerInfo = classInitializerAnalysis;
|
||||||
|
@ -494,13 +493,13 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListableClassHolderSource lazyPipeline() {
|
private ListableClassHolderSource lazyPipeline() {
|
||||||
PostProcessingClassHolderSource result = new PostProcessingClassHolderSource();
|
var result = new PostProcessingClassHolderSource();
|
||||||
writtenClasses = result;
|
writtenClasses = result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertClassInit(ListableClassHolderSource classes) {
|
private void insertClassInit(ListableClassHolderSource classes) {
|
||||||
ClassInitializerInsertionTransformer clinitInsertion = new ClassInitializerInsertionTransformer(
|
var clinitInsertion = new ClassInitializerInsertionTransformer(
|
||||||
dependencyAnalyzer.getClassSource(), classInitializerInfo);
|
dependencyAnalyzer.getClassSource(), classInitializerInfo);
|
||||||
for (String className : classes.getClassNames()) {
|
for (String className : classes.getClassNames()) {
|
||||||
ClassHolder cls = classes.get(className);
|
ClassHolder cls = classes.get(className);
|
||||||
|
@ -525,7 +524,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
for (BasicBlock block : program.getBasicBlocks()) {
|
for (BasicBlock block : program.getBasicBlocks()) {
|
||||||
for (Instruction instruction : block) {
|
for (Instruction instruction : block) {
|
||||||
if (instruction instanceof InitClassInstruction) {
|
if (instruction instanceof InitClassInstruction) {
|
||||||
InitClassInstruction clinit = (InitClassInstruction) instruction;
|
var clinit = (InitClassInstruction) instruction;
|
||||||
if (!classInitializerInfo.isDynamicInitializer(clinit.getClassName())) {
|
if (!classInitializerInfo.isDynamicInitializer(clinit.getClassName())) {
|
||||||
clinit.delete();
|
clinit.delete();
|
||||||
}
|
}
|
||||||
|
@ -555,7 +554,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
BasicBlock block = program.basicBlockAt(0);
|
BasicBlock block = program.basicBlockAt(0);
|
||||||
Instruction first = block.getFirstInstruction();
|
Instruction first = block.getFirstInstruction();
|
||||||
for (String className : classInitializerInfo.getInitializationOrder()) {
|
for (String className : classInitializerInfo.getInitializationOrder()) {
|
||||||
InvokeInstruction invoke = new InvokeInstruction();
|
var invoke = new InvokeInstruction();
|
||||||
invoke.setMethod(new MethodReference(className, "<clinit>", ValueType.VOID));
|
invoke.setMethod(new MethodReference(className, "<clinit>", ValueType.VOID));
|
||||||
first.insertPrevious(invoke);
|
first.insertPrevious(invoke);
|
||||||
}
|
}
|
||||||
|
@ -563,8 +562,8 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
|
|
||||||
public ListableClassHolderSource link(DependencyAnalyzer dependency) {
|
public ListableClassHolderSource link(DependencyAnalyzer dependency) {
|
||||||
Linker linker = new Linker(dependency);
|
Linker linker = new Linker(dependency);
|
||||||
MutableClassHolderSource cutClasses = new MutableClassHolderSource();
|
var cutClasses = new MutableClassHolderSource();
|
||||||
MissingItemsProcessor missingItemsProcessor = new MissingItemsProcessor(dependency,
|
var missingItemsProcessor = new MissingItemsProcessor(dependency,
|
||||||
dependency.getClassHierarchy(), diagnostics, target.getPlatformTags());
|
dependency.getClassHierarchy(), diagnostics, target.getPlatformTags());
|
||||||
if (wasCancelled()) {
|
if (wasCancelled()) {
|
||||||
return cutClasses;
|
return cutClasses;
|
||||||
|
@ -617,8 +616,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
System.out.println("Running devirtualization");
|
System.out.println("Running devirtualization");
|
||||||
}
|
}
|
||||||
|
|
||||||
Devirtualization devirtualization = new Devirtualization(dependencyAnalyzer,
|
var devirtualization = new Devirtualization(dependencyAnalyzer, dependencyAnalyzer.getClassHierarchy());
|
||||||
dependencyAnalyzer.getClassHierarchy());
|
|
||||||
for (String className : classes.getClassNames()) {
|
for (String className : classes.getClassNames()) {
|
||||||
ClassHolder cls = classes.get(className);
|
ClassHolder cls = classes.get(className);
|
||||||
for (MethodHolder method : cls.getMethods()) {
|
for (MethodHolder method : cls.getMethods()) {
|
||||||
|
@ -655,7 +653,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
Inlining inlining = new Inlining(new ClassHierarchy(classes), dependencyAnalyzer, inliningStrategy,
|
Inlining inlining = new Inlining(new ClassHierarchy(classes), dependencyAnalyzer, inliningStrategy,
|
||||||
classes, this::isExternal, optimizationLevel == TeaVMOptimizationLevel.FULL,
|
classes, this::isExternal, optimizationLevel == TeaVMOptimizationLevel.FULL,
|
||||||
target.getInliningFilter());
|
target.getInliningFilter());
|
||||||
List<MethodReference> methodReferences = inlining.getOrder();
|
var methodReferences = inlining.getOrder();
|
||||||
int classCount = classes.getClassNames().size();
|
int classCount = classes.getClassNames().size();
|
||||||
int initialValue = compileProgressValue;
|
int initialValue = compileProgressValue;
|
||||||
for (int i = 0; i < methodReferences.size(); i++) {
|
for (int i = 0; i < methodReferences.size(); i++) {
|
||||||
|
@ -675,7 +673,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
method.setProgram(null);
|
method.setProgram(null);
|
||||||
} else {
|
} else {
|
||||||
Program program = method.getProgram();
|
Program program = method.getProgram();
|
||||||
MethodOptimizationContextImpl context = new MethodOptimizationContextImpl(method);
|
var context = new MethodOptimizationContextImpl(method);
|
||||||
inlining.apply(program, method.getReference());
|
inlining.apply(program, method.getReference());
|
||||||
new UnusedVariableElimination().optimize(context, program);
|
new UnusedVariableElimination().optimize(context, program);
|
||||||
}
|
}
|
||||||
|
@ -726,7 +724,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
|
||||||
target.beforeOptimizations(optimizedProgram, method);
|
target.beforeOptimizations(optimizedProgram, method);
|
||||||
|
|
||||||
if (optimizedProgram.basicBlockCount() > 0) {
|
if (optimizedProgram.basicBlockCount() > 0) {
|
||||||
MethodOptimizationContextImpl context = new MethodOptimizationContextImpl(method);
|
var context = new MethodOptimizationContextImpl(method);
|
||||||
boolean changed;
|
boolean changed;
|
||||||
do {
|
do {
|
||||||
changed = false;
|
changed = false;
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -70,7 +70,7 @@
|
||||||
<slf4j.version>1.7.30</slf4j.version>
|
<slf4j.version>1.7.30</slf4j.version>
|
||||||
<asm.version>9.4</asm.version>
|
<asm.version>9.4</asm.version>
|
||||||
|
|
||||||
<java.version>1.8</java.version>
|
<java.version>11</java.version>
|
||||||
<java-tests.version>17</java-tests.version>
|
<java-tests.version>17</java-tests.version>
|
||||||
|
|
||||||
<rhino.version>1.7.11</rhino.version>
|
<rhino.version>1.7.11</rhino.version>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user