Skip to content

Instantly share code, notes, and snippets.

@MasterDuke17
Last active December 26, 2020 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterDuke17/4b754d5666dca556b6631d3fa1f94b19 to your computer and use it in GitHub Desktop.
Save MasterDuke17/4b754d5666dca556b6631d3fa1f94b19 to your computer and use it in GitHub Desktop.
1 uh, lots of deopts for 0x55b709526a90, maybe it should be removed
1 uh, lots of deopts for 0x55b70952a750, maybe it should be removed
1581 uh, lots of deopts for 0x55b709504398, maybe it should be removed
686388 uh, lots of deopts for 0x55b709528080, maybe it should be removed
687971 but its discard state is already 1
687971 found the matching candidate
diff --git src/6model/reprs/MVMSpeshCandidate.c src/6model/reprs/MVMSpeshCandidate.c
index 370571401..4be8b860e 100644
--- src/6model/reprs/MVMSpeshCandidate.c
+++ src/6model/reprs/MVMSpeshCandidate.c
@@ -364,3 +364,20 @@ void MVM_spesh_candidate_discard_existing(MVMThreadContext *tc, MVMStaticFrame *
MVM_spesh_arg_guard_discard(tc, sf);
}
}
+
+/* Discards one candidates. */
+void MVM_spesh_candidate_discard_one(MVMThreadContext *tc, MVMStaticFrame *sf, MVMSpeshCandidate *cand) {
+ MVMStaticFrameSpesh *spesh = sf->body.spesh;
+ if (spesh) {
+ MVMuint32 i;
+ for (i = 0; i < spesh->body.num_spesh_candidates; i++) {
+ MVMSpeshCandidate *sc = spesh->body.spesh_candidates[i];
+ if (sc == cand) {
+ fprintf(stderr, "found the matching candidate\n");
+ sc->body.discarded = 1;
+ break;
+ }
+ }
+ MVM_spesh_arg_guard_discard(tc, sf);
+ }
+}
diff --git src/6model/reprs/MVMSpeshCandidate.h src/6model/reprs/MVMSpeshCandidate.h
index e0b189990..f3b70bbed 100644
--- src/6model/reprs/MVMSpeshCandidate.h
+++ src/6model/reprs/MVMSpeshCandidate.h
@@ -31,6 +31,9 @@ struct MVMSpeshCandidateBody {
/* Deoptimization mappings. */
MVMint32 *deopts;
+ /* Count of times an optimization was deopted. */
+ MVMuint32 deopt_count;
+
/* Bit field of named args used to put in place during deopt, since we
* typically don't update the array in specialized code. */
MVMuint64 deopt_named_used_bit_field;
@@ -88,3 +91,4 @@ const MVMREPROps * MVMSpeshCandidate_initialize(MVMThreadContext *tc);
/* Functions for creating and clearing up specializations. */
void MVM_spesh_candidate_add(MVMThreadContext *tc, MVMSpeshPlanned *p);
void MVM_spesh_candidate_discard_existing(MVMThreadContext *tc, MVMStaticFrame *sf);
+void MVM_spesh_candidate_discard_one(MVMThreadContext *tc, MVMStaticFrame *sf, MVMSpeshCandidate *cand);
diff --git src/spesh/deopt.c src/spesh/deopt.c
index 87a408de3..08e521e77 100644
--- src/spesh/deopt.c
+++ src/spesh/deopt.c
@@ -243,6 +243,14 @@ static void deopt_frame(MVMThreadContext *tc, MVMFrame *f, MVMuint32 deopt_idx,
materialize_replaced_objects(tc, f, deopt_idx);
});
+ /* Log that this opt was deopted, we want to undo the
+ * optimization if this happens too many times. */
+ if (f->spesh_cand->body.deopt_count++ > 100) {
+ fprintf(stderr, "uh, lots of deopts for %p, maybe it should be removed\n", f->spesh_cand);
+ MVM_spesh_candidate_discard_one(tc, f->static_info, f->spesh_cand);
+ fprintf(stderr, "but its discard state is already %u\n", f->spesh_cand->body.discarded);
+ }
+
/* Check if we have inlines. */
if (f->spesh_cand->body.inlines) {
/* Yes, going to have to re-create the frames; uninline
my @a = ("a" .. "za")[*]; say @a[(^@a).pick]; say @a.elems; $*VM.request-garbage-collection; $*VM.request-garbage-collection; say now - INIT now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment