Navigation Menu

Skip to content

Commit

Permalink
Fix HLL types seperate compilation leaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Apr 18, 2013
1 parent d8d3f2f commit ddd73cb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions nqp-src/ModuleLoader.pm
Expand Up @@ -49,8 +49,13 @@ knowhow ModuleLoader {
else {
my $*CTXSAVE := self;
my $*MAIN_CTX := ModuleLoader;
my $boot_mode;
try { my $hack; $boot_mode := %*COMPILING<%?OPTIONS><bootstrap>; }
$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;
}
Expand Down Expand Up @@ -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><bootstrap>; }
$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?");
Expand Down
1 change: 1 addition & 0 deletions nqp-src/NQP.pm
Expand Up @@ -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.
Expand Down
32 changes: 29 additions & 3 deletions src/org/perl6/nqp/runtime/GlobalContext.java
Expand Up @@ -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<String, HLLConfig> hllConfiguration;

/**
* HLL configuration of the compiler. We need to distinguish it from
* the HLL configuration of the code being compiled in bootstrap.
*/
private HashMap<String, HLLConfig> compilerHLLConfiguration;

/**
* HLL configuration of the compilee (see above).
*/
private HashMap<String, HLLConfig> compileeHLLConfiguration;

/**
* HLL global symbols.
*/
Expand All @@ -125,7 +136,13 @@ public class GlobalContext {
*/
public GlobalContext()
{
hllConfiguration = new HashMap<String, HLLConfig>();
compileeHLLConfiguration = new HashMap<String, HLLConfig>();
hllConfiguration = compileeHLLConfiguration;
getHLLConfigFor("");
compilerHLLConfiguration = new HashMap<String, HLLConfig>();
hllConfiguration = compilerHLLConfiguration;
getHLLConfigFor("");

scs = new HashMap<String, SerializationContext>();
scRefs = new HashMap<String, SixModelObject>();
compilerRegistry = new HashMap<String, SixModelObject>();
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
}
8 changes: 8 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -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;
}
}

0 comments on commit ddd73cb

Please sign in to comment.