From e7e13b21e04093d88670d1981b050258fccf7313 Mon Sep 17 00:00:00 2001 From: Mirko Sertic Date: Fri, 15 May 2020 09:33:36 +0200 Subject: [PATCH] #410 Turn off escape analysis by default (#411) --- .../bytecoder/cli/BytecoderCLI.java | 5 +- .../bytecoder/backend/CompileOptions.java | 9 +++- .../backend/llvm/LLVMCompilerBackend.java | 4 +- .../bytecoder/backend/llvm/LLVMWriter.java | 52 ++++++++++--------- .../backend/opencl/OpenCLContext.java | 2 +- .../unittest/BytecoderTestOption.java | 3 ++ .../unittest/BytecoderUnitTestRunner.java | 36 ++++++------- .../bytecoder/unittest/TestOption.java | 8 ++- .../LinearRegisterAllocatorTest.java | 2 +- .../PassThruRegisterAllocatorTest.java | 20 +++---- .../bytecoder/api/opencl/CompilerTest.java | 4 +- .../bytecoder/complex/Profiler.java | 2 +- .../bytecoder/maven/BytecoderMavenMojo.java | 8 ++- 13 files changed, 91 insertions(+), 64 deletions(-) diff --git a/cli/src/main/java/de/mirkosertic/bytecoder/cli/BytecoderCLI.java b/cli/src/main/java/de/mirkosertic/bytecoder/cli/BytecoderCLI.java index b8a709f670..73f06190d0 100644 --- a/cli/src/main/java/de/mirkosertic/bytecoder/cli/BytecoderCLI.java +++ b/cli/src/main/java/de/mirkosertic/bytecoder/cli/BytecoderCLI.java @@ -94,6 +94,9 @@ public static class CLIOptions { @Option(names = "-llvmOptimizationLevel", required = false, description = "Optimization level for the LLVM backend. Generate code at different optimization levels. These correspond to the -O0, -O1, -O2, and -O3 optimization levels used by clang.") protected String llvmOptimizationLevel = LLVMOptimizationLevel.defaultValue().name(); + @Option(names = "-escapeAnalysis", required = false, description = "Shall the escape analysis be enabled? Defaults to 'false'.") + protected boolean escapeAnalysisEnabled = false; + } public static void main(final String[] args) throws IOException, ClassNotFoundException { @@ -125,7 +128,7 @@ public static void main(final String[] args) throws IOException, ClassNotFoundEx final BytecodeMethodSignature theSignature = new BytecodeMethodSignature(BytecodePrimitiveTypeRef.VOID, new BytecodeTypeRef[] { new BytecodeArrayTypeRef(BytecodeObjectTypeRef.fromRuntimeClass(String.class), 1) }); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), theCLIOptions.debugOutput, KnownOptimizer.valueOf(theCLIOptions.optimizationLevel), theCLIOptions.enableExceptionHandling, theCLIOptions.filenamePrefix, theCLIOptions.wasmInitialPages, theCLIOptions.wasmMaximumPages, theCLIOptions.minifyCompileResult, theCLIOptions.preferStackifier, Allocator.valueOf(theCLIOptions.registerAllocator), theCLIOptions.additionalClassesToLink, theCLIOptions.additionalResources, LLVMOptimizationLevel.valueOf(theCLIOptions.llvmOptimizationLevel)); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), theCLIOptions.debugOutput, KnownOptimizer.valueOf(theCLIOptions.optimizationLevel), theCLIOptions.enableExceptionHandling, theCLIOptions.filenamePrefix, theCLIOptions.wasmInitialPages, theCLIOptions.wasmMaximumPages, theCLIOptions.minifyCompileResult, theCLIOptions.preferStackifier, Allocator.valueOf(theCLIOptions.registerAllocator), theCLIOptions.additionalClassesToLink, theCLIOptions.additionalResources, LLVMOptimizationLevel.valueOf(theCLIOptions.llvmOptimizationLevel), theCLIOptions.escapeAnalysisEnabled); final CompileResult theCode = theCompileTarget.compile(theOptions, theTargetClass, "main", theSignature); for (final CompileResult.Content content : theCode.getContent()) { final File theBytecoderFileName = new File(theBytecoderDirectory, content.getFileName()); diff --git a/core/src/main/java/de/mirkosertic/bytecoder/backend/CompileOptions.java b/core/src/main/java/de/mirkosertic/bytecoder/backend/CompileOptions.java index 68c5ccdf28..4a34743e50 100644 --- a/core/src/main/java/de/mirkosertic/bytecoder/backend/CompileOptions.java +++ b/core/src/main/java/de/mirkosertic/bytecoder/backend/CompileOptions.java @@ -34,6 +34,7 @@ public class CompileOptions { private final String[] additionalClassesToLink; private final String[] additionalResources; private final LLVMOptimizationLevel llvmOptimizationLevel; + private final boolean escapeAnalysisEnabled; public CompileOptions(final Logger aLogger, final boolean aDebugOutput, final Optimizer aOptimizer, final boolean aEnableExceptions, final String aFilenamePrefix, final int aWasmMinimumPageSize, final int aWasmMaximumPageSize, @@ -42,7 +43,8 @@ public CompileOptions(final Logger aLogger, final boolean aDebugOutput, final Op final Allocator aAllocator, final String[] aAdditionalClassesToLink, final String[] aAdditionalResources, - final LLVMOptimizationLevel aLlvmOptimizationLevel) { + final LLVMOptimizationLevel aLlvmOptimizationLevel, + final boolean aEscapeAnalysisEnabled) { logger = aLogger; debugOutput = aDebugOutput; optimizer = aOptimizer; @@ -56,6 +58,7 @@ public CompileOptions(final Logger aLogger, final boolean aDebugOutput, final Op additionalClassesToLink = aAdditionalClassesToLink; additionalResources = aAdditionalResources; llvmOptimizationLevel = aLlvmOptimizationLevel; + escapeAnalysisEnabled = aEscapeAnalysisEnabled; } public Logger getLogger() { @@ -109,4 +112,8 @@ public String[] getAdditionalResources() { public LLVMOptimizationLevel getLlvmOptimizationLevel() { return llvmOptimizationLevel; } + + public boolean isEscapeAnalysisEnabled() { + return escapeAnalysisEnabled; + } } diff --git a/core/src/main/java/de/mirkosertic/bytecoder/backend/llvm/LLVMCompilerBackend.java b/core/src/main/java/de/mirkosertic/bytecoder/backend/llvm/LLVMCompilerBackend.java index 3715a3bac5..6a0afc7bee 100644 --- a/core/src/main/java/de/mirkosertic/bytecoder/backend/llvm/LLVMCompilerBackend.java +++ b/core/src/main/java/de/mirkosertic/bytecoder/backend/llvm/LLVMCompilerBackend.java @@ -1634,7 +1634,7 @@ public EscapeAnalysis.ProgramDescriptor resolveDirectInvocation(final BytecodeOb pw.println(" {"); } - try (final LLVMWriter theWriter = new LLVMWriter(pw, memoryLayouter, aLinkerContext, theSymbolResolver)) { + try (final LLVMWriter theWriter = new LLVMWriter(pw, memoryLayouter, aLinkerContext, theSymbolResolver, aOptions.isEscapeAnalysisEnabled())) { theWriter.write(theLinkedClass, theSSAProgram, subProgram); } @@ -1781,7 +1781,7 @@ public EscapeAnalysis.ProgramDescriptor resolveDirectInvocation(final BytecodeOb subProgram.writeDebugSuffixTo(pw); pw.println(" {"); - try (final LLVMWriter theWriter = new LLVMWriter(pw, memoryLayouter, aLinkerContext, theSymbolResolver)) { + try (final LLVMWriter theWriter = new LLVMWriter(pw, memoryLayouter, aLinkerContext, theSymbolResolver, aOptions.isEscapeAnalysisEnabled())) { theWriter.write(theEntry.getValue().owningClass, theEntry.getValue().program, subProgram); } diff --git a/core/src/main/java/de/mirkosertic/bytecoder/backend/llvm/LLVMWriter.java b/core/src/main/java/de/mirkosertic/bytecoder/backend/llvm/LLVMWriter.java index 72bf630213..a1b1055a5d 100644 --- a/core/src/main/java/de/mirkosertic/bytecoder/backend/llvm/LLVMWriter.java +++ b/core/src/main/java/de/mirkosertic/bytecoder/backend/llvm/LLVMWriter.java @@ -159,12 +159,14 @@ interface SymbolResolver { private final NativeMemoryLayouter memoryLayouter; private final BytecodeLinkerContext linkerContext; private final SymbolResolver symbolResolver; + private final boolean escapeAnalysisEnabled; - public LLVMWriter(final PrintWriter output, final NativeMemoryLayouter memoryLayouter, final BytecodeLinkerContext linkerContext, final SymbolResolver symbolResolver) { + public LLVMWriter(final PrintWriter output, final NativeMemoryLayouter memoryLayouter, final BytecodeLinkerContext linkerContext, final SymbolResolver symbolResolver, final boolean aEscapeAnalysisEnabled) { this.target = output; this.memoryLayouter = memoryLayouter; this.linkerContext = linkerContext; this.symbolResolver = symbolResolver; + this.escapeAnalysisEnabled = aEscapeAnalysisEnabled; } @Override @@ -579,7 +581,7 @@ private void tempify(final NewObjectExpression e) { } private void tempify(final NewObjectAndConstructExpression e) { - if (!e.isEscaping()) { + if (!e.isEscaping() && escapeAnalysisEnabled) { // Perform stack allocation final String theClassName = LLVMWriterUtils.toClassName(e.getClazz()); target.print(" %"); @@ -661,7 +663,7 @@ private void tempify(final NewArrayExpression e) { target.print(LLVMWriter.VTABLESUFFIX); target.println(" to i32"); - if (!e.isEscaping()) { + if (!e.isEscaping() && escapeAnalysisEnabled) { // Perform stack allocation target.print(" %"); @@ -1263,7 +1265,17 @@ private void write(final ArrayStoreExpression e) { } private void write(final NewArrayExpression e) { - if (e.isEscaping()) { + if (!e.isEscaping() && escapeAnalysisEnabled) { + + linkerContext.getStatistics().context("Codegenerator") + .counter("ArrayOnStackAllocations").increment(); + + target.print("add i32 0, %"); + target.print(toTempSymbol(e, "alloc_int")); + + target.println(";; does not escape, please verify"); + + } else { linkerContext.getStatistics().context("Codegenerator") .counter("ArrayOnHeapAllocations").increment(); @@ -1282,16 +1294,6 @@ private void write(final NewArrayExpression e) { target.print(toTempSymbol(e, "vtable")); target.print(")"); currentSubProgram.writeDebugSuffixFor(e, target); - - } else { - - linkerContext.getStatistics().context("Codegenerator") - .counter("ArrayOnStackAllocations").increment(); - - target.print("add i32 0, %"); - target.print(toTempSymbol(e, "alloc_int")); - - target.println(";; does not escape, please verify"); } } @@ -2303,7 +2305,17 @@ private void write(final GetFieldExpression e) { private void write(final NewObjectAndConstructExpression e) { - if (e.isEscaping()) { + if (!e.isEscaping() && escapeAnalysisEnabled) { + + linkerContext.getStatistics().context("Codegenerator") + .counter("ObjectOnStackAllocations").increment(); + + target.print("add i32 0, %"); + target.print(toTempSymbol(e, "alloc_int")); + + target.println(";; does not escape, please verify"); + + } else { linkerContext.getStatistics().context("Codegenerator") .counter("ObjectOnHeapAllocations").increment(); @@ -2324,16 +2336,6 @@ private void write(final NewObjectAndConstructExpression e) { writeResolved(e.incomingDataFlows().get(i)); } target.println(")"); - - } else { - - linkerContext.getStatistics().context("Codegenerator") - .counter("ObjectOnStackAllocations").increment(); - - target.print("add i32 0, %"); - target.print(toTempSymbol(e, "alloc_int")); - - target.println(";; does not escape, please verify"); } } diff --git a/core/src/main/java/de/mirkosertic/bytecoder/backend/opencl/OpenCLContext.java b/core/src/main/java/de/mirkosertic/bytecoder/backend/opencl/OpenCLContext.java index 6e19b3aa10..fe8089aaa2 100644 --- a/core/src/main/java/de/mirkosertic/bytecoder/backend/opencl/OpenCLContext.java +++ b/core/src/main/java/de/mirkosertic/bytecoder/backend/opencl/OpenCLContext.java @@ -117,7 +117,7 @@ void updateFromBuffer() { cachedKernels = new HashMap<>(); backend = new OpenCLCompileBackend(); compileOptions = new CompileOptions(logger, false, KnownOptimizer.ALL, true, "opencl", 512, 512, false, aOptions.isPreferStackifier(), Allocator.linear, - new String[0], new String[0], null); + new String[0], new String[0], null, true); final cl_context_properties contextProperties = new cl_context_properties(); contextProperties.addProperty(CL_CONTEXT_PLATFORM, aPlatform.selectedPlatform.id); diff --git a/core/src/main/java/de/mirkosertic/bytecoder/unittest/BytecoderTestOption.java b/core/src/main/java/de/mirkosertic/bytecoder/unittest/BytecoderTestOption.java index 272e11d08a..62ea415c6d 100644 --- a/core/src/main/java/de/mirkosertic/bytecoder/unittest/BytecoderTestOption.java +++ b/core/src/main/java/de/mirkosertic/bytecoder/unittest/BytecoderTestOption.java @@ -33,4 +33,7 @@ boolean exceptionsEnabled() default false; boolean minify() default false; + + boolean escapeAnalysisEnabled() default false; + } diff --git a/core/src/main/java/de/mirkosertic/bytecoder/unittest/BytecoderUnitTestRunner.java b/core/src/main/java/de/mirkosertic/bytecoder/unittest/BytecoderUnitTestRunner.java index c3f47c9b1e..dce1d1cd97 100644 --- a/core/src/main/java/de/mirkosertic/bytecoder/unittest/BytecoderUnitTestRunner.java +++ b/core/src/main/java/de/mirkosertic/bytecoder/unittest/BytecoderUnitTestRunner.java @@ -86,31 +86,31 @@ public BytecoderUnitTestRunner(final Class aClass) throws InitializationError { final BytecoderTestOptions declaredOptions = getTestClass().getJavaClass().getAnnotation(BytecoderTestOptions.class); if (declaredOptions != null) { if (declaredOptions.includeJVM()) { - testOptions.add(new TestOption(null, false, false, false)); + testOptions.add(new TestOption(null, false, false, false, false)); } if (declaredOptions.value().length == 0 && declaredOptions.includeTestPermutations()) { - testOptions.add(new TestOption(CompileTarget.BackendType.js, false, false, false)); - testOptions.add(new TestOption(CompileTarget.BackendType.js, false, false, true)); - testOptions.add(new TestOption(CompileTarget.BackendType.js, true, false, false)); - testOptions.add(new TestOption(CompileTarget.BackendType.wasm, false, false, false)); - testOptions.add(new TestOption(CompileTarget.BackendType.wasm, true, false, false)); - testOptions.add(new TestOption(CompileTarget.BackendType.wasm_llvm, false, false, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.js, false, false, false, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.js, false, false, true, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.js, true, false, false, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.wasm, false, false, false, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.wasm, true, false, false, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.wasm_llvm, false, false, false, false)); } else { for (final BytecoderTestOption o : declaredOptions.value()) { - testOptions.add(new TestOption(o.backend(), o.preferStackifier(), o.exceptionsEnabled(), o.minify())); + testOptions.add(new TestOption(o.backend(), o.preferStackifier(), o.exceptionsEnabled(), o.minify(), o. escapeAnalysisEnabled())); } } additionalClassesToLink = declaredOptions.additionalClassesToLink(); additionalResources = declaredOptions.additionalResources(); } else { - testOptions.add(new TestOption(null, false, false, false)); - testOptions.add(new TestOption(CompileTarget.BackendType.js, false, false, false)); - testOptions.add(new TestOption(CompileTarget.BackendType.js, false, false, true)); - testOptions.add(new TestOption(CompileTarget.BackendType.js, true, false, false)); - testOptions.add(new TestOption(CompileTarget.BackendType.wasm, false, false, false)); - testOptions.add(new TestOption(CompileTarget.BackendType.wasm, true, false, false)); - testOptions.add(new TestOption(CompileTarget.BackendType.wasm_llvm, false, false, false)); + testOptions.add(new TestOption(null, false, false, false, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.js, false, false, false, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.js, false, false, true, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.js, true, false, false, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.wasm, false, false, false, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.wasm, true, false, false, false)); + testOptions.add(new TestOption(CompileTarget.BackendType.wasm_llvm, false, false, false, false)); additionalClassesToLink = new String[0]; additionalResources = new String[0]; @@ -275,7 +275,7 @@ private void testJSBackendFrameworkMethod(final FrameworkMethod aFrameworkMethod final StringWriter theStrWriter = new StringWriter(); final PrintWriter theCodeWriter = new PrintWriter(theStrWriter); - final CompileOptions theOptions = new CompileOptions(LOGGER, true, KnownOptimizer.ALL, aTestOption.isExceptionsEnabled(), "bytecoder", 512, 512, aTestOption.isMinify(), aTestOption.isPreferStackifier(), Allocator.linear, additionalClassesToLink, additionalResources, null); + final CompileOptions theOptions = new CompileOptions(LOGGER, true, KnownOptimizer.ALL, aTestOption.isExceptionsEnabled(), "bytecoder", 512, 512, aTestOption.isMinify(), aTestOption.isPreferStackifier(), Allocator.linear, additionalClassesToLink, additionalResources, null, aTestOption.isEscapeAnalysisEnabled()); final JSCompileResult result = (JSCompileResult) theCompileTarget.compile(theOptions, testClass.getJavaClass(), aFrameworkMethod.getName(), theSignature); final CompileResult.StringContent content = (CompileResult.StringContent) result.getContent()[0]; @@ -374,7 +374,7 @@ private void testWASMASTBackendFrameworkMethod(final FrameworkMethod aFrameworkM final BytecodeMethodSignature theSignature = theCompileTarget.toMethodSignature(aFrameworkMethod.getMethod()); final BytecodeObjectTypeRef theTestClassType = new BytecodeObjectTypeRef(testClass.getName()); - final CompileOptions theOptions = new CompileOptions(LOGGER, true, KnownOptimizer.ALL, false, "bytecoder", 512, 512, aTestOption.isMinify(), aTestOption.isPreferStackifier(), Allocator.linear, additionalClassesToLink, additionalResources, null); + final CompileOptions theOptions = new CompileOptions(LOGGER, true, KnownOptimizer.ALL, false, "bytecoder", 512, 512, aTestOption.isMinify(), aTestOption.isPreferStackifier(), Allocator.linear, additionalClassesToLink, additionalResources, null, aTestOption.isEscapeAnalysisEnabled()); final WASMCompileResult theResult = (WASMCompileResult) theCompileTarget.compile(theOptions, testClass.getJavaClass(), aFrameworkMethod.getName(), theSignature); final WASMCompileResult.WASMCompileContent textualContent = (WASMCompileResult.WASMCompileContent) theResult.getContent()[0]; final WASMCompileResult.WASMCompileContent binaryContent = (WASMCompileResult.WASMCompileContent)theResult.getContent()[1]; @@ -557,7 +557,7 @@ private void testLLVMWASMASTBackendFrameworkMethod(final FrameworkMethod aFramew final BytecodeMethodSignature theSignature = theCompileTarget.toMethodSignature(aFrameworkMethod.getMethod()); final BytecodeObjectTypeRef theTypeRef = new BytecodeObjectTypeRef(testClass.getName()); - final CompileOptions theOptions = new CompileOptions(LOGGER, true, KnownOptimizer.ALL, false, "bytecoder", 512, 512, aTestOption.isMinify(), aTestOption.isPreferStackifier(), Allocator.linear, additionalClassesToLink, additionalResources, LLVMOptimizationLevel.defaultValue()); + final CompileOptions theOptions = new CompileOptions(LOGGER, true, KnownOptimizer.ALL, false, "bytecoder", 512, 512, aTestOption.isMinify(), aTestOption.isPreferStackifier(), Allocator.linear, additionalClassesToLink, additionalResources, LLVMOptimizationLevel.defaultValue(), aTestOption.isEscapeAnalysisEnabled()); final LLVMCompileResult theResult = (LLVMCompileResult) theCompileTarget.compile(theOptions, testClass.getJavaClass(), aFrameworkMethod.getName(), theSignature); final CompileResult.StringContent textualContent = (CompileResult.StringContent) theResult.getContent()[0]; final CompileResult.StringContent jsContent = (CompileResult.StringContent)theResult.getContent()[1]; diff --git a/core/src/main/java/de/mirkosertic/bytecoder/unittest/TestOption.java b/core/src/main/java/de/mirkosertic/bytecoder/unittest/TestOption.java index 416c2f7b58..cfa8def317 100644 --- a/core/src/main/java/de/mirkosertic/bytecoder/unittest/TestOption.java +++ b/core/src/main/java/de/mirkosertic/bytecoder/unittest/TestOption.java @@ -23,12 +23,14 @@ public class TestOption { private final boolean preferStackifier; private final boolean exceptionsEnabled; private final boolean minify; + private final boolean escapeAnalysisEnabled; - public TestOption(final CompileTarget.BackendType backendType, final boolean preferStackifier, final boolean exceptionsEnabled, final boolean minify) { + public TestOption(final CompileTarget.BackendType backendType, final boolean preferStackifier, final boolean exceptionsEnabled, final boolean minify, final boolean escapeAnalysisEnabled) { this.backendType = backendType; this.preferStackifier = preferStackifier; this.exceptionsEnabled = exceptionsEnabled; this.minify = minify; + this.escapeAnalysisEnabled = escapeAnalysisEnabled; } public String toDescription() { @@ -72,4 +74,8 @@ public boolean isExceptionsEnabled() { public boolean isMinify() { return minify; } + + public boolean isEscapeAnalysisEnabled() { + return escapeAnalysisEnabled; + } } diff --git a/core/src/test/java/de/mirkosertic/bytecoder/allocator/LinearRegisterAllocatorTest.java b/core/src/test/java/de/mirkosertic/bytecoder/allocator/LinearRegisterAllocatorTest.java index d01dbbd56b..8ef76ea551 100644 --- a/core/src/test/java/de/mirkosertic/bytecoder/allocator/LinearRegisterAllocatorTest.java +++ b/core/src/test/java/de/mirkosertic/bytecoder/allocator/LinearRegisterAllocatorTest.java @@ -129,7 +129,7 @@ public void testStringArrayInitRegisterAllocation() throws HeadToHeadControlFlow assertEquals(8, theAllocator.assignedRegister().size()); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); diff --git a/core/src/test/java/de/mirkosertic/bytecoder/allocator/PassThruRegisterAllocatorTest.java b/core/src/test/java/de/mirkosertic/bytecoder/allocator/PassThruRegisterAllocatorTest.java index 28e98ac204..1f5817d93b 100644 --- a/core/src/test/java/de/mirkosertic/bytecoder/allocator/PassThruRegisterAllocatorTest.java +++ b/core/src/test/java/de/mirkosertic/bytecoder/allocator/PassThruRegisterAllocatorTest.java @@ -166,7 +166,7 @@ public void testComplexPhiFlowRegisterAllocation() throws HeadToHeadControlFlowE final AbstractAllocator theAllocator = Allocator.passthru.allocate(p, Variable::resolveType, theLinkerContext); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); @@ -210,7 +210,7 @@ public void testSimplePhiFlowRegisterAllocation() throws HeadToHeadControlFlowEx assertEquals(11, theAllocator.assignedRegister().size()); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); @@ -269,7 +269,7 @@ public void testStandardCharsetsForNameRegisterAllocation() throws HeadToHeadCon assertEquals(72, theAllocator.assignedRegister().size()); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); @@ -306,7 +306,7 @@ public void testStringArrayInitRegisterAllocation() throws HeadToHeadControlFlow assertEquals(8, theAllocator.assignedRegister().size()); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); @@ -343,7 +343,7 @@ public void testCharsetInitRegisterAllocation() throws HeadToHeadControlFlowExce assertEquals(28, theAllocator.assignedRegister().size()); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); @@ -380,7 +380,7 @@ public void testCharsetEncoderRegisterAllocation() throws HeadToHeadControlFlowE assertEquals(50, theAllocator.assignedRegister().size()); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); @@ -418,7 +418,7 @@ public void testHashMapGetNodeRegisterAllocator() throws HeadToHeadControlFlowEx assertEquals(47, theAllocator.assignedRegister().size()); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); @@ -478,7 +478,7 @@ public void testFreeMemRegisterAllocator() throws HeadToHeadControlFlowException assertEquals(20, theAllocator.assignedRegister().size()); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); @@ -515,7 +515,7 @@ public void testMapEntryRegisterAllocator() throws HeadToHeadControlFlowExceptio assertEquals(3, theAllocator.assignedRegister().size()); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); @@ -554,7 +554,7 @@ public void testImageIconGetNext() throws HeadToHeadControlFlowException { assertEquals(6, theAllocator.assignedRegister().size()); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), true, KnownOptimizer.NONE, false, "ks", 100, 100, false, true, Allocator.passthru, new String[0], new String[0], null, false); final JSMinifier theMinifier = new JSMinifier(theOptions); final SourceMapWriter theSourcemapWriter = new SourceMapWriter(); final StringWriter theWriter = new StringWriter(); diff --git a/core/src/test/java/de/mirkosertic/bytecoder/api/opencl/CompilerTest.java b/core/src/test/java/de/mirkosertic/bytecoder/api/opencl/CompilerTest.java index 7b5e0be79a..441f473493 100644 --- a/core/src/test/java/de/mirkosertic/bytecoder/api/opencl/CompilerTest.java +++ b/core/src/test/java/de/mirkosertic/bytecoder/api/opencl/CompilerTest.java @@ -79,7 +79,7 @@ private Kernel createKernel() { public void testSimpleKernel() throws IOException { final OpenCLCompileBackend backend = new OpenCLCompileBackend(); - final CompileOptions compileOptions = new CompileOptions(new Slf4JLogger(), false, KnownOptimizer.ALL, true, "opencl", 512, 512, false, false, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions compileOptions = new CompileOptions(new Slf4JLogger(), false, KnownOptimizer.ALL, true, "opencl", 512, 512, false, false, Allocator.passthru, new String[0], new String[0], null, false); final Kernel theKernel = createKernel(); final Class theKernelClass = theKernel.getClass(); @@ -106,7 +106,7 @@ public void testSimpleKernel() throws IOException { public void testKernelWithComplexType() throws IOException { final OpenCLCompileBackend backend = new OpenCLCompileBackend(); - final CompileOptions compileOptions = new CompileOptions(new Slf4JLogger(), false, KnownOptimizer.ALL, true, "opencl", 512, 512, false, false, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions compileOptions = new CompileOptions(new Slf4JLogger(), false, KnownOptimizer.ALL, true, "opencl", 512, 512, false, false, Allocator.passthru, new String[0], new String[0], null, false); final Float2[] theIn = new Float2[10]; final Float2[] theOut = new Float2[10]; diff --git a/core/src/test/java/de/mirkosertic/bytecoder/complex/Profiler.java b/core/src/test/java/de/mirkosertic/bytecoder/complex/Profiler.java index f7cecb3a12..0017804985 100644 --- a/core/src/test/java/de/mirkosertic/bytecoder/complex/Profiler.java +++ b/core/src/test/java/de/mirkosertic/bytecoder/complex/Profiler.java @@ -27,7 +27,7 @@ public static void main(final String[] args) throws NoSuchMethodException { final BytecodeMethodSignature theSignature = theCompileTarget.toMethodSignature(theMethodToTest); - final CompileOptions theOptions = new CompileOptions(LOGGER, true, KnownOptimizer.ALL, true, "bytecoder", 512, 512, false, false, Allocator.passthru, new String[0], new String[0], null); + final CompileOptions theOptions = new CompileOptions(LOGGER, true, KnownOptimizer.ALL, true, "bytecoder", 512, 512, false, false, Allocator.passthru, new String[0], new String[0], null, false); final JSCompileResult result = (JSCompileResult) theCompileTarget .compile(theOptions, theClassToTest, theMethodToTest.getName(), theSignature); final CompileResult.StringContent content = (CompileResult.StringContent) result.getContent()[0]; diff --git a/maven/src/main/java/de/mirkosertic/bytecoder/maven/BytecoderMavenMojo.java b/maven/src/main/java/de/mirkosertic/bytecoder/maven/BytecoderMavenMojo.java index c62d60157f..144268fa2c 100644 --- a/maven/src/main/java/de/mirkosertic/bytecoder/maven/BytecoderMavenMojo.java +++ b/maven/src/main/java/de/mirkosertic/bytecoder/maven/BytecoderMavenMojo.java @@ -146,6 +146,12 @@ public class BytecoderMavenMojo extends AbstractMojo { */ protected String llvmOptimizationLevel = LLVMOptimizationLevel.defaultValue().name(); + /** + * Shall the escape analysis be enabled? Defaults to 'false'. + */ + @Parameter(required = false, defaultValue = "false") + protected boolean escapeAnalysisEnabled = false; + @Override public void execute() throws MojoExecutionException { final File theBaseDirectory = new File(buildDirectory); @@ -161,7 +167,7 @@ public void execute() throws MojoExecutionException { final BytecodeMethodSignature theSignature = new BytecodeMethodSignature(BytecodePrimitiveTypeRef.VOID, new BytecodeTypeRef[] { new BytecodeArrayTypeRef(BytecodeObjectTypeRef.fromRuntimeClass(String.class), 1) }); - final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), debugOutput, KnownOptimizer.valueOf(optimizationLevel), enableExceptionHandling, filenamePrefix, wasmInitialPages, wasmMaximumPages, minifyCompileResult, preferStackifier, Allocator.valueOf(registerAllocator), additionalClassesToLink, additionalResources, LLVMOptimizationLevel.valueOf(llvmOptimizationLevel)); + final CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), debugOutput, KnownOptimizer.valueOf(optimizationLevel), enableExceptionHandling, filenamePrefix, wasmInitialPages, wasmMaximumPages, minifyCompileResult, preferStackifier, Allocator.valueOf(registerAllocator), additionalClassesToLink, additionalResources, LLVMOptimizationLevel.valueOf(llvmOptimizationLevel), escapeAnalysisEnabled); final CompileResult theCode = theCompileTarget.compile(theOptions, theTargetClass, "main", theSignature); for (final CompileResult.Content content : theCode.getContent()) { final File theBytecoderFileName = new File(theBytecoderDirectory, content.getFileName());