Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix race/timing issue in JVM classname generation.
If the time between two evals was too short, we could end up re-using
a class name, thus upsetting the class loader.
  • Loading branch information
jnthn committed Apr 4, 2015
1 parent 1c6c916 commit 314a1cd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/vm/jvm/HLL/Backend.nqp
Expand Up @@ -2,7 +2,8 @@
use JASTNodes;

class HLL::Backend::JVM {
our %jvm_config := nqp::backendconfig();
our %jvm_config := nqp::backendconfig();
my $compile_count := 0;

method apply_transcodings($s, $transcode) {
$s
Expand Down Expand Up @@ -53,13 +54,13 @@ class HLL::Backend::JVM {

method classname($source, *%adverbs) {
unless %*COMPILING<%?OPTIONS><javaclass> {
%*COMPILING<%?OPTIONS><javaclass> := nqp::sha1(nqp::sha1($source) ~ nqp::time_n());
%*COMPILING<%?OPTIONS><javaclass> := nqp::sha1(nqp::sha1($source) ~ nqp::time_n() ~ $compile_count++);
}
$source
}

method jast($qast, *%adverbs) {
my $classname := %*COMPILING<%?OPTIONS><javaclass> || nqp::sha1('eval-at-' ~ nqp::time_n());
my $classname := %*COMPILING<%?OPTIONS><javaclass> || nqp::sha1('eval-at-' ~ nqp::time_n() ~ $compile_count++);
nqp::getcomp('QAST').jast($qast, :$classname);
}

Expand Down

0 comments on commit 314a1cd

Please sign in to comment.