Skip to content

Commit

Permalink
Merge pull request #63 from lukego/auditlog
Browse files Browse the repository at this point in the history
Auditlog: Binary log of JIT and runtime behavior
  • Loading branch information
lukego authored Aug 6, 2018
2 parents a4f36d3 + 7e74425 commit 48b2be9
Show file tree
Hide file tree
Showing 23 changed files with 561 additions and 118 deletions.
4 changes: 2 additions & 2 deletions raptorjit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ mkDerivation rec {
buildInputs = [ luajit ]; # LuaJIT to bootstrap DynASM
dontStrip = true;
installPhase = ''
mkdir -p $out/bin
cp src/raptorjit $out/bin/raptorjit
install -D src/raptorjit $out/bin/raptorjit
install -D src/lj_dwarf.dwo $out/lib/raptorjit.dwo
'';

enableParallelBuilding = true; # Do 'make -j'
Expand Down
15 changes: 13 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,15 @@ LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \
lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \
lj_asm.o lj_trace.o lj_gdbjit.o \
lj_asm.o lj_trace.o lj_gdbjit.o lj_auditlog.o \
lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \
lj_carith.o lj_clib.o lj_cparse.o \
lj_lib.o lj_alloc.o lib_aux.o \
lj_dwarf_dwo.o \
$(LJLIB_O) lib_init.o

DWARF_DWO= lj_dwarf.dwo

LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)

Expand Down Expand Up @@ -271,7 +274,7 @@ E= @echo
# Make targets.
##############################################################################

default all: $(TARGET_T)
default all: $(TARGET_T) $(DWARF_DWO)

clean:
$(HOST_RM) $(ALL_RM)
Expand Down Expand Up @@ -377,10 +380,18 @@ $(HOST_O): %.o: %.c
$(E) "HOSTCC $@"
$(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<

$(DWARF_DWO): $(ALL_HDRGEN)

$(DWARF_DWO): %.dwo: %.c
$(E) "CC(debug) $@"
$(Q)$(TARGET_CC) -g3 -fno-eliminate-unused-debug-types -gsplit-dwarf -c $<

# Embed DWARF debug information as binary data available to raptorjit.
lj_dwarf_dwo.o lj_dwarf_dwo_dyn.o: $(DWARF_DWO)
$(E) "EMBED $@"
$(Q)$(LD) -r -b binary -o $@ $<
$(Q)$(LD) -shared -b binary -o $(@:.o=_dyn.o) $<

include Makefile.dep

##############################################################################
Expand Down
15 changes: 15 additions & 0 deletions src/lib_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "lj_dispatch.h"
#include "lj_vm.h"
#include "lj_lib.h"
#include "lj_auditlog.h"

#include "luajit.h"

Expand Down Expand Up @@ -80,6 +81,20 @@ LJLIB_CF(jit_flush)
return setjitmode(L, LUAJIT_MODE_FLUSH);
}

LJLIB_CF(jit_auditlog)
{
if (L->base < L->top && tvisstr(L->base)) {
/* XXX Support auditlog file size argument. */
if (lj_auditlog_open(strdata(lj_lib_checkstr(L, 1)), 0)) {
return 0;
} else {
lj_err_caller(L, LJ_ERR_AUDITLOG);
}
} else {
lj_err_argtype(L, 1, "string filename");
}
}

/* Push a string for every flag bit that is set. */
static void flagbits_to_strings(lua_State *L, uint32_t flags, uint32_t base,
const char *str)
Expand Down
12 changes: 8 additions & 4 deletions src/lj_asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,7 @@ void lj_asm_trace(jit_State *J, GCtrace *T)
{
ASMState as_;
ASMState *as = &as_;
MCode *origtop;
MCode *origtop, *firstins;

/* Remove nops/renames left over from ASM restart due to LJ_TRERR_MCODELM. */
{
Expand Down Expand Up @@ -2003,8 +2003,8 @@ void lj_asm_trace(jit_State *J, GCtrace *T)
as->parent = J->parent ? traceref(J, J->parent) : NULL;

/* Initialize mcode size of IR instructions array. */
T->szirmcode = lj_mem_new(J->L, T->nins * sizeof(*T->szirmcode));
memset(T->szirmcode, 0, T->nins * sizeof(*T->szirmcode));
T->szirmcode = lj_mem_new(J->L, (T->nins + 1) * sizeof(*T->szirmcode));
memset(T->szirmcode, 0, (T->nins + 1) * sizeof(*T->szirmcode));

/* Reserve MCode memory. */
as->mctop = origtop = lj_mcode_reserve(J, &as->mcbot);
Expand Down Expand Up @@ -2074,9 +2074,11 @@ void lj_asm_trace(jit_State *J, GCtrace *T)
RA_DBG_REF();
checkmclim(as);
asm_ir(as, ir);
T->szirmcode[as->curins] = (uint16_t)(end - as->mcp);
T->szirmcode[as->curins - REF_BIAS] = (uint16_t)((intptr_t)end - (intptr_t)as->mcp);
}

firstins = as->mcp; /* MCode assembled for IR instructions. */

if (as->realign && J->curfinal->nins >= T->nins)
continue; /* Retry in case only the MCode needs to be realigned. */

Expand All @@ -2101,6 +2103,8 @@ void lj_asm_trace(jit_State *J, GCtrace *T)
memcpy(J->curfinal->ir + as->orignins, T->ir + as->orignins,
(T->nins - as->orignins) * sizeof(IRIns)); /* Copy RENAMEs. */
T->nins = J->curfinal->nins;
/* Log size of trace head */
T->szirmcode[0] = (uint16_t)((intptr_t)firstins - (intptr_t)as->mcp);
break; /* Done. */
}

Expand Down
Loading

0 comments on commit 48b2be9

Please sign in to comment.