-
-
Save niner/065c8585c477f2ec98997e816b54cd4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/6model/reprconv.c b/src/6model/reprconv.c | |
index cfa58f70f..815c19ebe 100644 | |
--- a/src/6model/reprconv.c | |
+++ b/src/6model/reprconv.c | |
@@ -715,6 +715,7 @@ MVM_PUBLIC MVMString * MVM_repr_get_attr_s(MVMThreadContext *tc, MVMObject *obje | |
STABLE(object), object, OBJECT_BODY(object), | |
type, name, | |
hint, &result_reg, MVM_reg_str); | |
+ MVM_ASSERT_NOT_FROMSPACE(tc, result_reg.s); | |
return result_reg.s; | |
} | |
@@ -727,6 +728,7 @@ MVM_PUBLIC MVMObject * MVM_repr_get_attr_o(MVMThreadContext *tc, MVMObject *obje | |
STABLE(object), object, OBJECT_BODY(object), | |
type, name, | |
hint, &result_reg, MVM_reg_obj); | |
+ MVM_ASSERT_NOT_FROMSPACE(tc, result_reg.o); | |
return result_reg.o; | |
} | |
diff --git a/src/core/frame.c b/src/core/frame.c | |
index 8f36540f9..bc9f9b8af 100644 | |
--- a/src/core/frame.c | |
+++ b/src/core/frame.c | |
@@ -643,6 +643,7 @@ MVMFrame * MVM_frame_move_to_heap(MVMThreadContext *tc, MVMFrame *frame) { | |
MVMFrame *result = NULL; | |
MVM_CHECK_CALLER_CHAIN(tc, cur_to_promote); | |
MVMROOT3(tc, new_cur_frame, update_caller, result, { | |
+ //MVMROOT5(tc, frame, new_cur_frame, update_caller, cur_to_promote, result, { | |
while (cur_to_promote) { | |
/* Allocate a heap frame. */ | |
MVMFrame *promoted = MVM_gc_allocate_frame(tc); | |
@@ -1146,6 +1147,9 @@ MVMObject * MVM_frame_get_code_object(MVMThreadContext *tc, MVMCode *code) { | |
resolved); | |
} | |
} | |
+ if (code->body.code_object) | |
+ MVM_ASSERT_NOT_FROMSPACE(tc, code->body.code_object); | |
+ | |
return code->body.code_object | |
? code->body.code_object | |
: tc->instance->VMNull; | |
@@ -1215,6 +1219,8 @@ MVMObject * MVM_frame_takeclosure(MVMThreadContext *tc, MVMObject *code) { | |
MVM_ASSIGN_REF(tc, &(closure->common.header), closure->body.name, ((MVMCode *)code)->body.name); | |
MVM_ASSIGN_REF(tc, &(closure->common.header), closure->body.outer, captured); | |
+ MVM_ASSERT_NOT_FROMSPACE(tc, code); | |
+ MVM_ASSERT_NOT_FROMSPACE(tc, ((MVMCode*)code)->body.code_object); | |
MVM_ASSIGN_REF(tc, &(closure->common.header), closure->body.code_object, | |
((MVMCode *)code)->body.code_object); | |
diff --git a/src/core/interp.c b/src/core/interp.c | |
index 88de4bc43..f2de373d7 100644 | |
--- a/src/core/interp.c | |
+++ b/src/core/interp.c | |
@@ -2843,6 +2843,8 @@ void MVM_interp_run(MVMThreadContext *tc, void (*initial_invoke)(MVMThreadContex | |
OP(setcodeobj): { | |
MVMObject *obj = GET_REG(cur_op, 0).o; | |
if (REPR(obj)->ID == MVM_REPR_ID_MVMCode) { | |
+ MVM_ASSERT_NOT_FROMSPACE(tc, obj); | |
+ MVM_ASSERT_NOT_FROMSPACE(tc, ((MVMCode *)obj)->body.code_object); | |
MVM_ASSIGN_REF(tc, &(obj->header), ((MVMCode *)obj)->body.code_object, | |
GET_REG(cur_op, 2).o); | |
} | |
diff --git a/src/gc/collect.c b/src/gc/collect.c | |
index e37d56736..1236d2bf6 100644 | |
--- a/src/gc/collect.c | |
+++ b/src/gc/collect.c | |
@@ -215,7 +215,7 @@ static void process_worklist(MVMThreadContext *tc, MVMGCWorklist *worklist, Work | |
/* If the item was already seen and copied, then it will have a | |
* forwarding address already. Just update this pointer to the | |
* new address and we're done. */ | |
- assert(*item_ptr != item->sc_forward_u.forwarder); | |
+ //assert(*item_ptr != item->sc_forward_u.forwarder); | |
if (MVM_GC_DEBUG_ENABLED(MVM_GC_DEBUG_COLLECT)) { | |
if (*item_ptr != item->sc_forward_u.forwarder) { | |
GCDEBUG_LOG(tc, MVM_GC_DEBUG_COLLECT, "Thread %d run %d : updating handle %p from %p to forwarder %p\n", item_ptr, item, item->sc_forward_u.forwarder); | |
diff --git a/src/gc/collect.h b/src/gc/collect.h | |
index b967a2bcc..5a386314c 100644 | |
--- a/src/gc/collect.h | |
+++ b/src/gc/collect.h | |
@@ -1,6 +1,7 @@ | |
/* The maximum size of the nursery area. Note that since it's semi-space | |
* copying, we could actually have double this amount allocated per thread. */ | |
#define MVM_NURSERY_SIZE 4194304 | |
+//#define MVM_NURSERY_SIZE 512 | |
/* The nursery size threads other than the main thread start out with. If | |
* they fill it and trigger a GC run, then it is doubled. If they are | |
diff --git a/src/gc/orchestrate.c b/src/gc/orchestrate.c | |
index c2a761413..529b848e9 100644 | |
--- a/src/gc/orchestrate.c | |
+++ b/src/gc/orchestrate.c | |
@@ -250,7 +250,42 @@ static void finish_gc(MVMThreadContext *tc, MVMuint8 gen, MVMuint8 is_coordinato | |
} | |
#if MVM_GC_DEBUG >= 3 | |
+ //fprintf(stderr, "%d Killing old nursery\n", other->thread_id); | |
+// if (tc->instance->stables_to_free != NULL) { | |
+// MVMSTable *save, *cur_save; | |
+// int stable_count = 0, i = 0; | |
+// MVMSTable *cur = tc->instance->stables_to_free; | |
+// while (cur) { | |
+// stable_count++; | |
+// cur = cur->header.sc_forward_u.st; | |
+// } | |
+// save = MVM_calloc(stable_count, sizeof(MVMSTable)); | |
+// | |
+// cur = tc->instance->stables_to_free; | |
+// cur_save = save; | |
+// while (cur) { /* copy STables to the save space */ | |
+// memcpy(cur_save, cur, sizeof(MVMSTable)); | |
+// cur_save += sizeof(MVMSTable); | |
+// cur = cur->header.sc_forward_u.st; | |
+// if (++i > stable_count) abort(); | |
+// } | |
+// if (cur_save != save + stable_count * sizeof(MVMSTable)) | |
+// abort(); | |
+// | |
memset(other->nursery_fromspace, 0xef, other->nursery_fromspace_size); | |
+// | |
+// cur = tc->instance->stables_to_free; | |
+// cur_save = save; | |
+// while (cur) { /* copy STables back */ | |
+// memcpy(cur, cur_save, sizeof(MVMSTable)); | |
+// cur_save += sizeof(MVMSTable); | |
+// cur = cur->header.sc_forward_u.st; | |
+// stable_count--; | |
+// if (stable_count < 0) abort(); | |
+// } | |
+// if (stable_count != 0) abort(); | |
+// MVM_free(save); | |
+// } | |
#endif | |
/* Mark thread free to continue. */ | |
diff --git a/src/gc/roots.h b/src/gc/roots.h | |
index 39366bd23..2868673ba 100644 | |
--- a/src/gc/roots.h | |
+++ b/src/gc/roots.h | |
@@ -8,12 +8,19 @@ | |
/* Temp root push slow-path case. */ | |
MVM_PUBLIC void MVM_gc_root_temp_push_slow(MVMThreadContext *tc, MVMCollectable **obj_ref); | |
+#define MVM_GC_CHECK_OBJECT(obj_ref, name) \ | |
+ fprintf(stderr, "Checking %s at %p\n", name, obj_ref); \ | |
+ if (obj_ref && (obj_ref->common.header.sc_forward_u.forwarder == (void*)0xefefefefefefefef)) \ | |
+ MVM_panic(MVM_exitcode_gcroots, "Check for fromspace address failed for %s", name); | |
+ | |
/* Fast-path case of pushing a root onto the per-thread temporary roots. */ | |
MVM_STATIC_INLINE void MVM_gc_root_temp_push(MVMThreadContext *tc, MVMCollectable **obj_ref) { | |
/* If debugging, ensure the root is not null. */ | |
#ifdef MVM_TEMP_ROOT_DEBUG | |
if (obj_ref == NULL) | |
MVM_panic(MVM_exitcode_gcroots, "Illegal attempt to add null object address as a temporary root"); | |
+ if (*obj_ref && ((*obj_ref)->sc_forward_u.forwarder == (void*)0xefefefefefefefef)) | |
+ MVM_panic(MVM_exitcode_gcroots, "Illegal attempt to add fromspace address as a temporary root"); | |
#endif | |
/* If less than the number of always-allocated roots, just add. */ | |
diff --git a/src/gc/worklist.h b/src/gc/worklist.h | |
index 062f383d8..34328048b 100644 | |
--- a/src/gc/worklist.h | |
+++ b/src/gc/worklist.h | |
@@ -46,13 +46,20 @@ struct MVMGCWorklist { | |
MVM_panic(1, "Frame with NULL static_info added to worklist"); \ | |
}\ | |
else if (((*item_to_add)->flags & MVM_CF_STABLE) == 0 && !STABLE(*item_to_add)) \ | |
- MVM_panic(1, "NULL STable in item added to GC worklist"); \ | |
+ MVM_panic(1, "NULL STable in item added to GC worklist"); {\ | |
+ char* item_deref = (char*)*item_to_add;\ | |
+ char* nursery_alloc = (char*)tc->nursery_alloc; \ | |
+ char* nursery_alloc_limit = (char*)tc->nursery_alloc_limit; \ | |
if ((char *)*item_to_add >= (char *)tc->nursery_alloc && \ | |
- (char *)*item_to_add < (char *)tc->nursery_alloc_limit) \ | |
+ (char *)*item_to_add < (char *)tc->nursery_alloc_limit) { \ | |
+ fprintf(stderr, "thread %d item %p -> %p saved: %p nursery: %p limit: %p\n", tc->thread_id, item_to_add, *item_to_add, item_deref, nursery_alloc, nursery_alloc_limit); \ | |
MVM_panic(1, "Adding pointer %p to past fromspace to GC worklist", \ | |
- *item_to_add); \ | |
+ *item_to_add); } }\ | |
+ if ((*item_to_add)->flags & MVM_CF_FORWARDER_VALID) \ | |
+ assert(*item_to_add != (*item_to_add)->sc_forward_u.forwarder); \ | |
} \ | |
if (*item_to_add && (worklist->include_gen2 || !((*item_to_add)->flags & MVM_CF_SECOND_GEN))) { \ | |
+ /*fprintf(stderr, " adding %p -> %p\n", item_to_add, *item_to_add); */\ | |
if (worklist->items == worklist->alloc) \ | |
MVM_gc_worklist_add_slow(tc, worklist, item_to_add); \ | |
else \ | |
diff --git a/src/strings/ops.c b/src/strings/ops.c | |
index d51f0ebf8..3084a70ed 100644 | |
--- a/src/strings/ops.c | |
+++ b/src/strings/ops.c | |
@@ -20,6 +20,19 @@ static void check_strand_sanity(MVMThreadContext *tc, MVMString *s) { | |
MVM_exception_throw_adhoc(tc, | |
"Strand sanity check failed (strand length %d != num_graphs %d)", | |
len, MVM_string_graphs(tc, s)); | |
+ if (s->body.storage_type == MVM_STRING_STRAND) { | |
+ int i; | |
+ for (i = 0; i < s->body.num_strands; i++) { | |
+ if (s->body.storage.strands[i].blob_string == s) | |
+ MVM_panic(1, | |
+ "Strand sanity check failed (string contains itself as strand %d (%p)", | |
+ i, s->body.storage.strands[i]); | |
+ if (s->body.storage.strands[i].blob_string && s->body.storage.strands[i].blob_string->body.storage_type == MVM_STRING_STRAND) | |
+ MVM_panic(1, | |
+ "Strand sanity check failed (strand %d (%p) consists of strands", | |
+ i, s->body.storage.strands[i]); | |
+ } | |
+ } | |
} | |
#define STRAND_CHECK(tc, s) check_strand_sanity(tc, s); | |
#else | |
@@ -163,7 +176,7 @@ static MVMint64 knuth_morris_pratt_string_index (MVMThreadContext *tc, MVMString | |
/* Allocates strand storage. */ | |
static MVMStringStrand * allocate_strands(MVMThreadContext *tc, MVMuint16 num_strands) { | |
- return MVM_malloc(num_strands * sizeof(MVMStringStrand)); | |
+ return MVM_calloc(num_strands, sizeof(MVMStringStrand)); | |
} | |
/* Copies strands from one strand string to another. */ | |
@@ -870,29 +883,29 @@ MVMString * MVM_string_concatenate(MVMThreadContext *tc, MVMString *a, MVMString | |
MVM_string_get_grapheme_at_nocheck(tc, b, 0) | |
}; | |
MVMROOT2(tc, a, b, { | |
- /* If both are not synthetics, we can can pass those values unchanged | |
- * instead of iterating by codepoint */ | |
- if (0 <= last_a_first_b[0] && 0 <= last_a_first_b[1]) { | |
- renormalized_section = MVM_unicode_codepoints_c_array_to_nfg_string(tc, last_a_first_b, 2); | |
- consumed_a = 1; consumed_b = 1; | |
- } | |
- else { | |
- MVMCodepointIter last_a_ci; | |
- MVMCodepointIter first_b_ci; | |
- MVMuint32 a_codes = MVM_string_grapheme_ci_init(tc, &last_a_ci, last_a_first_b[0], 1); | |
- MVMuint32 b_codes = MVM_string_grapheme_ci_init(tc, &first_b_ci, last_a_first_b[1], 1); | |
- /* MSVC doesn't allow variable length arrays so use alloca to allocate onto the stack */ | |
- MVMCodepoint *last_a_first_b_codes = alloca((a_codes + b_codes) * sizeof(MVMCodepoint)); | |
- MVMuint32 i = 0; | |
- for (; MVM_string_grapheme_ci_has_more(tc, &last_a_ci); i++) { | |
- last_a_first_b_codes[i] = MVM_string_grapheme_ci_get_codepoint(tc, &last_a_ci); | |
+ /* If both are not synthetics, we can can pass those values unchanged | |
+ * instead of iterating by codepoint */ | |
+ if (0 <= last_a_first_b[0] && 0 <= last_a_first_b[1]) { | |
+ renormalized_section = MVM_unicode_codepoints_c_array_to_nfg_string(tc, last_a_first_b, 2); | |
+ consumed_a = 1; consumed_b = 1; | |
} | |
- for (; MVM_string_grapheme_ci_has_more(tc, &first_b_ci); i++) { | |
- last_a_first_b_codes[i] = MVM_string_grapheme_ci_get_codepoint(tc, &first_b_ci); | |
+ else { | |
+ MVMCodepointIter last_a_ci; | |
+ MVMCodepointIter first_b_ci; | |
+ MVMuint32 a_codes = MVM_string_grapheme_ci_init(tc, &last_a_ci, last_a_first_b[0], 1); | |
+ MVMuint32 b_codes = MVM_string_grapheme_ci_init(tc, &first_b_ci, last_a_first_b[1], 1); | |
+ /* MSVC doesn't allow variable length arrays so use alloca to allocate onto the stack */ | |
+ MVMCodepoint *last_a_first_b_codes = alloca((a_codes + b_codes) * sizeof(MVMCodepoint)); | |
+ MVMuint32 i = 0; | |
+ for (; MVM_string_grapheme_ci_has_more(tc, &last_a_ci); i++) { | |
+ last_a_first_b_codes[i] = MVM_string_grapheme_ci_get_codepoint(tc, &last_a_ci); | |
+ } | |
+ for (; MVM_string_grapheme_ci_has_more(tc, &first_b_ci); i++) { | |
+ last_a_first_b_codes[i] = MVM_string_grapheme_ci_get_codepoint(tc, &first_b_ci); | |
+ } | |
+ renormalized_section = MVM_unicode_codepoints_c_array_to_nfg_string(tc, last_a_first_b_codes, a_codes + b_codes); | |
+ consumed_a = 1; consumed_b = 1; | |
} | |
- renormalized_section = MVM_unicode_codepoints_c_array_to_nfg_string(tc, last_a_first_b_codes, a_codes + b_codes); | |
- consumed_a = 1; consumed_b = 1; | |
- } | |
}); | |
if (renormalized_section) { | |
if (agraphs == consumed_a && bgraphs == consumed_b) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment