Skip to content

Commit

Permalink
[truffle] Stub STables while deserializing
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Aug 30, 2018
1 parent 91a5f6c commit a203dc0
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 20 deletions.
8 changes: 8 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/truffle/sixmodel/REPR.java
@@ -0,0 +1,8 @@
package org.perl6.nqp.truffle.sixmodel;

/**
* Base of all 6model representations. Has default implementations of functions that
* are not mandatory.
*/
public abstract class REPR {
}
@@ -0,0 +1,15 @@
package org.perl6.nqp.truffle.sixmodel;

import java.util.ArrayList;
import java.util.HashMap;

import org.perl6.nqp.truffle.sixmodel.reprs.P6opaque;

public class REPRRegistry {
public static REPR getByName(String name) {
switch (name) {
case "P6opaque": return new P6opaque();
default: throw new RuntimeException("No REPR " + name);
}
}
}
30 changes: 30 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/truffle/sixmodel/STable.java
@@ -0,0 +1,30 @@
package org.perl6.nqp.truffle.sixmodel;

public class STable {
/** Initializes a new STable.
*/
public STable(REPR repr, Object how) {
this.repr = repr;
this.how = how;
}

/**
* The representation operation table.
*/
public REPR repr;

/**
* The meta-object.
*/
public Object how;

/**
* The type-object.
*/
public Object what;

/**
* Serialization context that this s-table belongs to.
*/
public SerializationContext sc;
}
@@ -1,14 +1,59 @@
package org.perl6.nqp.truffle.sixmodel;

import java.util.ArrayList;
import java.util.HashMap;

public final class SerializationContext {
/* The handle of this SC. */
public String handle;

/* Description (probably the file name) if any. */
public String description;

/* The root set of objects that live in this SC. */
private ArrayList<Object> rootObjects;

/* The root set of STables that live in this SC. */
private ArrayList<STable> rootSTables;

public SerializationContext(String handle) {
this.handle = handle;
this.rootObjects = new ArrayList<Object>();
this.rootSTables = new ArrayList<STable>();
}

public void initSTableList(int entries) {
rootSTables.ensureCapacity(entries);
for (int i = 0; i < entries; i++)
rootSTables.add(null);
}

private HashMap<STable, Integer> stableIndexCache = new HashMap<STable, Integer>();
public void addSTable(STable stable) {
int newIndex = rootSTables.size();
rootSTables.add(stable);
stableIndexCache.put(stable, new Integer(newIndex));
}

public void setSTable(int index, STable stable) {
rootSTables.set(index, stable);
stableIndexCache.put(stable, new Integer(index));
}

public int getSTableIndex(STable stable) {
Integer cachedIndex = stableIndexCache.get(stable);
if (cachedIndex != null) {
return cachedIndex.intValue();
} else {
return -1;
}
}

public STable getSTable(int index) {
return rootSTables.get(index);
}

public int stableCount() {
return rootSTables.size();
}
}
Expand Up @@ -110,11 +110,11 @@ public void deserialize() {
// sc.addCodeRef(cr[i]);
// }
//
// // Handle any STable repossessions, then stub STables.
// sc.initSTableList(stTableEntries);
// Handle any STable repossessions, then stub STables.
sc.initSTableList(stTableEntries);
// if (reposTableEntries > 0)
// repossess(1);
// stubSTables();
stubSTables();
//
// // Handle any object repossessions, then stub objects.
// sc.initObjectList(objTableEntries);
Expand Down Expand Up @@ -335,23 +335,23 @@ private void resolveDependencies() {
// }
// }
//
// private void stubSTables() {
// for (int i = 0; i < stTableEntries; i++) {
// // May already have it, due to repossession.
// if (sc.getSTable(i) != null)
// continue;
//
// // Look up representation.
// orig.position(stTableOffset + i * STABLES_TABLE_ENTRY_SIZE);
// REPR repr = REPRRegistry.getByName(lookupString(orig.getInt()));
//
// // Create STable stub and add it to the root STable set.
// STable st = new STable(repr, null);
// st.sc = sc;
// sc.setSTable(i, st);
// }
// }
//
private void stubSTables() {
for (int i = 0; i < stTableEntries; i++) {
// May already have it, due to repossession.
if (sc.getSTable(i) != null)
continue;

// Look up representation.
orig.position(stTableOffset + i * STABLES_TABLE_ENTRY_SIZE);
REPR repr = REPRRegistry.getByName(lookupString(orig.getInt()));

// Create STable stub and add it to the root STable set.
STable st = new STable(repr, null);
st.sc = sc;
sc.setSTable(i, st);
}
}

// private void stubObjects() {
// for (int i = 0; i < objTableEntries; i++) {
// // May already have it, due to repossession.
Expand Down
@@ -0,0 +1,6 @@
package org.perl6.nqp.truffle.sixmodel.reprs;

import org.perl6.nqp.truffle.sixmodel.REPR;

public class P6opaque extends REPR {
}
1 change: 1 addition & 0 deletions tools/build/Makefile-JVM.in
Expand Up @@ -13,6 +13,7 @@ TRUFFLE_JAVAS = \
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/*.java \
src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/*/*.java \
src/vm/jvm/runtime/org/perl6/nqp/truffle/sixmodel/*.java \
src/vm/jvm/runtime/org/perl6/nqp/truffle/sixmodel/reprs/*.java \
src/vm/jvm/runtime/org/perl6/nqp/truffle/*.java \

RUNTIME_JAVAS = \
Expand Down

0 comments on commit a203dc0

Please sign in to comment.