Skip to content

Commit

Permalink
[JIT] Be more silent about internal failures
Browse files Browse the repository at this point in the history
Loudly complaining about internal failures tends to upset some people.
  • Loading branch information
bdw committed Oct 15, 2018
1 parent 588873f commit 8c2dd3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
17 changes: 12 additions & 5 deletions src/jit/compile.c
Expand Up @@ -123,19 +123,22 @@ MVMJitCode * MVM_jit_compiler_assemble(MVMThreadContext *tc, MVMJitCompiler *cl,

/* compile the function */
if ((dasm_error = dasm_link(cl, &codesize)) != 0) {
fprintf(stderr, "DynASM could not link, error: %d\n", dasm_error);
if (tc->instance->jit_debug_enabled)
fprintf(stderr, "DynASM could not link, error: %d\n", dasm_error);
return NULL;
}

memory = MVM_platform_alloc_pages(codesize, MVM_PAGE_READ|MVM_PAGE_WRITE);
if ((dasm_error = dasm_encode(cl, memory)) != 0) {
fprintf(stderr, "DynASM could not encode, error: %d\n", dasm_error);
if (tc->instance->jit_debug_enabled)
fprintf(stderr, "DynASM could not encode, error: %d\n", dasm_error);
return NULL;
}

/* set memory readable + executable */
if (!MVM_platform_set_page_mode(memory, codesize, MVM_PAGE_READ|MVM_PAGE_EXEC)) {
fprintf(stderr, "Setting jit page executable failed or was denied. deactivating jit.\n");
if (tc->instance->jit_debug_enabled)
fprintf(stderr, "JIT: Impossible to mark code read/executable");
/* our caller allocated the compiler and our caller must clean it up */
tc->instance->jit_enabled = 0;
return NULL;
Expand Down Expand Up @@ -171,8 +174,12 @@ MVMJitCode * MVM_jit_compiler_assemble(MVMThreadContext *tc, MVMJitCompiler *cl,

for (i = 0; i < code->num_labels; i++) {
MVMint32 offset = dasm_getpclabel(cl, i);
if (offset < 0)
fprintf(stderr, "JIT ERROR: Negative offset for dynamic label %d\n", i);
if (offset < 0) {
if (tc->instance->jit_debug_enabled)
fprintf(stderr, "JIT ERROR: Negative offset for dynamic label %d\n", i);
MVM_jit_code_destroy(tc, code);
return NULL;
}
code->labels[i] = memory + offset;
}
/* We only ever use one global label, which is the exit label */
Expand Down
18 changes: 5 additions & 13 deletions src/jit/dump.c
@@ -1,30 +1,22 @@
#include "moar.h"

void MVM_jit_dump_bytecode(MVMThreadContext *tc, MVMJitCode *code) {
/* Filename format: moar-jit-%d.bin. number can consume at most 10
* bytes, moar-jit-.bin is 13 bytes, one byte for the zero at the
* end, one byte for the directory separator is 25 bytes, plus the
* length of the bytecode directory itself */
size_t filename_size = strlen(tc->instance->jit_bytecode_dir) + 25;
char * filename = MVM_malloc(filename_size);
char filename[1024];
FILE * dump;
snprintf(filename, filename_size, "%s/moar-jit-%04d.bin",
snprintf(filename, sizeof(filename), "%s/moar-jit-%04d.bin",
tc->instance->jit_bytecode_dir, code->seq_nr);
dump = fopen(filename, "w");
if (dump) {
fwrite(code->func_ptr, sizeof(char), code->size, dump);
fclose(dump);
if (tc->instance->spesh_log_fh) {
fprintf(tc->instance->spesh_log_fh,
"JIT: Dumped bytecode to %s\n\n", filename);
}
} else {
if (MVM_spesh_debug_enabled(tc))
MVM_spesh_debug_printf(tc, "JIT: Dumped bytecode to %s\n\n", filename);
} else if (tc->instance->jit_debug_enabled) {
FILE *file = tc->instance->spesh_log_fh ?
tc->instance->spesh_log_fh : stderr;
fprintf(file, "JIT ERROR: could not dump bytecode: %s",
strerror(errno));
}
MVM_free(filename);
}


Expand Down

0 comments on commit 8c2dd3a

Please sign in to comment.