Skip to content

Commit 0de5175

Browse files
committed
Initial bits of SC repossession support.
This doesn't serialize/deserialize the repossessions, but at least should mean we start to detect and record them.
1 parent 5eac9c8 commit 0de5175

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,8 +1516,11 @@ public static SixModelObject setwho(SixModelObject o, SixModelObject who, Thread
15161516
public static SixModelObject rebless(SixModelObject obj, SixModelObject newType, ThreadContext tc) {
15171517
obj = decont(obj, tc);
15181518
newType = decont(newType, tc);
1519-
if (obj.st != newType.st)
1519+
if (obj.st != newType.st) {
15201520
obj.st.REPR.change_type(tc, obj, newType);
1521+
if (obj.sc != null)
1522+
scwbObject(tc, obj);
1523+
}
15211524
return obj;
15221525
}
15231526
public static SixModelObject create(SixModelObject obj, ThreadContext tc) {
@@ -1630,13 +1633,17 @@ public static SixModelObject setmethcache(SixModelObject obj, SixModelObject met
16301633
cache.put(iterkey_s(cur, tc), iterval(cur, tc));
16311634
}
16321635
obj.st.MethodCache = cache;
1636+
if (obj.st.sc != null)
1637+
scwbSTable(tc, obj.st);
16331638
return obj;
16341639
}
16351640
public static SixModelObject setmethcacheauth(SixModelObject obj, long flag, ThreadContext tc) {
16361641
int newFlags = obj.st.ModeFlags & (~STable.METHOD_CACHE_AUTHORITATIVE);
16371642
if (flag != 0)
16381643
newFlags = newFlags | STable.METHOD_CACHE_AUTHORITATIVE;
16391644
obj.st.ModeFlags = newFlags;
1645+
if (obj.st.sc != null)
1646+
scwbSTable(tc, obj.st);
16401647
return obj;
16411648
}
16421649
public static SixModelObject settypecache(SixModelObject obj, SixModelObject types, ThreadContext tc) {
@@ -1645,11 +1652,15 @@ public static SixModelObject settypecache(SixModelObject obj, SixModelObject typ
16451652
for (long i = 0; i < elems; i++)
16461653
cache[(int)i] = types.at_pos_boxed(tc, i);
16471654
obj.st.TypeCheckCache = cache;
1655+
if (obj.st.sc != null)
1656+
scwbSTable(tc, obj.st);
16481657
return obj;
16491658
}
16501659
public static SixModelObject settypecheckmode(SixModelObject obj, long mode, ThreadContext tc) {
16511660
obj.st.ModeFlags = (int)mode |
16521661
(obj.st.ModeFlags & (~STable.TYPE_CHECK_CACHE_FLAG_MASK));
1662+
if (obj.st.sc != null)
1663+
scwbSTable(tc, obj.st);
16531664
return obj;
16541665
}
16551666
public static long objprimspec(SixModelObject obj, ThreadContext tc) {
@@ -1781,27 +1792,35 @@ public static String getattr_s(SixModelObject obj, SixModelObject ch, String nam
17811792
}
17821793
public static SixModelObject bindattr(SixModelObject obj, SixModelObject ch, String name, SixModelObject value, ThreadContext tc) {
17831794
obj.bind_attribute_boxed(tc, decont(ch, tc), name, STable.NO_HINT, value);
1795+
if (obj.sc != null)
1796+
scwbObject(tc, obj);
17841797
return value;
17851798
}
17861799
public static long bindattr_i(SixModelObject obj, SixModelObject ch, String name, long value, ThreadContext tc) {
17871800
tc.native_i = value;
17881801
obj.bind_attribute_native(tc, decont(ch, tc), name, STable.NO_HINT);
17891802
if (tc.native_type != ThreadContext.NATIVE_INT)
17901803
throw ExceptionHandling.dieInternal(tc, "Attribute '" + name + "' is not a native int");
1804+
if (obj.sc != null)
1805+
scwbObject(tc, obj);
17911806
return value;
17921807
}
17931808
public static double bindattr_n(SixModelObject obj, SixModelObject ch, String name, double value, ThreadContext tc) {
17941809
tc.native_n = value;
17951810
obj.bind_attribute_native(tc, decont(ch, tc), name, STable.NO_HINT);
17961811
if (tc.native_type != ThreadContext.NATIVE_NUM)
17971812
throw ExceptionHandling.dieInternal(tc, "Attribute '" + name + "' is not a native num");
1813+
if (obj.sc != null)
1814+
scwbObject(tc, obj);
17981815
return value;
17991816
}
18001817
public static String bindattr_s(SixModelObject obj, SixModelObject ch, String name, String value, ThreadContext tc) {
18011818
tc.native_s = value;
18021819
obj.bind_attribute_native(tc, decont(ch, tc), name, STable.NO_HINT);
18031820
if (tc.native_type != ThreadContext.NATIVE_STR)
18041821
throw ExceptionHandling.dieInternal(tc, "Attribute '" + name + "' is not a native str");
1822+
if (obj.sc != null)
1823+
scwbObject(tc, obj);
18051824
return value;
18061825
}
18071826
public static long attrinited(SixModelObject obj, SixModelObject ch, String name, ThreadContext tc) {
@@ -2828,6 +2847,29 @@ public static SixModelObject popcompsc(ThreadContext tc) {
28282847
tc.compilingSCs = null;
28292848
return result;
28302849
}
2850+
2851+
/* SC write barriers (not really ops, but putting them here with the SC
2852+
* related bits). */
2853+
public static void scwbObject(ThreadContext tc, SixModelObject obj) {
2854+
int cscSize = tc.compilingSCs == null ? 0 : tc.compilingSCs.size();
2855+
if (cscSize == 0 || tc.scwbDisableDepth > 0)
2856+
return;
2857+
SerializationContext compSC = tc.compilingSCs.get(cscSize - 1).referencedSC;
2858+
if (obj.sc != compSC) {
2859+
compSC.repossessObject(obj.sc, obj);
2860+
obj.sc = compSC;
2861+
}
2862+
}
2863+
public static void scwbSTable(ThreadContext tc, STable st) {
2864+
int cscSize = tc.compilingSCs == null ? 0 : tc.compilingSCs.size();
2865+
if (cscSize == 0 || tc.scwbDisableDepth > 0)
2866+
return;
2867+
SerializationContext compSC = tc.compilingSCs.get(cscSize - 1).referencedSC;
2868+
if (st.sc != compSC) {
2869+
compSC.repossessSTable(st.sc, st);
2870+
st.sc = compSC;
2871+
}
2872+
}
28312873

28322874
/* bitwise operations. */
28332875
public static long bitor_i(long valA, long valB) {

src/vm/jvm/runtime/org/perl6/nqp/sixmodel/SerializationContext.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,28 @@ public SerializationContext(String handle) {
3838
this.rep_indexes = new ArrayList<Integer>();
3939
this.rep_scs = new ArrayList<SerializationContext>();
4040
}
41+
42+
/* Takes an object and adds it to this SC's root set, and installs a
43+
* reposession entry. */
44+
public void repossessObject(SerializationContext origSC, SixModelObject obj) {
45+
/* Add to root set. */
46+
int newSlot = root_objects.size();
47+
root_objects.add(obj);
48+
49+
/* Add repossession entry. */
50+
rep_indexes.add(newSlot << 1);
51+
rep_scs.add(origSC);
52+
}
53+
54+
/* Takes an STable and adds it to this SC's root set, and installs a
55+
* reposession entry. */
56+
public void repossessSTable(SerializationContext origSC, STable st) {
57+
/* Add to root set. */
58+
int newSlot = root_stables.size();
59+
root_stables.add(st);
60+
61+
/* Add repossession entry. */
62+
rep_indexes.add((newSlot << 1) | 1);
63+
rep_scs.add(origSC);
64+
}
4165
}

0 commit comments

Comments
 (0)