Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use qbindex instead of cuid for finding sub outers
We're no longer looking up cuids for any reason outside stage0, and we're
no longer using them at all outside of a single dynamic-compilation case
in NQP::World and Perl6::World.  So don't even bother emitting them when
precompiling.
  • Loading branch information
sorear committed Jun 21, 2013
1 parent cda5cc2 commit eba21ca
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 44 deletions.
14 changes: 8 additions & 6 deletions src/vm/jvm/QAST/Compiler.nqp
Expand Up @@ -2819,8 +2819,8 @@ class QAST::CompilerJAST {
my %*CUID_TO_QBID;
my $*NEXT_QBID := 0;
# Pre-seed to make sure that qbids correspond to serialization IDs
my $comp_mode := $cu.compilation_mode;
if $comp_mode {
my $*COMP_MODE := $cu.compilation_mode;
if $*COMP_MODE {
for $cu.code_ref_blocks() -> $qblock {
%*CUID_TO_QBID{$qblock.cuid} := $*NEXT_QBID++;
}
Expand All @@ -2845,7 +2845,7 @@ class QAST::CompilerJAST {
QAST::Op.new( :op('setup_blv'), %*BLOCK_LEX_VALUES )
));
}
if $comp_mode || @pre_des || @post_des {
if $*COMP_MODE || @pre_des || @post_des {
# Create a block into which we'll install all of the other
# pieces.
my $block := QAST::Block.new( :blocktype('raw') );
Expand All @@ -2856,7 +2856,7 @@ class QAST::CompilerJAST {
}

# If we need to do deserialization, emit code for that.
if $comp_mode {
if $*COMP_MODE {
$block.push(self.deserialization_code($cu.sc(), $cu.code_ref_blocks(),
$cu.repo_conflict_resolver()));
}
Expand Down Expand Up @@ -3042,12 +3042,14 @@ class QAST::CompilerJAST {
# are handled out of band).
my $*JMETH := JAST::Method.new( :name('qb_'~self.cuid_to_qbid($node.cuid)), :returns('Void'), :static(1) );
$*JMETH.cr_name($node.name);
$*JMETH.cr_cuid($node.cuid);
$*JMETH.cr_cuid($node.cuid) unless $*COMP_MODE;
$*CODEREFS.register_method($*JMETH, $node.cuid);

# Set outer if we have one.
if nqp::istype($outer, BlockInfo) {
$*JMETH.cr_outer($outer.qast.cuid);
$*JMETH.cr_outer(self.cuid_to_qbid($outer.qast.cuid));
} else {
$*JMETH.cr_outer(-1); # marks as coderef
}

# Always take ThreadContext and callsite descriptor as arguments.
Expand Down
6 changes: 3 additions & 3 deletions src/vm/jvm/QAST/JASTNodes.nqp
Expand Up @@ -104,7 +104,7 @@ class JAST::Method is JAST::Node {
has @!instructions;
has str $!cr_name;
has str $!cr_cuid;
has str $!cr_outer;
has int $!cr_outer; # -1 = has no outer -2 = not a coderef
has @!cr_olex;
has @!cr_ilex;
has @!cr_nlex;
Expand All @@ -120,7 +120,7 @@ class JAST::Method is JAST::Node {
@!instructions := [];
$!cr_name := '';
$!cr_cuid := '';
$!cr_outer := '';
$!cr_outer := -2;
@!cr_olex := [];
@!cr_ilex := [];
@!cr_nlex := [];
Expand Down Expand Up @@ -172,7 +172,7 @@ class JAST::Method is JAST::Node {
}
nqp::push(@dumped, "++ crname $!cr_name");
nqp::push(@dumped, "++ crcuid $!cr_cuid");
nqp::push(@dumped, "++ crouter $!cr_outer");
nqp::push(@dumped, "++ crouterix $!cr_outer");
for @!cr_olex { nqp::push(@dumped, "++ olex $_"); }
for @!cr_ilex { nqp::push(@dumped, "++ ilex $_"); }
for @!cr_nlex { nqp::push(@dumped, "++ nlex $_"); }
Expand Down
58 changes: 35 additions & 23 deletions src/vm/jvm/runtime/org/perl6/nqp/jast2bc/JASTToJVMBytecode.java
Expand Up @@ -149,6 +149,7 @@ private static class LabelInfo {
private static boolean processMethod(BufferedReader in, ClassWriter c, String className) throws Exception {
String curLine, methodName = null, returnType = null, desc = null;
String crName = null, crCuid = null, crOuter = null;
int crOuterIx = -2; // not coderef
boolean isStatic = false;
List<Type> argTypes = new ArrayList<Type>();
Map<String, VariableDef> localVariables = new HashMap<String, VariableDef>();
Expand Down Expand Up @@ -203,8 +204,10 @@ else if (curLine.startsWith("++ crname "))
crName = curLine.substring("++ crname ".length());
else if (curLine.startsWith("++ crcuid "))
crCuid = curLine.substring("++ crcuid ".length());
else if (curLine.startsWith("++ crouter "))
else if (curLine.startsWith("++ crouter ")) /*FOR_STAGE0*/
crOuter = curLine.substring("++ crouter ".length());
else if (curLine.startsWith("++ crouterix "))
crOuterIx = Integer.parseInt(curLine.substring("++ crouterix ".length()));
else if (curLine.startsWith("++ olex "))
croLex.add(curLine.substring("++ olex ".length()));
else if (curLine.startsWith("++ ilex "))
Expand Down Expand Up @@ -245,32 +248,41 @@ else if (curLine.startsWith("++ handlers ")) {
methodName, desc, null, null);

// Add code ref info annotation.
if (crCuid != null && !crCuid.equals("")) {
if ((crCuid != null && !crCuid.equals("")) || crOuterIx >= -1) {
Type crAnnType = Type.getType("Lorg/perl6/nqp/runtime/CodeRefAnnotation;");
AnnotationVisitor av = m.visitAnnotation(crAnnType.getDescriptor(), true);
av.visit("name", crName);
av.visit("cuid", crCuid);
av.visit("outerCuid", crOuter);

if (crCuid != null && !crCuid.isEmpty()) av.visit("cuid", crCuid);
if (crOuter != null && !crOuter.isEmpty()) av.visit("outerCuid", crOuter);
if (crOuterIx >= 0) av.visit("outerQbid", crOuterIx);

AnnotationVisitor avLex;
avLex = av.visitArray("oLexicalNames");
for (int i = 0; i < croLex.size(); i++)
avLex.visit(null, croLex.get(i));
avLex.visitEnd();
avLex = av.visitArray("iLexicalNames");
for (int i = 0; i < criLex.size(); i++)
avLex.visit(null, criLex.get(i));
avLex.visitEnd();
avLex = av.visitArray("nLexicalNames");
for (int i = 0; i < crnLex.size(); i++)
avLex.visit(null, crnLex.get(i));
avLex.visitEnd();
avLex = av.visitArray("sLexicalNames");
for (int i = 0; i < crsLex.size(); i++)
avLex.visit(null, crsLex.get(i));
avLex.visitEnd();

av.visit("handlers", crHandlers);
if (croLex.size() > 0) {
avLex = av.visitArray("oLexicalNames");
for (int i = 0; i < croLex.size(); i++)
avLex.visit(null, croLex.get(i));
avLex.visitEnd();
}
if (criLex.size() > 0) {
avLex = av.visitArray("iLexicalNames");
for (int i = 0; i < criLex.size(); i++)
avLex.visit(null, criLex.get(i));
avLex.visitEnd();
}
if (crnLex.size() > 0) {
avLex = av.visitArray("nLexicalNames");
for (int i = 0; i < crnLex.size(); i++)
avLex.visit(null, crnLex.get(i));
avLex.visitEnd();
}
if (crsLex.size() > 0) {
avLex = av.visitArray("sLexicalNames");
for (int i = 0; i < crsLex.size(); i++)
avLex.visit(null, crsLex.get(i));
avLex.visitEnd();
}

if (crHandlers.length != 1 || crHandlers[0] != 0) av.visit("handlers", crHandlers);
av.visitEnd();
}

Expand Down
17 changes: 9 additions & 8 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/CodeRefAnnotation.java
Expand Up @@ -6,12 +6,13 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface CodeRefAnnotation
{
String name();
String cuid();
String outerCuid();
String[] oLexicalNames();
String[] iLexicalNames();
String[] nLexicalNames();
String[] sLexicalNames();
long[] handlers();
String name() default "";
String cuid() default "";
String outerCuid() default "";
int outerQbid() default -1;
String[] oLexicalNames() default {};
String[] iLexicalNames() default {};
String[] nLexicalNames() default {};
String[] sLexicalNames() default {};
long[] handlers() default {0};
}
13 changes: 9 additions & 4 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/CompilationUnit.java
Expand Up @@ -84,7 +84,7 @@ public void initializeCompilationUnit(ThreadContext tc) {
/* Look through methods for code refs. */
STable BOOTCodeSTable = tc.gc.BOOTCode == null ? null : tc.gc.BOOTCode.st;
ArrayList<CodeRef> codeRefList = new ArrayList<CodeRef>();
ArrayList<String> outerCuid = new ArrayList<String>();
ArrayList<CodeRefAnnotation> outerCuid = new ArrayList< >();
Lookup l = MethodHandles.lookup();
boolean codeRefsFound = false;
try {
Expand Down Expand Up @@ -119,7 +119,7 @@ public void initializeCompilationUnit(ThreadContext tc) {
cr.staticInfo.methodName = name;
cr.st = BOOTCodeSTable;
codeRefList.add(cr);
cuidToCodeRef.put(cuid, cr);
if (!cuid.isEmpty()) cuidToCodeRef.put(cuid, cr);

if (name.startsWith("qb_")) {
int i = 3;
Expand All @@ -130,7 +130,7 @@ public void initializeCompilationUnit(ThreadContext tc) {
}

/* Stash outer, for later resolution. */
outerCuid.add(cra.outerCuid());
outerCuid.add(cra);

codeRefsFound = true;
}
Expand All @@ -139,7 +139,12 @@ public void initializeCompilationUnit(ThreadContext tc) {
/* Resolve outers. */
codeRefs = codeRefList.toArray(new CodeRef[0]);
for (int i = 0; i < codeRefs.length; i++) {
CodeRef outer = cuidToCodeRef.get(outerCuid.get(i));
CodeRefAnnotation cra = outerCuid.get(i);
String cuid = cra.outerCuid();
int qbid = cra.outerQbid();

CodeRef outer = qbid >= 0 ? qbidToCodeRef[qbid] :
cuid != null ? cuidToCodeRef.get(cuid) : null;
if (outer != null)
codeRefs[i].staticInfo.outerStaticInfo = outer.staticInfo;
}
Expand Down

0 comments on commit eba21ca

Please sign in to comment.