immunio 0.15.4 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +0 -27
- data/ext/immunio/Rakefile +9 -0
- data/lib/immunio/plugins/active_record.rb +1 -1
- data/lib/immunio/plugins/active_record_relation.rb +1 -1
- data/lib/immunio/plugins/environment_reporter.rb +20 -0
- data/lib/immunio/rufus_lua_ext/ref.rb +1 -3
- data/lib/immunio/version.rb +1 -1
- data/lib/immunio/vm.rb +1 -2
- data/lua-hooks/Makefile +97 -0
- data/lua-hooks/ext/all.c +41 -52
- data/lua-hooks/ext/all.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_html5.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_sqli.o +0 -0
- data/lua-hooks/ext/libinjection/libinjection_xss.o +0 -0
- data/lua-hooks/ext/libinjection/lualib.c +2 -2
- data/lua-hooks/ext/lpeg/lpcap.c +2 -2
- data/lua-hooks/ext/lpeg/lpcap.o +0 -0
- data/lua-hooks/ext/lpeg/lpcode.c +2 -2
- data/lua-hooks/ext/lpeg/lpcode.h +1 -1
- data/lua-hooks/ext/lpeg/lpcode.o +0 -0
- data/lua-hooks/ext/lpeg/lpprint.o +0 -0
- data/lua-hooks/ext/lpeg/lptree.c +2 -2
- data/lua-hooks/ext/lpeg/lptypes.h +1 -1
- data/lua-hooks/ext/lpeg/lpvm.c +2 -2
- data/lua-hooks/ext/lpeg/lpvm.o +0 -0
- data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +16 -3
- data/lua-hooks/ext/lua-snapshot/snapshot.c +14 -7
- data/lua-hooks/ext/luajit/COPYRIGHT +56 -0
- data/lua-hooks/ext/luajit/Makefile +159 -0
- data/lua-hooks/ext/luajit/README +16 -0
- data/lua-hooks/ext/luajit/doc/bluequad-print.css +166 -0
- data/lua-hooks/ext/luajit/doc/bluequad.css +325 -0
- data/lua-hooks/ext/luajit/doc/changes.html +804 -0
- data/lua-hooks/ext/luajit/doc/contact.html +104 -0
- data/lua-hooks/ext/luajit/doc/ext_c_api.html +189 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi.html +332 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +570 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +1261 -0
- data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +603 -0
- data/lua-hooks/ext/luajit/doc/ext_jit.html +201 -0
- data/lua-hooks/ext/luajit/doc/ext_profiler.html +365 -0
- data/lua-hooks/ext/luajit/doc/extensions.html +448 -0
- data/lua-hooks/ext/luajit/doc/faq.html +186 -0
- data/lua-hooks/ext/luajit/doc/img/contact.png +0 -0
- data/lua-hooks/ext/luajit/doc/install.html +659 -0
- data/lua-hooks/ext/luajit/doc/luajit.html +236 -0
- data/lua-hooks/ext/luajit/doc/running.html +309 -0
- data/lua-hooks/ext/luajit/doc/status.html +118 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +456 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1125 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +518 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1166 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +416 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +953 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +419 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1919 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +83 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +12 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +471 -0
- data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +1945 -0
- data/lua-hooks/ext/luajit/dynasm/dynasm.lua +1094 -0
- data/lua-hooks/ext/luajit/etc/luajit.1 +88 -0
- data/lua-hooks/ext/luajit/etc/luajit.pc +25 -0
- data/lua-hooks/ext/luajit/src/Makefile +697 -0
- data/lua-hooks/ext/luajit/src/Makefile.dep +244 -0
- data/lua-hooks/ext/luajit/src/host/README +4 -0
- data/lua-hooks/ext/luajit/src/host/buildvm +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.c +518 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.h +105 -0
- data/lua-hooks/ext/luajit/src/host/buildvm.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_arch.h +7449 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +345 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_asm.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +229 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_fold.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +457 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_lib.o +0 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +45 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +368 -0
- data/lua-hooks/ext/luajit/src/host/buildvm_peobj.o +0 -0
- data/lua-hooks/ext/luajit/src/host/genlibbc.lua +197 -0
- data/lua-hooks/ext/luajit/src/host/genminilua.lua +428 -0
- data/lua-hooks/ext/luajit/src/host/minilua +0 -0
- data/lua-hooks/ext/luajit/src/host/minilua.c +7770 -0
- data/lua-hooks/ext/luajit/src/host/minilua.o +0 -0
- data/lua-hooks/ext/luajit/src/jit/bc.lua +190 -0
- data/lua-hooks/ext/luajit/src/jit/bcsave.lua +661 -0
- data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +689 -0
- data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +428 -0
- data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +17 -0
- data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +591 -0
- data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +17 -0
- data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +838 -0
- data/lua-hooks/ext/luajit/src/jit/dump.lua +706 -0
- data/lua-hooks/ext/luajit/src/jit/p.lua +310 -0
- data/lua-hooks/ext/luajit/src/jit/v.lua +170 -0
- data/lua-hooks/ext/luajit/src/jit/vmdef.lua +362 -0
- data/lua-hooks/ext/luajit/src/jit/zone.lua +45 -0
- data/lua-hooks/ext/{lua → luajit/src}/lauxlib.h +10 -17
- data/lua-hooks/ext/luajit/src/lib_aux.c +356 -0
- data/lua-hooks/ext/luajit/src/lib_aux.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_aux_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_base.c +664 -0
- data/lua-hooks/ext/luajit/src/lib_base.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_base_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_bit.c +180 -0
- data/lua-hooks/ext/luajit/src/lib_bit.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_bit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_debug.c +405 -0
- data/lua-hooks/ext/luajit/src/lib_debug.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_debug_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_ffi.c +872 -0
- data/lua-hooks/ext/luajit/src/lib_ffi.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_ffi_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_init.c +55 -0
- data/lua-hooks/ext/luajit/src/lib_init.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_init_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_io.c +541 -0
- data/lua-hooks/ext/luajit/src/lib_io.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_io_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_jit.c +767 -0
- data/lua-hooks/ext/luajit/src/lib_jit.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_jit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_math.c +230 -0
- data/lua-hooks/ext/luajit/src/lib_math.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_math_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_os.c +292 -0
- data/lua-hooks/ext/luajit/src/lib_os.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_os_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_package.c +610 -0
- data/lua-hooks/ext/luajit/src/lib_package.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_package_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_string.c +752 -0
- data/lua-hooks/ext/luajit/src/lib_string.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_string_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_table.c +307 -0
- data/lua-hooks/ext/luajit/src/lib_table.o +0 -0
- data/lua-hooks/ext/luajit/src/lib_table_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/libluajit.a +0 -0
- data/lua-hooks/ext/luajit/src/libluajit.so +0 -0
- data/lua-hooks/ext/luajit/src/lj.supp +26 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.c +1398 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.h +17 -0
- data/lua-hooks/ext/luajit/src/lj_alloc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_alloc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_api.c +1210 -0
- data/lua-hooks/ext/luajit/src/lj_api.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_api_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_arch.h +509 -0
- data/lua-hooks/ext/luajit/src/lj_asm.c +2278 -0
- data/lua-hooks/ext/luajit/src/lj_asm.h +17 -0
- data/lua-hooks/ext/luajit/src/lj_asm.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_asm_arm.h +2217 -0
- data/lua-hooks/ext/luajit/src/lj_asm_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_asm_mips.h +1833 -0
- data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +2015 -0
- data/lua-hooks/ext/luajit/src/lj_asm_x86.h +2634 -0
- data/lua-hooks/ext/luajit/src/lj_bc.c +14 -0
- data/lua-hooks/ext/luajit/src/lj_bc.h +265 -0
- data/lua-hooks/ext/luajit/src/lj_bc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcdef.h +220 -0
- data/lua-hooks/ext/luajit/src/lj_bcdump.h +68 -0
- data/lua-hooks/ext/luajit/src/lj_bcread.c +457 -0
- data/lua-hooks/ext/luajit/src/lj_bcread.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcread_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite.c +361 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_bcwrite_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_buf.c +234 -0
- data/lua-hooks/ext/luajit/src/lj_buf.h +105 -0
- data/lua-hooks/ext/luajit/src/lj_buf.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_buf_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_carith.c +429 -0
- data/lua-hooks/ext/luajit/src/lj_carith.h +37 -0
- data/lua-hooks/ext/luajit/src/lj_carith.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_carith_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.c +984 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.h +178 -0
- data/lua-hooks/ext/luajit/src/lj_ccall.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccall_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.c +712 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.h +25 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ccallback_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.c +752 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.h +70 -0
- data/lua-hooks/ext/luajit/src/lj_cconv.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cconv_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.c +288 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.h +76 -0
- data/lua-hooks/ext/luajit/src/lj_cdata.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cdata_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_char.c +43 -0
- data/lua-hooks/ext/luajit/src/lj_char.h +42 -0
- data/lua-hooks/ext/luajit/src/lj_char.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_char_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_clib.c +418 -0
- data/lua-hooks/ext/luajit/src/lj_clib.h +29 -0
- data/lua-hooks/ext/luajit/src/lj_clib.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_clib_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.c +1862 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.h +65 -0
- data/lua-hooks/ext/luajit/src/lj_cparse.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_cparse_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.c +1834 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.h +38 -0
- data/lua-hooks/ext/luajit/src/lj_crecord.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_crecord_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.c +635 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.h +461 -0
- data/lua-hooks/ext/luajit/src/lj_ctype.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ctype_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_debug.c +699 -0
- data/lua-hooks/ext/luajit/src/lj_debug.h +65 -0
- data/lua-hooks/ext/luajit/src/lj_debug.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_debug_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_def.h +365 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.c +557 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.h +138 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_dispatch_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_emit_arm.h +356 -0
- data/lua-hooks/ext/luajit/src/lj_emit_mips.h +211 -0
- data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +238 -0
- data/lua-hooks/ext/luajit/src/lj_emit_x86.h +462 -0
- data/lua-hooks/ext/luajit/src/lj_err.c +794 -0
- data/lua-hooks/ext/luajit/src/lj_err.h +41 -0
- data/lua-hooks/ext/luajit/src/lj_err.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_err_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_errmsg.h +190 -0
- data/lua-hooks/ext/luajit/src/lj_ff.h +18 -0
- data/lua-hooks/ext/luajit/src/lj_ffdef.h +209 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.c +1247 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.h +24 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ffrecord_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_folddef.h +1138 -0
- data/lua-hooks/ext/luajit/src/lj_frame.h +259 -0
- data/lua-hooks/ext/luajit/src/lj_func.c +185 -0
- data/lua-hooks/ext/luajit/src/lj_func.h +24 -0
- data/lua-hooks/ext/luajit/src/lj_func.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_func_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gc.c +845 -0
- data/lua-hooks/ext/luajit/src/lj_gc.h +134 -0
- data/lua-hooks/ext/luajit/src/lj_gc.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gc_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.c +787 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.h +22 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_gdbjit_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ir.c +505 -0
- data/lua-hooks/ext/luajit/src/lj_ir.h +577 -0
- data/lua-hooks/ext/luajit/src/lj_ir.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ir_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_ircall.h +321 -0
- data/lua-hooks/ext/luajit/src/lj_iropt.h +161 -0
- data/lua-hooks/ext/luajit/src/lj_jit.h +440 -0
- data/lua-hooks/ext/luajit/src/lj_lex.c +482 -0
- data/lua-hooks/ext/luajit/src/lj_lex.h +86 -0
- data/lua-hooks/ext/luajit/src/lj_lex.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lex_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lib.c +303 -0
- data/lua-hooks/ext/luajit/src/lj_lib.h +115 -0
- data/lua-hooks/ext/luajit/src/lj_lib.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_lib_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_libdef.h +414 -0
- data/lua-hooks/ext/luajit/src/lj_load.c +168 -0
- data/lua-hooks/ext/luajit/src/lj_load.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_load_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.c +386 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.h +30 -0
- data/lua-hooks/ext/luajit/src/lj_mcode.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_mcode_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_meta.c +477 -0
- data/lua-hooks/ext/luajit/src/lj_meta.h +38 -0
- data/lua-hooks/ext/luajit/src/lj_meta.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_meta_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_obj.c +50 -0
- data/lua-hooks/ext/luajit/src/lj_obj.h +976 -0
- data/lua-hooks/ext/luajit/src/lj_obj.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_obj_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce.c +78 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_dce_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold.c +2488 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_fold_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop.c +449 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_loop_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem.c +935 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_mem_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +652 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_narrow_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink.c +245 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_sink_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split.c +856 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_opt_split_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_parse.c +2725 -0
- data/lua-hooks/ext/luajit/src/lj_parse.h +18 -0
- data/lua-hooks/ext/luajit/src/lj_parse.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_parse_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_profile.c +368 -0
- data/lua-hooks/ext/luajit/src/lj_profile.h +21 -0
- data/lua-hooks/ext/luajit/src/lj_profile.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_profile_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_recdef.h +270 -0
- data/lua-hooks/ext/luajit/src/lj_record.c +2554 -0
- data/lua-hooks/ext/luajit/src/lj_record.h +45 -0
- data/lua-hooks/ext/luajit/src/lj_record.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_record_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_snap.c +870 -0
- data/lua-hooks/ext/luajit/src/lj_snap.h +34 -0
- data/lua-hooks/ext/luajit/src/lj_snap.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_snap_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_state.c +300 -0
- data/lua-hooks/ext/luajit/src/lj_state.h +35 -0
- data/lua-hooks/ext/luajit/src/lj_state.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_state_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_str.c +197 -0
- data/lua-hooks/ext/luajit/src/lj_str.h +27 -0
- data/lua-hooks/ext/luajit/src/lj_str.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_str_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.c +554 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.h +125 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strfmt_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.c +547 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.h +39 -0
- data/lua-hooks/ext/luajit/src/lj_strscan.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_strscan_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_tab.c +666 -0
- data/lua-hooks/ext/luajit/src/lj_tab.h +73 -0
- data/lua-hooks/ext/luajit/src/lj_tab.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_tab_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_target.h +164 -0
- data/lua-hooks/ext/luajit/src/lj_target_arm.h +270 -0
- data/lua-hooks/ext/luajit/src/lj_target_arm64.h +97 -0
- data/lua-hooks/ext/luajit/src/lj_target_mips.h +260 -0
- data/lua-hooks/ext/luajit/src/lj_target_ppc.h +280 -0
- data/lua-hooks/ext/luajit/src/lj_target_x86.h +345 -0
- data/lua-hooks/ext/luajit/src/lj_trace.c +859 -0
- data/lua-hooks/ext/luajit/src/lj_trace.h +54 -0
- data/lua-hooks/ext/luajit/src/lj_trace.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_trace_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_traceerr.h +63 -0
- data/lua-hooks/ext/luajit/src/lj_udata.c +34 -0
- data/lua-hooks/ext/luajit/src/lj_udata.h +14 -0
- data/lua-hooks/ext/luajit/src/lj_udata.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_udata_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vm.S +2730 -0
- data/lua-hooks/ext/luajit/src/lj_vm.h +114 -0
- data/lua-hooks/ext/luajit/src/lj_vm.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vm_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.c +58 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.h +59 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmevent_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath.c +152 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath.o +0 -0
- data/lua-hooks/ext/luajit/src/lj_vmmath_dyn.o +0 -0
- data/lua-hooks/ext/luajit/src/ljamalg.c +96 -0
- data/lua-hooks/ext/{lua → luajit/src}/lua.h +12 -7
- data/lua-hooks/ext/luajit/src/lua.hpp +9 -0
- data/lua-hooks/ext/luajit/src/luaconf.h +156 -0
- data/lua-hooks/ext/luajit/src/luajit +0 -0
- data/lua-hooks/ext/luajit/src/luajit.c +570 -0
- data/lua-hooks/ext/luajit/src/luajit.h +79 -0
- data/lua-hooks/ext/luajit/src/luajit.o +0 -0
- data/lua-hooks/ext/luajit/src/lualib.h +43 -0
- data/lua-hooks/ext/luajit/src/msvcbuild.bat +114 -0
- data/lua-hooks/ext/luajit/src/ps4build.bat +103 -0
- data/lua-hooks/ext/luajit/src/psvitabuild.bat +93 -0
- data/lua-hooks/ext/luajit/src/vm_arm.dasc +4585 -0
- data/lua-hooks/ext/luajit/src/vm_arm64.dasc +3764 -0
- data/lua-hooks/ext/luajit/src/vm_mips.dasc +4355 -0
- data/lua-hooks/ext/luajit/src/vm_ppc.dasc +5252 -0
- data/lua-hooks/ext/luajit/src/vm_x64.dasc +4902 -0
- data/lua-hooks/ext/luajit/src/vm_x86.dasc +5710 -0
- data/lua-hooks/ext/luajit/src/xb1build.bat +101 -0
- data/lua-hooks/ext/luajit/src/xedkbuild.bat +92 -0
- data/lua-hooks/ext/luautf8/lutf8lib.c +3 -3
- data/lua-hooks/lib/boot.lua +37 -2
- metadata +372 -69
- data/lua-hooks/ext/bitop/README +0 -22
- data/lua-hooks/ext/bitop/bit.c +0 -189
- data/lua-hooks/ext/extconf.rb +0 -38
- data/lua-hooks/ext/lua/COPYRIGHT +0 -34
- data/lua-hooks/ext/lua/lapi.c +0 -1087
- data/lua-hooks/ext/lua/lapi.h +0 -16
- data/lua-hooks/ext/lua/lauxlib.c +0 -652
- data/lua-hooks/ext/lua/lbaselib.c +0 -659
- data/lua-hooks/ext/lua/lcode.c +0 -831
- data/lua-hooks/ext/lua/lcode.h +0 -76
- data/lua-hooks/ext/lua/ldblib.c +0 -398
- data/lua-hooks/ext/lua/ldebug.c +0 -638
- data/lua-hooks/ext/lua/ldebug.h +0 -33
- data/lua-hooks/ext/lua/ldo.c +0 -519
- data/lua-hooks/ext/lua/ldo.h +0 -57
- data/lua-hooks/ext/lua/ldump.c +0 -164
- data/lua-hooks/ext/lua/lfunc.c +0 -174
- data/lua-hooks/ext/lua/lfunc.h +0 -34
- data/lua-hooks/ext/lua/lgc.c +0 -710
- data/lua-hooks/ext/lua/lgc.h +0 -110
- data/lua-hooks/ext/lua/linit.c +0 -38
- data/lua-hooks/ext/lua/liolib.c +0 -556
- data/lua-hooks/ext/lua/llex.c +0 -463
- data/lua-hooks/ext/lua/llex.h +0 -81
- data/lua-hooks/ext/lua/llimits.h +0 -128
- data/lua-hooks/ext/lua/lmathlib.c +0 -263
- data/lua-hooks/ext/lua/lmem.c +0 -86
- data/lua-hooks/ext/lua/lmem.h +0 -49
- data/lua-hooks/ext/lua/loadlib.c +0 -705
- data/lua-hooks/ext/lua/loadlib_rel.c +0 -760
- data/lua-hooks/ext/lua/lobject.c +0 -214
- data/lua-hooks/ext/lua/lobject.h +0 -381
- data/lua-hooks/ext/lua/lopcodes.c +0 -102
- data/lua-hooks/ext/lua/lopcodes.h +0 -268
- data/lua-hooks/ext/lua/loslib.c +0 -243
- data/lua-hooks/ext/lua/lparser.c +0 -1339
- data/lua-hooks/ext/lua/lparser.h +0 -82
- data/lua-hooks/ext/lua/lstate.c +0 -214
- data/lua-hooks/ext/lua/lstate.h +0 -169
- data/lua-hooks/ext/lua/lstring.c +0 -111
- data/lua-hooks/ext/lua/lstring.h +0 -31
- data/lua-hooks/ext/lua/lstrlib.c +0 -871
- data/lua-hooks/ext/lua/ltable.c +0 -588
- data/lua-hooks/ext/lua/ltable.h +0 -40
- data/lua-hooks/ext/lua/ltablib.c +0 -287
- data/lua-hooks/ext/lua/ltm.c +0 -75
- data/lua-hooks/ext/lua/ltm.h +0 -54
- data/lua-hooks/ext/lua/lua.c +0 -392
- data/lua-hooks/ext/lua/lua.def +0 -131
- data/lua-hooks/ext/lua/lua.rc +0 -28
- data/lua-hooks/ext/lua/lua_dll.rc +0 -26
- data/lua-hooks/ext/lua/luac.c +0 -200
- data/lua-hooks/ext/lua/luac.rc +0 -1
- data/lua-hooks/ext/lua/luaconf.h +0 -763
- data/lua-hooks/ext/lua/luaconf.h.in +0 -724
- data/lua-hooks/ext/lua/luaconf.h.orig +0 -763
- data/lua-hooks/ext/lua/lualib.h +0 -53
- data/lua-hooks/ext/lua/lundump.c +0 -227
- data/lua-hooks/ext/lua/lundump.h +0 -36
- data/lua-hooks/ext/lua/lvm.c +0 -767
- data/lua-hooks/ext/lua/lvm.h +0 -36
- data/lua-hooks/ext/lua/lzio.c +0 -82
- data/lua-hooks/ext/lua/lzio.h +0 -67
- data/lua-hooks/ext/lua/print.c +0 -227
Binary file
|
Binary file
|
@@ -0,0 +1,845 @@
|
|
1
|
+
/*
|
2
|
+
** Garbage collector.
|
3
|
+
** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
|
4
|
+
**
|
5
|
+
** Major portions taken verbatim or adapted from the Lua interpreter.
|
6
|
+
** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
|
7
|
+
*/
|
8
|
+
|
9
|
+
#define lj_gc_c
|
10
|
+
#define LUA_CORE
|
11
|
+
|
12
|
+
#include "lj_obj.h"
|
13
|
+
#include "lj_gc.h"
|
14
|
+
#include "lj_err.h"
|
15
|
+
#include "lj_buf.h"
|
16
|
+
#include "lj_str.h"
|
17
|
+
#include "lj_tab.h"
|
18
|
+
#include "lj_func.h"
|
19
|
+
#include "lj_udata.h"
|
20
|
+
#include "lj_meta.h"
|
21
|
+
#include "lj_state.h"
|
22
|
+
#include "lj_frame.h"
|
23
|
+
#if LJ_HASFFI
|
24
|
+
#include "lj_ctype.h"
|
25
|
+
#include "lj_cdata.h"
|
26
|
+
#endif
|
27
|
+
#include "lj_trace.h"
|
28
|
+
#include "lj_vm.h"
|
29
|
+
|
30
|
+
#define GCSTEPSIZE 1024u
|
31
|
+
#define GCSWEEPMAX 40
|
32
|
+
#define GCSWEEPCOST 10
|
33
|
+
#define GCFINALIZECOST 100
|
34
|
+
|
35
|
+
/* Macros to set GCobj colors and flags. */
|
36
|
+
#define white2gray(x) ((x)->gch.marked &= (uint8_t)~LJ_GC_WHITES)
|
37
|
+
#define gray2black(x) ((x)->gch.marked |= LJ_GC_BLACK)
|
38
|
+
#define isfinalized(u) ((u)->marked & LJ_GC_FINALIZED)
|
39
|
+
|
40
|
+
/* -- Mark phase ---------------------------------------------------------- */
|
41
|
+
|
42
|
+
/* Mark a TValue (if needed). */
|
43
|
+
#define gc_marktv(g, tv) \
|
44
|
+
{ lua_assert(!tvisgcv(tv) || (~itype(tv) == gcval(tv)->gch.gct)); \
|
45
|
+
if (tviswhite(tv)) gc_mark(g, gcV(tv)); }
|
46
|
+
|
47
|
+
/* Mark a GCobj (if needed). */
|
48
|
+
#define gc_markobj(g, o) \
|
49
|
+
{ if (iswhite(obj2gco(o))) gc_mark(g, obj2gco(o)); }
|
50
|
+
|
51
|
+
/* Mark a string object. */
|
52
|
+
#define gc_mark_str(s) ((s)->marked &= (uint8_t)~LJ_GC_WHITES)
|
53
|
+
|
54
|
+
/* Mark a white GCobj. */
|
55
|
+
static void gc_mark(global_State *g, GCobj *o)
|
56
|
+
{
|
57
|
+
int gct = o->gch.gct;
|
58
|
+
lua_assert(iswhite(o) && !isdead(g, o));
|
59
|
+
white2gray(o);
|
60
|
+
if (LJ_UNLIKELY(gct == ~LJ_TUDATA)) {
|
61
|
+
GCtab *mt = tabref(gco2ud(o)->metatable);
|
62
|
+
gray2black(o); /* Userdata are never gray. */
|
63
|
+
if (mt) gc_markobj(g, mt);
|
64
|
+
gc_markobj(g, tabref(gco2ud(o)->env));
|
65
|
+
} else if (LJ_UNLIKELY(gct == ~LJ_TUPVAL)) {
|
66
|
+
GCupval *uv = gco2uv(o);
|
67
|
+
gc_marktv(g, uvval(uv));
|
68
|
+
if (uv->closed)
|
69
|
+
gray2black(o); /* Closed upvalues are never gray. */
|
70
|
+
} else if (gct != ~LJ_TSTR && gct != ~LJ_TCDATA) {
|
71
|
+
lua_assert(gct == ~LJ_TFUNC || gct == ~LJ_TTAB ||
|
72
|
+
gct == ~LJ_TTHREAD || gct == ~LJ_TPROTO);
|
73
|
+
setgcrefr(o->gch.gclist, g->gc.gray);
|
74
|
+
setgcref(g->gc.gray, o);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
/* Mark GC roots. */
|
79
|
+
static void gc_mark_gcroot(global_State *g)
|
80
|
+
{
|
81
|
+
ptrdiff_t i;
|
82
|
+
for (i = 0; i < GCROOT_MAX; i++)
|
83
|
+
if (gcref(g->gcroot[i]) != NULL)
|
84
|
+
gc_markobj(g, gcref(g->gcroot[i]));
|
85
|
+
}
|
86
|
+
|
87
|
+
/* Start a GC cycle and mark the root set. */
|
88
|
+
static void gc_mark_start(global_State *g)
|
89
|
+
{
|
90
|
+
setgcrefnull(g->gc.gray);
|
91
|
+
setgcrefnull(g->gc.grayagain);
|
92
|
+
setgcrefnull(g->gc.weak);
|
93
|
+
gc_markobj(g, mainthread(g));
|
94
|
+
gc_markobj(g, tabref(mainthread(g)->env));
|
95
|
+
gc_marktv(g, &g->registrytv);
|
96
|
+
gc_mark_gcroot(g);
|
97
|
+
g->gc.state = GCSpropagate;
|
98
|
+
}
|
99
|
+
|
100
|
+
/* Mark open upvalues. */
|
101
|
+
static void gc_mark_uv(global_State *g)
|
102
|
+
{
|
103
|
+
GCupval *uv;
|
104
|
+
for (uv = uvnext(&g->uvhead); uv != &g->uvhead; uv = uvnext(uv)) {
|
105
|
+
lua_assert(uvprev(uvnext(uv)) == uv && uvnext(uvprev(uv)) == uv);
|
106
|
+
if (isgray(obj2gco(uv)))
|
107
|
+
gc_marktv(g, uvval(uv));
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
/* Mark userdata in mmudata list. */
|
112
|
+
static void gc_mark_mmudata(global_State *g)
|
113
|
+
{
|
114
|
+
GCobj *root = gcref(g->gc.mmudata);
|
115
|
+
GCobj *u = root;
|
116
|
+
if (u) {
|
117
|
+
do {
|
118
|
+
u = gcnext(u);
|
119
|
+
makewhite(g, u); /* Could be from previous GC. */
|
120
|
+
gc_mark(g, u);
|
121
|
+
} while (u != root);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
/* Separate userdata objects to be finalized to mmudata list. */
|
126
|
+
size_t lj_gc_separateudata(global_State *g, int all)
|
127
|
+
{
|
128
|
+
size_t m = 0;
|
129
|
+
GCRef *p = &mainthread(g)->nextgc;
|
130
|
+
GCobj *o;
|
131
|
+
while ((o = gcref(*p)) != NULL) {
|
132
|
+
if (!(iswhite(o) || all) || isfinalized(gco2ud(o))) {
|
133
|
+
p = &o->gch.nextgc; /* Nothing to do. */
|
134
|
+
} else if (!lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc)) {
|
135
|
+
markfinalized(o); /* Done, as there's no __gc metamethod. */
|
136
|
+
p = &o->gch.nextgc;
|
137
|
+
} else { /* Otherwise move userdata to be finalized to mmudata list. */
|
138
|
+
m += sizeudata(gco2ud(o));
|
139
|
+
markfinalized(o);
|
140
|
+
*p = o->gch.nextgc;
|
141
|
+
if (gcref(g->gc.mmudata)) { /* Link to end of mmudata list. */
|
142
|
+
GCobj *root = gcref(g->gc.mmudata);
|
143
|
+
setgcrefr(o->gch.nextgc, root->gch.nextgc);
|
144
|
+
setgcref(root->gch.nextgc, o);
|
145
|
+
setgcref(g->gc.mmudata, o);
|
146
|
+
} else { /* Create circular list. */
|
147
|
+
setgcref(o->gch.nextgc, o);
|
148
|
+
setgcref(g->gc.mmudata, o);
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
return m;
|
153
|
+
}
|
154
|
+
|
155
|
+
/* -- Propagation phase --------------------------------------------------- */
|
156
|
+
|
157
|
+
/* Traverse a table. */
|
158
|
+
static int gc_traverse_tab(global_State *g, GCtab *t)
|
159
|
+
{
|
160
|
+
int weak = 0;
|
161
|
+
cTValue *mode;
|
162
|
+
GCtab *mt = tabref(t->metatable);
|
163
|
+
if (mt)
|
164
|
+
gc_markobj(g, mt);
|
165
|
+
mode = lj_meta_fastg(g, mt, MM_mode);
|
166
|
+
if (mode && tvisstr(mode)) { /* Valid __mode field? */
|
167
|
+
const char *modestr = strVdata(mode);
|
168
|
+
int c;
|
169
|
+
while ((c = *modestr++)) {
|
170
|
+
if (c == 'k') weak |= LJ_GC_WEAKKEY;
|
171
|
+
else if (c == 'v') weak |= LJ_GC_WEAKVAL;
|
172
|
+
else if (c == 'K') weak = (int)(~0u & ~LJ_GC_WEAKVAL);
|
173
|
+
}
|
174
|
+
if (weak > 0) { /* Weak tables are cleared in the atomic phase. */
|
175
|
+
t->marked = (uint8_t)((t->marked & ~LJ_GC_WEAK) | weak);
|
176
|
+
setgcrefr(t->gclist, g->gc.weak);
|
177
|
+
setgcref(g->gc.weak, obj2gco(t));
|
178
|
+
}
|
179
|
+
}
|
180
|
+
if (weak == LJ_GC_WEAK) /* Nothing to mark if both keys/values are weak. */
|
181
|
+
return 1;
|
182
|
+
if (!(weak & LJ_GC_WEAKVAL)) { /* Mark array part. */
|
183
|
+
MSize i, asize = t->asize;
|
184
|
+
for (i = 0; i < asize; i++)
|
185
|
+
gc_marktv(g, arrayslot(t, i));
|
186
|
+
}
|
187
|
+
if (t->hmask > 0) { /* Mark hash part. */
|
188
|
+
Node *node = noderef(t->node);
|
189
|
+
MSize i, hmask = t->hmask;
|
190
|
+
for (i = 0; i <= hmask; i++) {
|
191
|
+
Node *n = &node[i];
|
192
|
+
if (!tvisnil(&n->val)) { /* Mark non-empty slot. */
|
193
|
+
lua_assert(!tvisnil(&n->key));
|
194
|
+
if (!(weak & LJ_GC_WEAKKEY)) gc_marktv(g, &n->key);
|
195
|
+
if (!(weak & LJ_GC_WEAKVAL)) gc_marktv(g, &n->val);
|
196
|
+
}
|
197
|
+
}
|
198
|
+
}
|
199
|
+
return weak;
|
200
|
+
}
|
201
|
+
|
202
|
+
/* Traverse a function. */
|
203
|
+
static void gc_traverse_func(global_State *g, GCfunc *fn)
|
204
|
+
{
|
205
|
+
gc_markobj(g, tabref(fn->c.env));
|
206
|
+
if (isluafunc(fn)) {
|
207
|
+
uint32_t i;
|
208
|
+
lua_assert(fn->l.nupvalues <= funcproto(fn)->sizeuv);
|
209
|
+
gc_markobj(g, funcproto(fn));
|
210
|
+
for (i = 0; i < fn->l.nupvalues; i++) /* Mark Lua function upvalues. */
|
211
|
+
gc_markobj(g, &gcref(fn->l.uvptr[i])->uv);
|
212
|
+
} else {
|
213
|
+
uint32_t i;
|
214
|
+
for (i = 0; i < fn->c.nupvalues; i++) /* Mark C function upvalues. */
|
215
|
+
gc_marktv(g, &fn->c.upvalue[i]);
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
#if LJ_HASJIT
|
220
|
+
/* Mark a trace. */
|
221
|
+
static void gc_marktrace(global_State *g, TraceNo traceno)
|
222
|
+
{
|
223
|
+
GCobj *o = obj2gco(traceref(G2J(g), traceno));
|
224
|
+
lua_assert(traceno != G2J(g)->cur.traceno);
|
225
|
+
if (iswhite(o)) {
|
226
|
+
white2gray(o);
|
227
|
+
setgcrefr(o->gch.gclist, g->gc.gray);
|
228
|
+
setgcref(g->gc.gray, o);
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
/* Traverse a trace. */
|
233
|
+
static void gc_traverse_trace(global_State *g, GCtrace *T)
|
234
|
+
{
|
235
|
+
IRRef ref;
|
236
|
+
if (T->traceno == 0) return;
|
237
|
+
for (ref = T->nk; ref < REF_TRUE; ref++) {
|
238
|
+
IRIns *ir = &T->ir[ref];
|
239
|
+
if (ir->o == IR_KGC)
|
240
|
+
gc_markobj(g, ir_kgc(ir));
|
241
|
+
}
|
242
|
+
if (T->link) gc_marktrace(g, T->link);
|
243
|
+
if (T->nextroot) gc_marktrace(g, T->nextroot);
|
244
|
+
if (T->nextside) gc_marktrace(g, T->nextside);
|
245
|
+
gc_markobj(g, gcref(T->startpt));
|
246
|
+
}
|
247
|
+
|
248
|
+
/* The current trace is a GC root while not anchored in the prototype (yet). */
|
249
|
+
#define gc_traverse_curtrace(g) gc_traverse_trace(g, &G2J(g)->cur)
|
250
|
+
#else
|
251
|
+
#define gc_traverse_curtrace(g) UNUSED(g)
|
252
|
+
#endif
|
253
|
+
|
254
|
+
/* Traverse a prototype. */
|
255
|
+
static void gc_traverse_proto(global_State *g, GCproto *pt)
|
256
|
+
{
|
257
|
+
ptrdiff_t i;
|
258
|
+
gc_mark_str(proto_chunkname(pt));
|
259
|
+
for (i = -(ptrdiff_t)pt->sizekgc; i < 0; i++) /* Mark collectable consts. */
|
260
|
+
gc_markobj(g, proto_kgc(pt, i));
|
261
|
+
#if LJ_HASJIT
|
262
|
+
if (pt->trace) gc_marktrace(g, pt->trace);
|
263
|
+
#endif
|
264
|
+
}
|
265
|
+
|
266
|
+
/* Traverse the frame structure of a stack. */
|
267
|
+
static MSize gc_traverse_frames(global_State *g, lua_State *th)
|
268
|
+
{
|
269
|
+
TValue *frame, *top = th->top-1, *bot = tvref(th->stack);
|
270
|
+
/* Note: extra vararg frame not skipped, marks function twice (harmless). */
|
271
|
+
for (frame = th->base-1; frame > bot+LJ_FR2; frame = frame_prev(frame)) {
|
272
|
+
GCfunc *fn = frame_func(frame);
|
273
|
+
TValue *ftop = frame;
|
274
|
+
if (isluafunc(fn)) ftop += funcproto(fn)->framesize;
|
275
|
+
if (ftop > top) top = ftop;
|
276
|
+
if (!LJ_FR2) gc_markobj(g, fn); /* Need to mark hidden function (or L). */
|
277
|
+
}
|
278
|
+
top++; /* Correct bias of -1 (frame == base-1). */
|
279
|
+
if (top > tvref(th->maxstack)) top = tvref(th->maxstack);
|
280
|
+
return (MSize)(top - bot); /* Return minimum needed stack size. */
|
281
|
+
}
|
282
|
+
|
283
|
+
/* Traverse a thread object. */
|
284
|
+
static void gc_traverse_thread(global_State *g, lua_State *th)
|
285
|
+
{
|
286
|
+
TValue *o, *top = th->top;
|
287
|
+
for (o = tvref(th->stack)+1+LJ_FR2; o < top; o++)
|
288
|
+
gc_marktv(g, o);
|
289
|
+
if (g->gc.state == GCSatomic) {
|
290
|
+
top = tvref(th->stack) + th->stacksize;
|
291
|
+
for (; o < top; o++) /* Clear unmarked slots. */
|
292
|
+
setnilV(o);
|
293
|
+
}
|
294
|
+
gc_markobj(g, tabref(th->env));
|
295
|
+
lj_state_shrinkstack(th, gc_traverse_frames(g, th));
|
296
|
+
}
|
297
|
+
|
298
|
+
/* Propagate one gray object. Traverse it and turn it black. */
|
299
|
+
static size_t propagatemark(global_State *g)
|
300
|
+
{
|
301
|
+
GCobj *o = gcref(g->gc.gray);
|
302
|
+
int gct = o->gch.gct;
|
303
|
+
lua_assert(isgray(o));
|
304
|
+
gray2black(o);
|
305
|
+
setgcrefr(g->gc.gray, o->gch.gclist); /* Remove from gray list. */
|
306
|
+
if (LJ_LIKELY(gct == ~LJ_TTAB)) {
|
307
|
+
GCtab *t = gco2tab(o);
|
308
|
+
if (gc_traverse_tab(g, t) > 0)
|
309
|
+
black2gray(o); /* Keep weak tables gray. */
|
310
|
+
return sizeof(GCtab) + sizeof(TValue) * t->asize +
|
311
|
+
sizeof(Node) * (t->hmask + 1);
|
312
|
+
} else if (LJ_LIKELY(gct == ~LJ_TFUNC)) {
|
313
|
+
GCfunc *fn = gco2func(o);
|
314
|
+
gc_traverse_func(g, fn);
|
315
|
+
return isluafunc(fn) ? sizeLfunc((MSize)fn->l.nupvalues) :
|
316
|
+
sizeCfunc((MSize)fn->c.nupvalues);
|
317
|
+
} else if (LJ_LIKELY(gct == ~LJ_TPROTO)) {
|
318
|
+
GCproto *pt = gco2pt(o);
|
319
|
+
gc_traverse_proto(g, pt);
|
320
|
+
return pt->sizept;
|
321
|
+
} else if (LJ_LIKELY(gct == ~LJ_TTHREAD)) {
|
322
|
+
lua_State *th = gco2th(o);
|
323
|
+
setgcrefr(th->gclist, g->gc.grayagain);
|
324
|
+
setgcref(g->gc.grayagain, o);
|
325
|
+
black2gray(o); /* Threads are never black. */
|
326
|
+
gc_traverse_thread(g, th);
|
327
|
+
return sizeof(lua_State) + sizeof(TValue) * th->stacksize;
|
328
|
+
} else {
|
329
|
+
#if LJ_HASJIT
|
330
|
+
GCtrace *T = gco2trace(o);
|
331
|
+
gc_traverse_trace(g, T);
|
332
|
+
return ((sizeof(GCtrace)+7)&~7) + (T->nins-T->nk)*sizeof(IRIns) +
|
333
|
+
T->nsnap*sizeof(SnapShot) + T->nsnapmap*sizeof(SnapEntry);
|
334
|
+
#else
|
335
|
+
lua_assert(0);
|
336
|
+
return 0;
|
337
|
+
#endif
|
338
|
+
}
|
339
|
+
}
|
340
|
+
|
341
|
+
/* Propagate all gray objects. */
|
342
|
+
static size_t gc_propagate_gray(global_State *g)
|
343
|
+
{
|
344
|
+
size_t m = 0;
|
345
|
+
while (gcref(g->gc.gray) != NULL)
|
346
|
+
m += propagatemark(g);
|
347
|
+
return m;
|
348
|
+
}
|
349
|
+
|
350
|
+
/* -- Sweep phase --------------------------------------------------------- */
|
351
|
+
|
352
|
+
/* Type of GC free functions. */
|
353
|
+
typedef void (LJ_FASTCALL *GCFreeFunc)(global_State *g, GCobj *o);
|
354
|
+
|
355
|
+
/* GC free functions for LJ_TSTR .. LJ_TUDATA. ORDER LJ_T */
|
356
|
+
static const GCFreeFunc gc_freefunc[] = {
|
357
|
+
(GCFreeFunc)lj_str_free,
|
358
|
+
(GCFreeFunc)lj_func_freeuv,
|
359
|
+
(GCFreeFunc)lj_state_free,
|
360
|
+
(GCFreeFunc)lj_func_freeproto,
|
361
|
+
(GCFreeFunc)lj_func_free,
|
362
|
+
#if LJ_HASJIT
|
363
|
+
(GCFreeFunc)lj_trace_free,
|
364
|
+
#else
|
365
|
+
(GCFreeFunc)0,
|
366
|
+
#endif
|
367
|
+
#if LJ_HASFFI
|
368
|
+
(GCFreeFunc)lj_cdata_free,
|
369
|
+
#else
|
370
|
+
(GCFreeFunc)0,
|
371
|
+
#endif
|
372
|
+
(GCFreeFunc)lj_tab_free,
|
373
|
+
(GCFreeFunc)lj_udata_free
|
374
|
+
};
|
375
|
+
|
376
|
+
/* Full sweep of a GC list. */
|
377
|
+
#define gc_fullsweep(g, p) gc_sweep(g, (p), ~(uint32_t)0)
|
378
|
+
|
379
|
+
/* Partial sweep of a GC list. */
|
380
|
+
static GCRef *gc_sweep(global_State *g, GCRef *p, uint32_t lim)
|
381
|
+
{
|
382
|
+
/* Mask with other white and LJ_GC_FIXED. Or LJ_GC_SFIXED on shutdown. */
|
383
|
+
int ow = otherwhite(g);
|
384
|
+
GCobj *o;
|
385
|
+
while ((o = gcref(*p)) != NULL && lim-- > 0) {
|
386
|
+
if (o->gch.gct == ~LJ_TTHREAD) /* Need to sweep open upvalues, too. */
|
387
|
+
gc_fullsweep(g, &gco2th(o)->openupval);
|
388
|
+
if (((o->gch.marked ^ LJ_GC_WHITES) & ow)) { /* Black or current white? */
|
389
|
+
lua_assert(!isdead(g, o) || (o->gch.marked & LJ_GC_FIXED));
|
390
|
+
makewhite(g, o); /* Value is alive, change to the current white. */
|
391
|
+
p = &o->gch.nextgc;
|
392
|
+
} else { /* Otherwise value is dead, free it. */
|
393
|
+
lua_assert(isdead(g, o) || ow == LJ_GC_SFIXED);
|
394
|
+
setgcrefr(*p, o->gch.nextgc);
|
395
|
+
if (o == gcref(g->gc.root))
|
396
|
+
setgcrefr(g->gc.root, o->gch.nextgc); /* Adjust list anchor. */
|
397
|
+
gc_freefunc[o->gch.gct - ~LJ_TSTR](g, o);
|
398
|
+
}
|
399
|
+
}
|
400
|
+
return p;
|
401
|
+
}
|
402
|
+
|
403
|
+
/* Check whether we can clear a key or a value slot from a table. */
|
404
|
+
static int gc_mayclear(cTValue *o, int val)
|
405
|
+
{
|
406
|
+
if (tvisgcv(o)) { /* Only collectable objects can be weak references. */
|
407
|
+
if (tvisstr(o)) { /* But strings cannot be used as weak references. */
|
408
|
+
gc_mark_str(strV(o)); /* And need to be marked. */
|
409
|
+
return 0;
|
410
|
+
}
|
411
|
+
if (iswhite(gcV(o)))
|
412
|
+
return 1; /* Object is about to be collected. */
|
413
|
+
if (tvisudata(o) && val && isfinalized(udataV(o)))
|
414
|
+
return 1; /* Finalized userdata is dropped only from values. */
|
415
|
+
}
|
416
|
+
return 0; /* Cannot clear. */
|
417
|
+
}
|
418
|
+
|
419
|
+
/* Clear collected entries from weak tables. */
|
420
|
+
static void gc_clearweak(GCobj *o)
|
421
|
+
{
|
422
|
+
while (o) {
|
423
|
+
GCtab *t = gco2tab(o);
|
424
|
+
lua_assert((t->marked & LJ_GC_WEAK));
|
425
|
+
if ((t->marked & LJ_GC_WEAKVAL)) {
|
426
|
+
MSize i, asize = t->asize;
|
427
|
+
for (i = 0; i < asize; i++) {
|
428
|
+
/* Clear array slot when value is about to be collected. */
|
429
|
+
TValue *tv = arrayslot(t, i);
|
430
|
+
if (gc_mayclear(tv, 1))
|
431
|
+
setnilV(tv);
|
432
|
+
}
|
433
|
+
}
|
434
|
+
if (t->hmask > 0) {
|
435
|
+
Node *node = noderef(t->node);
|
436
|
+
MSize i, hmask = t->hmask;
|
437
|
+
for (i = 0; i <= hmask; i++) {
|
438
|
+
Node *n = &node[i];
|
439
|
+
/* Clear hash slot when key or value is about to be collected. */
|
440
|
+
if (!tvisnil(&n->val) && (gc_mayclear(&n->key, 0) ||
|
441
|
+
gc_mayclear(&n->val, 1)))
|
442
|
+
setnilV(&n->val);
|
443
|
+
}
|
444
|
+
}
|
445
|
+
o = gcref(t->gclist);
|
446
|
+
}
|
447
|
+
}
|
448
|
+
|
449
|
+
/* Call a userdata or cdata finalizer. */
|
450
|
+
static void gc_call_finalizer(global_State *g, lua_State *L,
|
451
|
+
cTValue *mo, GCobj *o)
|
452
|
+
{
|
453
|
+
/* Save and restore lots of state around the __gc callback. */
|
454
|
+
uint8_t oldh = hook_save(g);
|
455
|
+
GCSize oldt = g->gc.threshold;
|
456
|
+
int errcode;
|
457
|
+
TValue *top;
|
458
|
+
lj_trace_abort(g);
|
459
|
+
hook_entergc(g); /* Disable hooks and new traces during __gc. */
|
460
|
+
g->gc.threshold = LJ_MAX_MEM; /* Prevent GC steps. */
|
461
|
+
top = L->top;
|
462
|
+
copyTV(L, top++, mo);
|
463
|
+
if (LJ_FR2) setnilV(top++);
|
464
|
+
setgcV(L, top, o, ~o->gch.gct);
|
465
|
+
L->top = top+1;
|
466
|
+
errcode = lj_vm_pcall(L, top, 1+0, -1); /* Stack: |mo|o| -> | */
|
467
|
+
hook_restore(g, oldh);
|
468
|
+
g->gc.threshold = oldt; /* Restore GC threshold. */
|
469
|
+
if (errcode)
|
470
|
+
lj_err_throw(L, errcode); /* Propagate errors. */
|
471
|
+
}
|
472
|
+
|
473
|
+
/* Finalize one userdata or cdata object from the mmudata list. */
|
474
|
+
static void gc_finalize(lua_State *L)
|
475
|
+
{
|
476
|
+
global_State *g = G(L);
|
477
|
+
GCobj *o = gcnext(gcref(g->gc.mmudata));
|
478
|
+
cTValue *mo;
|
479
|
+
lua_assert(tvref(g->jit_base) == NULL); /* Must not be called on trace. */
|
480
|
+
/* Unchain from list of userdata to be finalized. */
|
481
|
+
if (o == gcref(g->gc.mmudata))
|
482
|
+
setgcrefnull(g->gc.mmudata);
|
483
|
+
else
|
484
|
+
setgcrefr(gcref(g->gc.mmudata)->gch.nextgc, o->gch.nextgc);
|
485
|
+
#if LJ_HASFFI
|
486
|
+
if (o->gch.gct == ~LJ_TCDATA) {
|
487
|
+
TValue tmp, *tv;
|
488
|
+
/* Add cdata back to the GC list and make it white. */
|
489
|
+
setgcrefr(o->gch.nextgc, g->gc.root);
|
490
|
+
setgcref(g->gc.root, o);
|
491
|
+
makewhite(g, o);
|
492
|
+
o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN;
|
493
|
+
/* Resolve finalizer. */
|
494
|
+
setcdataV(L, &tmp, gco2cd(o));
|
495
|
+
tv = lj_tab_set(L, ctype_ctsG(g)->finalizer, &tmp);
|
496
|
+
if (!tvisnil(tv)) {
|
497
|
+
g->gc.nocdatafin = 0;
|
498
|
+
copyTV(L, &tmp, tv);
|
499
|
+
setnilV(tv); /* Clear entry in finalizer table. */
|
500
|
+
gc_call_finalizer(g, L, &tmp, o);
|
501
|
+
}
|
502
|
+
return;
|
503
|
+
}
|
504
|
+
#endif
|
505
|
+
/* Add userdata back to the main userdata list and make it white. */
|
506
|
+
setgcrefr(o->gch.nextgc, mainthread(g)->nextgc);
|
507
|
+
setgcref(mainthread(g)->nextgc, o);
|
508
|
+
makewhite(g, o);
|
509
|
+
/* Resolve the __gc metamethod. */
|
510
|
+
mo = lj_meta_fastg(g, tabref(gco2ud(o)->metatable), MM_gc);
|
511
|
+
if (mo)
|
512
|
+
gc_call_finalizer(g, L, mo, o);
|
513
|
+
}
|
514
|
+
|
515
|
+
/* Finalize all userdata objects from mmudata list. */
|
516
|
+
void lj_gc_finalize_udata(lua_State *L)
|
517
|
+
{
|
518
|
+
while (gcref(G(L)->gc.mmudata) != NULL)
|
519
|
+
gc_finalize(L);
|
520
|
+
}
|
521
|
+
|
522
|
+
#if LJ_HASFFI
|
523
|
+
/* Finalize all cdata objects from finalizer table. */
|
524
|
+
void lj_gc_finalize_cdata(lua_State *L)
|
525
|
+
{
|
526
|
+
global_State *g = G(L);
|
527
|
+
CTState *cts = ctype_ctsG(g);
|
528
|
+
if (cts) {
|
529
|
+
GCtab *t = cts->finalizer;
|
530
|
+
Node *node = noderef(t->node);
|
531
|
+
ptrdiff_t i;
|
532
|
+
setgcrefnull(t->metatable); /* Mark finalizer table as disabled. */
|
533
|
+
for (i = (ptrdiff_t)t->hmask; i >= 0; i--)
|
534
|
+
if (!tvisnil(&node[i].val) && tviscdata(&node[i].key)) {
|
535
|
+
GCobj *o = gcV(&node[i].key);
|
536
|
+
TValue tmp;
|
537
|
+
makewhite(g, o);
|
538
|
+
o->gch.marked &= (uint8_t)~LJ_GC_CDATA_FIN;
|
539
|
+
copyTV(L, &tmp, &node[i].val);
|
540
|
+
setnilV(&node[i].val);
|
541
|
+
gc_call_finalizer(g, L, &tmp, o);
|
542
|
+
}
|
543
|
+
}
|
544
|
+
}
|
545
|
+
#endif
|
546
|
+
|
547
|
+
/* Free all remaining GC objects. */
|
548
|
+
void lj_gc_freeall(global_State *g)
|
549
|
+
{
|
550
|
+
MSize i, strmask;
|
551
|
+
/* Free everything, except super-fixed objects (the main thread). */
|
552
|
+
g->gc.currentwhite = LJ_GC_WHITES | LJ_GC_SFIXED;
|
553
|
+
gc_fullsweep(g, &g->gc.root);
|
554
|
+
strmask = g->strmask;
|
555
|
+
for (i = 0; i <= strmask; i++) /* Free all string hash chains. */
|
556
|
+
gc_fullsweep(g, &g->strhash[i]);
|
557
|
+
}
|
558
|
+
|
559
|
+
/* -- Collector ----------------------------------------------------------- */
|
560
|
+
|
561
|
+
/* Atomic part of the GC cycle, transitioning from mark to sweep phase. */
|
562
|
+
static void atomic(global_State *g, lua_State *L)
|
563
|
+
{
|
564
|
+
size_t udsize;
|
565
|
+
|
566
|
+
gc_mark_uv(g); /* Need to remark open upvalues (the thread may be dead). */
|
567
|
+
gc_propagate_gray(g); /* Propagate any left-overs. */
|
568
|
+
|
569
|
+
setgcrefr(g->gc.gray, g->gc.weak); /* Empty the list of weak tables. */
|
570
|
+
setgcrefnull(g->gc.weak);
|
571
|
+
lua_assert(!iswhite(obj2gco(mainthread(g))));
|
572
|
+
gc_markobj(g, L); /* Mark running thread. */
|
573
|
+
gc_traverse_curtrace(g); /* Traverse current trace. */
|
574
|
+
gc_mark_gcroot(g); /* Mark GC roots (again). */
|
575
|
+
gc_propagate_gray(g); /* Propagate all of the above. */
|
576
|
+
|
577
|
+
setgcrefr(g->gc.gray, g->gc.grayagain); /* Empty the 2nd chance list. */
|
578
|
+
setgcrefnull(g->gc.grayagain);
|
579
|
+
gc_propagate_gray(g); /* Propagate it. */
|
580
|
+
|
581
|
+
udsize = lj_gc_separateudata(g, 0); /* Separate userdata to be finalized. */
|
582
|
+
gc_mark_mmudata(g); /* Mark them. */
|
583
|
+
udsize += gc_propagate_gray(g); /* And propagate the marks. */
|
584
|
+
|
585
|
+
/* All marking done, clear weak tables. */
|
586
|
+
gc_clearweak(gcref(g->gc.weak));
|
587
|
+
|
588
|
+
lj_buf_shrink(L, &g->tmpbuf); /* Shrink temp buffer. */
|
589
|
+
|
590
|
+
/* Prepare for sweep phase. */
|
591
|
+
g->gc.currentwhite = (uint8_t)otherwhite(g); /* Flip current white. */
|
592
|
+
g->strempty.marked = g->gc.currentwhite;
|
593
|
+
setmref(g->gc.sweep, &g->gc.root);
|
594
|
+
g->gc.estimate = g->gc.total - (GCSize)udsize; /* Initial estimate. */
|
595
|
+
}
|
596
|
+
|
597
|
+
/* GC state machine. Returns a cost estimate for each step performed. */
|
598
|
+
static size_t gc_onestep(lua_State *L)
|
599
|
+
{
|
600
|
+
global_State *g = G(L);
|
601
|
+
switch (g->gc.state) {
|
602
|
+
case GCSpause:
|
603
|
+
gc_mark_start(g); /* Start a new GC cycle by marking all GC roots. */
|
604
|
+
return 0;
|
605
|
+
case GCSpropagate:
|
606
|
+
if (gcref(g->gc.gray) != NULL)
|
607
|
+
return propagatemark(g); /* Propagate one gray object. */
|
608
|
+
g->gc.state = GCSatomic; /* End of mark phase. */
|
609
|
+
return 0;
|
610
|
+
case GCSatomic:
|
611
|
+
if (tvref(g->jit_base)) /* Don't run atomic phase on trace. */
|
612
|
+
return LJ_MAX_MEM;
|
613
|
+
atomic(g, L);
|
614
|
+
g->gc.state = GCSsweepstring; /* Start of sweep phase. */
|
615
|
+
g->gc.sweepstr = 0;
|
616
|
+
return 0;
|
617
|
+
case GCSsweepstring: {
|
618
|
+
GCSize old = g->gc.total;
|
619
|
+
gc_fullsweep(g, &g->strhash[g->gc.sweepstr++]); /* Sweep one chain. */
|
620
|
+
if (g->gc.sweepstr > g->strmask)
|
621
|
+
g->gc.state = GCSsweep; /* All string hash chains sweeped. */
|
622
|
+
lua_assert(old >= g->gc.total);
|
623
|
+
g->gc.estimate -= old - g->gc.total;
|
624
|
+
return GCSWEEPCOST;
|
625
|
+
}
|
626
|
+
case GCSsweep: {
|
627
|
+
GCSize old = g->gc.total;
|
628
|
+
setmref(g->gc.sweep, gc_sweep(g, mref(g->gc.sweep, GCRef), GCSWEEPMAX));
|
629
|
+
lua_assert(old >= g->gc.total);
|
630
|
+
g->gc.estimate -= old - g->gc.total;
|
631
|
+
if (gcref(*mref(g->gc.sweep, GCRef)) == NULL) {
|
632
|
+
if (g->strnum <= (g->strmask >> 2) && g->strmask > LJ_MIN_STRTAB*2-1)
|
633
|
+
lj_str_resize(L, g->strmask >> 1); /* Shrink string table. */
|
634
|
+
if (gcref(g->gc.mmudata)) { /* Need any finalizations? */
|
635
|
+
g->gc.state = GCSfinalize;
|
636
|
+
#if LJ_HASFFI
|
637
|
+
g->gc.nocdatafin = 1;
|
638
|
+
#endif
|
639
|
+
} else { /* Otherwise skip this phase to help the JIT. */
|
640
|
+
g->gc.state = GCSpause; /* End of GC cycle. */
|
641
|
+
g->gc.debt = 0;
|
642
|
+
}
|
643
|
+
}
|
644
|
+
return GCSWEEPMAX*GCSWEEPCOST;
|
645
|
+
}
|
646
|
+
case GCSfinalize:
|
647
|
+
if (gcref(g->gc.mmudata) != NULL) {
|
648
|
+
if (tvref(g->jit_base)) /* Don't call finalizers on trace. */
|
649
|
+
return LJ_MAX_MEM;
|
650
|
+
gc_finalize(L); /* Finalize one userdata object. */
|
651
|
+
if (g->gc.estimate > GCFINALIZECOST)
|
652
|
+
g->gc.estimate -= GCFINALIZECOST;
|
653
|
+
return GCFINALIZECOST;
|
654
|
+
}
|
655
|
+
#if LJ_HASFFI
|
656
|
+
if (!g->gc.nocdatafin) lj_tab_rehash(L, ctype_ctsG(g)->finalizer);
|
657
|
+
#endif
|
658
|
+
g->gc.state = GCSpause; /* End of GC cycle. */
|
659
|
+
g->gc.debt = 0;
|
660
|
+
return 0;
|
661
|
+
default:
|
662
|
+
lua_assert(0);
|
663
|
+
return 0;
|
664
|
+
}
|
665
|
+
}
|
666
|
+
|
667
|
+
/* Perform a limited amount of incremental GC steps. */
|
668
|
+
int LJ_FASTCALL lj_gc_step(lua_State *L)
|
669
|
+
{
|
670
|
+
global_State *g = G(L);
|
671
|
+
GCSize lim;
|
672
|
+
int32_t ostate = g->vmstate;
|
673
|
+
setvmstate(g, GC);
|
674
|
+
lim = (GCSTEPSIZE/100) * g->gc.stepmul;
|
675
|
+
if (lim == 0)
|
676
|
+
lim = LJ_MAX_MEM;
|
677
|
+
if (g->gc.total > g->gc.threshold)
|
678
|
+
g->gc.debt += g->gc.total - g->gc.threshold;
|
679
|
+
do {
|
680
|
+
lim -= (GCSize)gc_onestep(L);
|
681
|
+
if (g->gc.state == GCSpause) {
|
682
|
+
g->gc.threshold = (g->gc.estimate/100) * g->gc.pause;
|
683
|
+
g->vmstate = ostate;
|
684
|
+
return 1; /* Finished a GC cycle. */
|
685
|
+
}
|
686
|
+
} while (sizeof(lim) == 8 ? ((int64_t)lim > 0) : ((int32_t)lim > 0));
|
687
|
+
if (g->gc.debt < GCSTEPSIZE) {
|
688
|
+
g->gc.threshold = g->gc.total + GCSTEPSIZE;
|
689
|
+
g->vmstate = ostate;
|
690
|
+
return -1;
|
691
|
+
} else {
|
692
|
+
g->gc.debt -= GCSTEPSIZE;
|
693
|
+
g->gc.threshold = g->gc.total;
|
694
|
+
g->vmstate = ostate;
|
695
|
+
return 0;
|
696
|
+
}
|
697
|
+
}
|
698
|
+
|
699
|
+
/* Ditto, but fix the stack top first. */
|
700
|
+
void LJ_FASTCALL lj_gc_step_fixtop(lua_State *L)
|
701
|
+
{
|
702
|
+
if (curr_funcisL(L)) L->top = curr_topL(L);
|
703
|
+
lj_gc_step(L);
|
704
|
+
}
|
705
|
+
|
706
|
+
#if LJ_HASJIT
|
707
|
+
/* Perform multiple GC steps. Called from JIT-compiled code. */
|
708
|
+
int LJ_FASTCALL lj_gc_step_jit(global_State *g, MSize steps)
|
709
|
+
{
|
710
|
+
lua_State *L = gco2th(gcref(g->cur_L));
|
711
|
+
L->base = tvref(G(L)->jit_base);
|
712
|
+
L->top = curr_topL(L);
|
713
|
+
while (steps-- > 0 && lj_gc_step(L) == 0)
|
714
|
+
;
|
715
|
+
/* Return 1 to force a trace exit. */
|
716
|
+
return (G(L)->gc.state == GCSatomic || G(L)->gc.state == GCSfinalize);
|
717
|
+
}
|
718
|
+
#endif
|
719
|
+
|
720
|
+
/* Perform a full GC cycle. */
|
721
|
+
void lj_gc_fullgc(lua_State *L)
|
722
|
+
{
|
723
|
+
global_State *g = G(L);
|
724
|
+
int32_t ostate = g->vmstate;
|
725
|
+
setvmstate(g, GC);
|
726
|
+
if (g->gc.state <= GCSatomic) { /* Caught somewhere in the middle. */
|
727
|
+
setmref(g->gc.sweep, &g->gc.root); /* Sweep everything (preserving it). */
|
728
|
+
setgcrefnull(g->gc.gray); /* Reset lists from partial propagation. */
|
729
|
+
setgcrefnull(g->gc.grayagain);
|
730
|
+
setgcrefnull(g->gc.weak);
|
731
|
+
g->gc.state = GCSsweepstring; /* Fast forward to the sweep phase. */
|
732
|
+
g->gc.sweepstr = 0;
|
733
|
+
}
|
734
|
+
while (g->gc.state == GCSsweepstring || g->gc.state == GCSsweep)
|
735
|
+
gc_onestep(L); /* Finish sweep. */
|
736
|
+
lua_assert(g->gc.state == GCSfinalize || g->gc.state == GCSpause);
|
737
|
+
/* Now perform a full GC. */
|
738
|
+
g->gc.state = GCSpause;
|
739
|
+
do { gc_onestep(L); } while (g->gc.state != GCSpause);
|
740
|
+
g->gc.threshold = (g->gc.estimate/100) * g->gc.pause;
|
741
|
+
g->vmstate = ostate;
|
742
|
+
}
|
743
|
+
|
744
|
+
/* -- Write barriers ------------------------------------------------------ */
|
745
|
+
|
746
|
+
/* Move the GC propagation frontier forward. */
|
747
|
+
void lj_gc_barrierf(global_State *g, GCobj *o, GCobj *v)
|
748
|
+
{
|
749
|
+
lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
|
750
|
+
lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);
|
751
|
+
lua_assert(o->gch.gct != ~LJ_TTAB);
|
752
|
+
/* Preserve invariant during propagation. Otherwise it doesn't matter. */
|
753
|
+
if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)
|
754
|
+
gc_mark(g, v); /* Move frontier forward. */
|
755
|
+
else
|
756
|
+
makewhite(g, o); /* Make it white to avoid the following barrier. */
|
757
|
+
}
|
758
|
+
|
759
|
+
/* Specialized barrier for closed upvalue. Pass &uv->tv. */
|
760
|
+
void LJ_FASTCALL lj_gc_barrieruv(global_State *g, TValue *tv)
|
761
|
+
{
|
762
|
+
#define TV2MARKED(x) \
|
763
|
+
(*((uint8_t *)(x) - offsetof(GCupval, tv) + offsetof(GCupval, marked)))
|
764
|
+
if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)
|
765
|
+
gc_mark(g, gcV(tv));
|
766
|
+
else
|
767
|
+
TV2MARKED(tv) = (TV2MARKED(tv) & (uint8_t)~LJ_GC_COLORS) | curwhite(g);
|
768
|
+
#undef TV2MARKED
|
769
|
+
}
|
770
|
+
|
771
|
+
/* Close upvalue. Also needs a write barrier. */
|
772
|
+
void lj_gc_closeuv(global_State *g, GCupval *uv)
|
773
|
+
{
|
774
|
+
GCobj *o = obj2gco(uv);
|
775
|
+
/* Copy stack slot to upvalue itself and point to the copy. */
|
776
|
+
copyTV(mainthread(g), &uv->tv, uvval(uv));
|
777
|
+
setmref(uv->v, &uv->tv);
|
778
|
+
uv->closed = 1;
|
779
|
+
setgcrefr(o->gch.nextgc, g->gc.root);
|
780
|
+
setgcref(g->gc.root, o);
|
781
|
+
if (isgray(o)) { /* A closed upvalue is never gray, so fix this. */
|
782
|
+
if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic) {
|
783
|
+
gray2black(o); /* Make it black and preserve invariant. */
|
784
|
+
if (tviswhite(&uv->tv))
|
785
|
+
lj_gc_barrierf(g, o, gcV(&uv->tv));
|
786
|
+
} else {
|
787
|
+
makewhite(g, o); /* Make it white, i.e. sweep the upvalue. */
|
788
|
+
lua_assert(g->gc.state != GCSfinalize && g->gc.state != GCSpause);
|
789
|
+
}
|
790
|
+
}
|
791
|
+
}
|
792
|
+
|
793
|
+
#if LJ_HASJIT
|
794
|
+
/* Mark a trace if it's saved during the propagation phase. */
|
795
|
+
void lj_gc_barriertrace(global_State *g, uint32_t traceno)
|
796
|
+
{
|
797
|
+
if (g->gc.state == GCSpropagate || g->gc.state == GCSatomic)
|
798
|
+
gc_marktrace(g, traceno);
|
799
|
+
}
|
800
|
+
#endif
|
801
|
+
|
802
|
+
/* -- Allocator ----------------------------------------------------------- */
|
803
|
+
|
804
|
+
/* Call pluggable memory allocator to allocate or resize a fragment. */
|
805
|
+
void *lj_mem_realloc(lua_State *L, void *p, GCSize osz, GCSize nsz)
|
806
|
+
{
|
807
|
+
global_State *g = G(L);
|
808
|
+
lua_assert((osz == 0) == (p == NULL));
|
809
|
+
p = g->allocf(g->allocd, p, osz, nsz);
|
810
|
+
if (p == NULL && nsz > 0)
|
811
|
+
lj_err_mem(L);
|
812
|
+
lua_assert((nsz == 0) == (p == NULL));
|
813
|
+
lua_assert(checkptrGC(p));
|
814
|
+
g->gc.total = (g->gc.total - osz) + nsz;
|
815
|
+
return p;
|
816
|
+
}
|
817
|
+
|
818
|
+
/* Allocate new GC object and link it to the root set. */
|
819
|
+
void * LJ_FASTCALL lj_mem_newgco(lua_State *L, GCSize size)
|
820
|
+
{
|
821
|
+
global_State *g = G(L);
|
822
|
+
GCobj *o = (GCobj *)g->allocf(g->allocd, NULL, 0, size);
|
823
|
+
if (o == NULL)
|
824
|
+
lj_err_mem(L);
|
825
|
+
lua_assert(checkptrGC(o));
|
826
|
+
g->gc.total += size;
|
827
|
+
setgcrefr(o->gch.nextgc, g->gc.root);
|
828
|
+
setgcref(g->gc.root, o);
|
829
|
+
newwhite(g, o);
|
830
|
+
return o;
|
831
|
+
}
|
832
|
+
|
833
|
+
/* Resize growable vector. */
|
834
|
+
void *lj_mem_grow(lua_State *L, void *p, MSize *szp, MSize lim, MSize esz)
|
835
|
+
{
|
836
|
+
MSize sz = (*szp) << 1;
|
837
|
+
if (sz < LJ_MIN_VECSZ)
|
838
|
+
sz = LJ_MIN_VECSZ;
|
839
|
+
if (sz > lim)
|
840
|
+
sz = lim;
|
841
|
+
p = lj_mem_realloc(L, p, (*szp)*esz, sz*esz);
|
842
|
+
*szp = sz;
|
843
|
+
return p;
|
844
|
+
}
|
845
|
+
|