Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Eliminate ArrayList.indexOf usage in SerializationContext on JVM.
  • Loading branch information
Donald Hunter committed Aug 14, 2014
1 parent daaf098 commit 334b593
Show file tree
Hide file tree
Showing 7 changed files with 709 additions and 594 deletions.
40 changes: 20 additions & 20 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/CompilationUnit.java
Expand Up @@ -25,17 +25,17 @@ public abstract class CompilationUnit {
* Mapping of local integer IDs to matching code reference.
*/
public CodeRef[] qbidToCodeRef;

/**
* Array of all code references.
*/
public CodeRef[] codeRefs;

/**
* Call site descriptors used in this compilation unit.
*/
public CallSiteDescriptor[] callSites;

/**
* HLL configuration for this compilation unit.
*/
Expand All @@ -45,7 +45,7 @@ public abstract class CompilationUnit {
* If true, the class corresponding to this CompilationUnit is shared between GlobalContexts.
*/
public boolean shared;

/**
* When a compilation unit is serving as the main entry point, its main
* method will just delegate to here. Thus this needs to trigger some
Expand All @@ -57,9 +57,9 @@ public static void enterFromMain(Class<?> cuType, int entryCodeRefIdx, String[]
CompilationUnit cu = setupCompilationUnit(tc, cuType, false);
Ops.invokeMain(tc, cu.qbidToCodeRef[entryCodeRefIdx], cuType.getName(), argv);
}

/**
* Takes the class object for some compilation unit and sets it up.
* Takes the class object for some compilation unit and sets it up.
*/
public static CompilationUnit setupCompilationUnit(ThreadContext tc, Class<?> cuType, boolean shared)
throws InstantiationException, IllegalAccessException {
Expand All @@ -68,7 +68,7 @@ public static CompilationUnit setupCompilationUnit(ThreadContext tc, Class<?> cu
cu.initializeCompilationUnit(tc);
return cu;
}

/**
* Does initialization work for the compilation unit.
*/
Expand All @@ -87,7 +87,7 @@ public void initializeCompilationUnit(ThreadContext tc) {

String cuid = ann.cuid();
CodeRef cr = new CodeRef(this, m.mh.bindTo(this), ann.name(), cuid,
ann.oLexicalNames().length == 0 ? null : ann.oLexicalNames(),
ann.oLexicalNames().length == 0 ? null : ann.oLexicalNames(),
ann.iLexicalNames().length == 0 ? null : ann.iLexicalNames(),
ann.nLexicalNames().length == 0 ? null : ann.nLexicalNames(),
ann.sLexicalNames().length == 0 ? null : ann.sLexicalNames(),
Expand Down Expand Up @@ -124,13 +124,13 @@ public void initializeCompilationUnit(ThreadContext tc) {
cuidToCodeRef.put(c.staticInfo.uniqueId, c);
}
}

/* Build callsite descriptors. */
callSites = getCallSites();

/* Get HLL configuration object. */
hllConfig = tc.gc.getHLLConfigFor(this.hllName());

/* Run any deserialization code. */
CodeRef desCodeRef = null;
if (deserializeQbid() >= 0)
Expand Down Expand Up @@ -223,7 +223,7 @@ public void runLoadIfAvailable(ThreadContext tc) {
throw ExceptionHandling.dieInternal(tc, e.toString());
}
}

/**
* Turns a compilation unit unique ID into the matching code-ref.
*/
Expand All @@ -237,7 +237,7 @@ public CodeRef lookupCodeRef(String uniqueId) { /*FOR_STAGE0*/
public CodeRef lookupCodeRef(int localId) {
return qbidToCodeRef[localId];
}

/**
* Parses a bunch of info on static lexical values for a block and
* installs each of them. TODO: lazify so we don't do it for blocks we
Expand All @@ -257,42 +257,42 @@ private void setLexValues(ThreadContext tc, CodeRef cr, String toParse) {
Integer idx = cr.staticInfo.oTryGetLexicalIdx(lexName);
if (idx == null)
new RuntimeException("Invalid lexical name '" + lexName + "' in static lexical installation");
cr.staticInfo.oLexStatic[idx] = tc.gc.scs.get(handle).root_objects.get(scIdx);
cr.staticInfo.oLexStatic[idx] = tc.gc.scs.get(handle).getObject(scIdx);
cr.staticInfo.oLexStaticFlags[idx] = (byte)flags;
}
}

/**
* Code generation emits this to build up the various CodeRef related
* data structures.
*/
public CodeRef[] getCodeRefs() { return null; }

/**
* Code generation emits this to build up all the callsite descriptors
* that are used by this compilation unit.
*/
public abstract CallSiteDescriptor[] getCallSites();

/**
* Code generation emits this to supply the HLL name from QAST::CompUnit.
*/
public abstract String hllName();

/**
* Code generation overrides this if there's an SC to deserialize.
*/
public int deserializeQbid() {
return -1;
}

/**
* Code generation overrides this if there's an SC to deserialize.
*/
public int loadQbid() {
return -1;
}

/**
* Code generation overrides this with the mainline blcok.
*/
Expand Down

0 comments on commit 334b593

Please sign in to comment.