From ddd73cb641905604b361c107c278affcc7810718 Mon Sep 17 00:00:00 2001 From: jnthn Date: Thu, 18 Apr 2013 13:10:36 +0200 Subject: [PATCH] Fix HLL types seperate compilation leaks. --- lib/QAST/JASTCompiler.nqp | 2 ++ nqp-src/ModuleLoader.pm | 10 ++++++ nqp-src/NQP.pm | 1 + src/org/perl6/nqp/runtime/GlobalContext.java | 32 ++++++++++++++++++-- src/org/perl6/nqp/runtime/Ops.java | 8 +++++ 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/lib/QAST/JASTCompiler.nqp b/lib/QAST/JASTCompiler.nqp index d85d60f..b108a3c 100644 --- a/lib/QAST/JASTCompiler.nqp +++ b/lib/QAST/JASTCompiler.nqp @@ -1893,6 +1893,8 @@ QAST::OperationsJAST.map_classlib_core_op('getcurhllsym', $TYPE_OPS, 'getcurhlls QAST::OperationsJAST.map_classlib_core_op('bindcurhllsym', $TYPE_OPS, 'bindcurhllsym', [$RT_STR, $RT_OBJ], $RT_OBJ, :tc); QAST::OperationsJAST.map_classlib_core_op('sethllconfig', $TYPE_OPS, 'sethllconfig', [$RT_STR, $RT_OBJ], $RT_OBJ, :tc); QAST::OperationsJAST.map_classlib_core_op('loadbytecode', $TYPE_OPS, 'loadbytecode', [$RT_STR], $RT_STR, :tc); +QAST::OperationsJAST.map_classlib_core_op('usecompilerhllconfig', $TYPE_OPS, 'usecompilerhllconfig', [], $RT_INT, :tc); +QAST::OperationsJAST.map_classlib_core_op('usecompileehllconfig', $TYPE_OPS, 'usecompileehllconfig', [], $RT_INT, :tc); # regex engine related opcodes QAST::OperationsJAST.map_classlib_core_op('nfafromstatelist', $TYPE_OPS, 'nfafromstatelist', [$RT_OBJ, $RT_OBJ], $RT_OBJ, :tc); diff --git a/nqp-src/ModuleLoader.pm b/nqp-src/ModuleLoader.pm index 2a5834b..1d686c1 100644 --- a/nqp-src/ModuleLoader.pm +++ b/nqp-src/ModuleLoader.pm @@ -49,8 +49,13 @@ knowhow ModuleLoader { else { my $*CTXSAVE := self; my $*MAIN_CTX := ModuleLoader; + my $boot_mode; + try { my $hack; $boot_mode := %*COMPILING<%?OPTIONS>; } + $boot_mode := !nqp::isnull($boot_mode) && $boot_mode; my $preserve_global := nqp::getcurhllsym('GLOBAL'); + __JVM__usecompileehllconfig() if $boot_mode; nqp::loadbytecode($path); + __JVM__usecompilerhllconfig() if $boot_mode; nqp::bindcurhllsym('GLOBAL', $preserve_global); %modules_loaded{$path} := $module_ctx := $*MAIN_CTX; } @@ -146,8 +151,13 @@ knowhow ModuleLoader { unless nqp::existskey(%settings_loaded, $path) { my $*CTXSAVE := self; my $*MAIN_CTX := ModuleLoader; + my $boot_mode; + try { my $hack; $boot_mode := %*COMPILING<%?OPTIONS>; } + $boot_mode := !nqp::isnull($boot_mode) && $boot_mode; my $preserve_global := nqp::getcurhllsym('GLOBAL'); + __JVM__usecompileehllconfig() if $boot_mode; nqp::loadbytecode($path); + __JVM__usecompilerhllconfig() if $boot_mode; nqp::bindcurhllsym('GLOBAL', $preserve_global); unless nqp::defined($*MAIN_CTX) { nqp::die("Unable to load setting $setting_name; maybe it is missing a YOU_ARE_HERE?"); diff --git a/nqp-src/NQP.pm b/nqp-src/NQP.pm index b29c685..65c9192 100644 --- a/nqp-src/NQP.pm +++ b/nqp-src/NQP.pm @@ -3436,6 +3436,7 @@ my @clo := $nqpcomp.commandline_options(); @clo.push('dynext=s'); @clo.push('stable-sc'); @clo.push('javaclass=s'); +@clo.push('bootstrap'); sub MAIN(*@ARGS) { # Enter the compiler. diff --git a/src/org/perl6/nqp/runtime/GlobalContext.java b/src/org/perl6/nqp/runtime/GlobalContext.java index 84f0fe0..428bc63 100644 --- a/src/org/perl6/nqp/runtime/GlobalContext.java +++ b/src/org/perl6/nqp/runtime/GlobalContext.java @@ -96,10 +96,21 @@ public class GlobalContext { public ThreadContext mainThread; /** - * HLL configuration (maps HLL name to the configuration). + * Active HLL configuration (maps HLL name to the configuration). */ private HashMap hllConfiguration; + /** + * HLL configuration of the compiler. We need to distinguish it from + * the HLL configuration of the code being compiled in bootstrap. + */ + private HashMap compilerHLLConfiguration; + + /** + * HLL configuration of the compilee (see above). + */ + private HashMap compileeHLLConfiguration; + /** * HLL global symbols. */ @@ -125,7 +136,13 @@ public class GlobalContext { */ public GlobalContext() { - hllConfiguration = new HashMap(); + compileeHLLConfiguration = new HashMap(); + hllConfiguration = compileeHLLConfiguration; + getHLLConfigFor(""); + compilerHLLConfiguration = new HashMap(); + hllConfiguration = compilerHLLConfiguration; + getHLLConfigFor(""); + scs = new HashMap(); scRefs = new HashMap(); compilerRegistry = new HashMap(); @@ -135,7 +152,8 @@ public GlobalContext() KnowHOWBootstrapper.bootstrap(mainThread); // BOOT* not available earlier; fixup some stuff. - setupConfig(hllConfiguration.get("")); + setupConfig(compileeHLLConfiguration.get("")); + setupConfig(compilerHLLConfiguration.get("")); mainThread.savedCC = (CallCaptureInstance)CallCapture.st.REPR.allocate(mainThread, CallCapture.st); mainThread.savedCC.initialize(mainThread); } @@ -168,4 +186,12 @@ private void setupConfig(HLLConfig config) { config.exceptionType = BOOTException; config.ioType = BOOTIO; } + + public void useCompileeHLLConfig() { + this.hllConfiguration = this.compileeHLLConfiguration; + } + + public void useCompilerHLLConfig() { + this.hllConfiguration = this.compilerHLLConfiguration; + } } diff --git a/src/org/perl6/nqp/runtime/Ops.java b/src/org/perl6/nqp/runtime/Ops.java index 63b6ccd..ed60645 100644 --- a/src/org/perl6/nqp/runtime/Ops.java +++ b/src/org/perl6/nqp/runtime/Ops.java @@ -3399,4 +3399,12 @@ public static SixModelObject jvmclasspaths(ThreadContext tc) { result.push_boxed(tc, box_s(cps[i], Str, tc)); return result; } + public static long usecompileehllconfig(ThreadContext tc) { + tc.gc.useCompileeHLLConfig(); + return 1; + } + public static long usecompilerhllconfig(ThreadContext tc) { + tc.gc.useCompilerHLLConfig(); + return 1; + } }