Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Last active May 2, 2020 16:07
Show Gist options
  • Save MasterDuke17/f790716120395df9f252063ed602fd8a to your computer and use it in GitHub Desktop.
Save MasterDuke17/f790716120395df9f252063ed602fd8a to your computer and use it in GitHub Desktop.
Thread 1 "raku" received signal SIGSEGV, Segmentation fault.
0x00007ffff7923a74 in at_key (tc=0x555555559fb0, st=0x5555555c4c28, root=<optimized out>, data=0x5555555da1c8, key_obj=0x55555730ce80, result=result@entry=0x7fffffffdd40, kind=8) at src/6model/reprs/MVMNull.h:11
11 return !check || check == tc->instance->VMNull;
(gdb) bt
#0 0x00007ffff7923a74 in at_key (tc=0x555555559fb0, st=0x5555555c4c28, root=<optimized out>, data=0x5555555da1c8, key_obj=0x55555730ce80, result=result@entry=0x7fffffffdd40, kind=8) at src/6model/reprs/MVMNull.h:11
#1 0x00007ffff79255fe in MVMHash_at_key (tc=<optimized out>, st=<optimized out>, root=<optimized out>, data=<optimized out>, key_obj=<optimized out>, result=result@entry=0x7fffffffdd40, kind=<optimized out>) at src/6model/reprs/MVMHash.c:88
#2 0x00007ffff791bb0b in MVM_repr_at_key_o (tc=tc@entry=0x555555559fb0, obj=<optimized out>, key=<optimized out>) at src/6model/reprconv.c:518
#3 0x00007ffff78e7f4d in MVM_hll_sym_get (tc=0x555555559fb0, hll=<optimized out>, sym=0x5555576e6fa0) at src/core/hll.c:273
#4 0x00007ffff78c1346 in MVM_interp_run (tc=0x555555559fb0, initial_invoke=0x5555555c4c28, invoke_data=0x5555555c4c28, outer_runloop=0x7ffff7e8c260 <Uninstantiable_this_repr>) at src/core/interp.c:2765
#5 0x0000555555555666 in main (argc=<optimized out>, argv=0x7fffffffe378) at src/vm/moar/runner/main.c:392
Thread 1 "raku" received signal SIGSEGV, Segmentation fault.
0x00007ffff78b4f3d in at_key (tc=0x555555559fb0, st=0x5555555c4c28, root=0x5555555da1b0, data=0x5555555da1c8, key_obj=0x55555730c2e0, result=0x7fffffffc8b0, kind=8) at src/6model/reprs/MVMHash.c:80
80 MVM_HASH_GET(tc, body->hash_head, (MVMString *)key_obj, entry);
(gdb) bt
#0 0x00007ffff78b4f3d in at_key (tc=0x555555559fb0, st=0x5555555c4c28, root=0x5555555da1b0, data=0x5555555da1c8, key_obj=0x55555730c2e0, result=0x7fffffffc8b0, kind=8) at src/6model/reprs/MVMHash.c:80
#1 0x00007ffff78b5213 in MVMHash_at_key (tc=0x555555559fb0, st=0x5555555c4c28, root=0x5555555da1b0, data=0x5555555da1c8, key_obj=0x55555730c2e0, result=0x7fffffffc8b0, kind=8) at src/6model/reprs/MVMHash.c:88
#2 0x00007ffff78a8dd2 in MVM_repr_at_key_o (tc=0x555555559fb0, obj=0x5555555da1b0, key=0x55555730c2e0) at src/6model/reprconv.c:518
#3 0x00007ffff785b2c2 in MVM_hll_sym_get (tc=0x555555559fb0, hll=0x55555730c2e0, sym=0x5555576e63e0) at src/core/hll.c:273
#4 0x00007ffff78278eb in MVM_interp_run (tc=0x555555559fb0, initial_invoke=0x7ffff799920b <toplevel_initial_invoke>, invoke_data=0x5555555fdc58, outer_runloop=0x0) at src/core/interp.c:2765
#5 0x00007ffff7999385 in MVM_vm_run_file (instance=0x5555555594a0, filename=0x555555559430 "/home/dan/Source/perl6/install/share/perl6/runtime/perl6.moarvm") at src/moar.c:461
#6 0x0000555555555666 in main (argc=<optimized out>, argv=0x7fffffffe378) at src/vm/moar/runner/main.c:392
diff --git src/jit/graph.c src/jit/graph.c
index a610001ee..78dd74a1a 100644
--- src/jit/graph.c
+++ src/jit/graph.c
@@ -293,6 +293,7 @@ static void * op_to_func(MVMThreadContext *tc, MVMint16 opcode) {
case MVM_OP_nfarunproto: return MVM_nfa_run_proto;
case MVM_OP_nfafromstatelist: return MVM_nfa_from_statelist;
case MVM_OP_hllize: return MVM_hll_map;
+ case MVM_OP_getcurhllsym: return MVM_hll_sym_get;
case MVM_OP_gethllsym: return MVM_hll_sym_get;
case MVM_OP_clone: return MVM_repr_clone;
case MVM_OP_create: return MVM_repr_alloc_init;
@@ -2027,6 +2028,16 @@ start:
jg_append_call_c(tc, jg, op_to_func(tc, op), 4, args, MVM_JIT_RV_VOID, -1);
break;
}
+ case MVM_OP_getcurhllsym: {
+ MVMint16 dst = ins->operands[0].reg.orig;
+ MVMint32 sym = ins->operands[1].reg.orig;
+ MVMJitCallArg args[] = { { MVM_JIT_INTERP_VAR, MVM_JIT_INTERP_TC },
+ { MVM_JIT_LITERAL_PTR, 0 },
+ { MVM_JIT_REG_VAL, sym } };
+ args[1].v.ptr = jg->sg->sf->body.cu->body.hll_name;
+ jg_append_call_c(tc, jg, op_to_func(tc, op), 3, args, MVM_JIT_RV_PTR, dst);
+ break;
+ }
case MVM_OP_gethllsym: {
MVMint16 dst = ins->operands[0].reg.orig;
MVMint16 hll = ins->operands[1].reg.orig;
diff --git src/spesh/optimize.c src/spesh/optimize.c
index 49061eda7..c790bc294 100644
--- src/spesh/optimize.c
+++ src/spesh/optimize.c
@@ -1305,6 +1305,27 @@ static void optimize_hllbool(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns
}
}
+/* Optimizes a getcurhllsym instruction away if the value is known */
+static void optimize_getcurhllsym(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins) {
+ MVMSpeshFacts *sym_facts = MVM_spesh_get_facts(tc, g, ins->operands[1]);
+ if (sym_facts->flags & MVM_SPESH_FACT_KNOWN_VALUE) {
+ MVMSpeshFacts *tgt_facts = MVM_spesh_get_facts(tc, g, ins->operands[0]);
+ MVMString *hll_name = g->sf->body.cu->body.hll_name;
+ MVMObject *hll_sym = MVM_hll_sym_get(tc, hll_name, sym_facts->value.s);
+
+ MVM_spesh_usages_delete_by_reg(tc, g, ins->operands[1], ins);
+
+ ins->info = MVM_op_get_op(MVM_OP_sp_getspeshslot);
+ ins->operands[1].lit_i16 = MVM_spesh_add_spesh_slot_try_reuse(tc, g,
+ (MVMCollectable*)hll_sym);
+ tgt_facts->flags |= (MVM_SPESH_FACT_KNOWN_VALUE | MVM_SPESH_FACT_KNOWN_TYPE);
+ tgt_facts->value.o = hll_sym;
+ tgt_facts->type = STABLE(hll_sym)->WHAT;
+ MVM_spesh_use_facts(tc, g, sym_facts);
+ MVM_spesh_facts_depend(tc, g, tgt_facts, sym_facts);
+ }
+}
+
/* Optimize an object conditional (if_o, unless_o) to simpler operations.
*
* We always perform the split of the if_o to istrue + if_i, because a branch
@@ -2648,6 +2669,9 @@ static void optimize_bb_switch(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshB
case MVM_OP_hllboolfor:
optimize_hllbool(tc, g, ins);
break;
+ case MVM_OP_getcurhllsym:
+ optimize_getcurhllsym(tc, g, ins);
+ break;
case MVM_OP_if_i:
case MVM_OP_unless_i:
case MVM_OP_if_n:
diff --git src/spesh/optimize.c src/spesh/optimize.c
index 49061eda7..692622197 100644
--- src/spesh/optimize.c
+++ src/spesh/optimize.c
@@ -1305,6 +1305,18 @@ static void optimize_hllbool(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns
}
}
+/* Turns a getcurhllsym instruction into an sp_getcurhllsym with the HLL name added to
+ * a spesh slot so the function call can be jitted. */
+static void optimize_getcurhllsym(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshIns *ins) {
+ MVMSpeshOperand *orig_o = ins->operands;
+ ins->info = MVM_op_get_op(MVM_OP_sp_getcurhllsym);
+ ins->operands = MVM_spesh_alloc(tc, g, 3 * sizeof(MVMSpeshOperand));
+ memcpy(ins->operands, orig_o, 2 * sizeof(MVMSpeshOperand));
+ ins->operands[2].lit_i16 = MVM_spesh_add_spesh_slot_try_reuse(tc, g, g->sf->body.cu->body.hll_name);
+
+ MVM_spesh_graph_add_comment(tc, g, ins, "specialized from %s", ins->info->name);
+}
+
/* Optimize an object conditional (if_o, unless_o) to simpler operations.
*
* We always perform the split of the if_o to istrue + if_i, because a branch
@@ -2648,6 +2660,9 @@ static void optimize_bb_switch(MVMThreadContext *tc, MVMSpeshGraph *g, MVMSpeshB
case MVM_OP_hllboolfor:
optimize_hllbool(tc, g, ins);
break;
+ case MVM_OP_getcurhllsym:
+ optimize_getcurhllsym(tc, g, ins);
+ break;
case MVM_OP_if_i:
case MVM_OP_unless_i:
case MVM_OP_if_n:
diff --git src/core/oplist src/core/oplist
index 7709c9183..84bd4dc63 100644
--- src/core/oplist
+++ src/core/oplist
@@ -1062,6 +1062,8 @@ sp_mul_I .s w(obj) int16 sslot r(obj) r(obj) int16 int16 :pure
sp_bool_I .s w(int64) r(obj) int16 :pure
+sp_getcurhllsym .s w(obj) str sslot :pure
+
# Profiler recording ops. Naming convention: start with prof_. Must all be
# marked .s, which is how the validator knows to exclude them. (For that
# purpose, we treat them as a kind of spesh op).
diff --git src/core/interp.c src/core/interp.c
index 783df4ddb..4f8abd4d3 100644
--- src/core/interp.c
+++ src/core/interp.c
@@ -2760,6 +2760,12 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex
cur_op += 4;
goto NEXT;
}
+ OP(sp_getcurhllsym): {
+ MVMString *hll_name = (MVMString *)tc->cur_frame->effective_spesh_slots[GET_UI16(cur_op, 4)];
+ GET_REG(cur_op, 0).o = MVM_hll_sym_get(tc, hll_name, GET_REG(cur_op, 2).s);
+ cur_op += 6;
+ goto NEXT;
+ }
OP(bindcurhllsym): {
MVMObject *syms = tc->instance->hll_syms, *hash;
MVMString *hll_name = tc->cur_frame->static_info->body.cu->body.hll_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment