Commit graph

62 commits

Author SHA1 Message Date
Fabian 75dbbbc55a Update rustfmt 2020-12-31 19:14:30 -06:00
Fabian a73988a817 Make loop, loopz, loopnz and jcxz custom generated 2020-12-31 19:14:30 -06:00
Fabian ea0cd01207 Comment so that I don't delete this again 2020-12-31 19:14:30 -06:00
Fabian b7e5f28104 Fix rust warning 2020-12-31 19:14:29 -06:00
Fabian c97301842e Put jit_cache_array and jit_page_first_entry into global state, reduces the size of the .wasm files by 8MB because for some reason the rust compiler decides to put them into the data section 2020-12-31 19:14:29 -06:00
Fabian 33e608fa70 fix rust warning 2020-12-31 19:14:29 -06:00
Fabian 3f1ba044ed Increment timestamp_counter before running basic block 2020-12-31 19:14:29 -06:00
Fabian c207400922 Fix Rust warnings 2020-12-31 19:14:29 -06:00
Fabian bc3c73a607 wasm state machine: Fallthrough 2020-12-31 19:14:28 -06:00
Fabian 0e8c8a1dda More opstats 2020-12-31 19:14:28 -06:00
Fabian c086c710ad Stat: Count duplicate entries 2020-08-30 19:37:15 -05:00
Fabian 0d938fb3da Minor: Flatten pattern match 2020-08-30 19:37:15 -05:00
Fabian b774db3f81 Fix: Clear prefixes when leaving instruction early 2020-08-30 19:37:15 -05:00
Fabian 724090b319 Reduce code size by removing register restoring around safe_{read,write}*_jit 2020-08-30 19:37:15 -05:00
Fabian 723f78c14f Reduce code size by creating a block to jump to that handles the page fault case 2020-08-30 19:37:15 -05:00
Fabian a8308b988d Store registers in locals
This changes registers to be temporarily stored in wasm locals, across
each complete wasm module. Registers are moved from memory to locals
upon entering the wasm module and moved from locals to memory upon
leaving. Additionally, calls to functions that modify registers are
wrapped between moving registers to memory before and moving back to
locals after. This affects:

1. All non-custom instructions
2. safe_{read,write}_slow, since it may page fault (the slow path of all memory accesses)
3. task_switch_test* and trigger_ud
4. All block boundaries
5. The fallback functions of gen_safe_read_write (read-modify-write memory accesses)

The performance benefits are currently mostly eaten up by 1. and 4. (if
one calculates the total number of read/writes to registers in memory,
they are higher after this patch, as each instructions of typ 1. or 4.
requires moving all 8 register twice). This can be improved later by the
relatively mechanical work of making instructions custom (not
necessarily full code generation, only the part of the instruction where
registers are accessed). Multi-page wasm module generation will
significantly reduce the number of type 4. instructions.

Due to 2., the overall code size has significantly increased. This case
(the slow path of memory access) is often generated but rarely executed.
These moves can be removed in a later patch by a different scheme for
safe_{read,write}_slow, which has been left out of this patch for
simplicity of reviewing.

This also simplifies our code generation for storing registers, as

    instructions_body.const_i32(register_offset);
    // some computations ...
    instruction_body.store_i32();

turns into:

    // some computations ...
    write_register(register_index);

I.e., a prefix is not necessary anymore as locals are indexed directly.

Further patches will allow getting rid of some temporary locals, as
registers now can be used directly.
2020-08-30 19:37:15 -05:00
Fabian 8838e263c3 Profiler: Track number of page faults and wasm bytes generated 2020-08-30 19:37:15 -05:00
Fabian 4d35564761 Simplify get_seg: Generate code inline, avoid importing it in every module 2020-08-30 19:37:15 -05:00
Fabian 69b834c8de Move condition function generation into codegen module and use it for cmovcc/setcc 2020-08-30 19:37:15 -05:00
Fabian f6718c3ead Fix a few missing local frees 2020-08-30 19:37:15 -05:00
Fabian bea53fdfb2 Fix profiler build 2020-08-30 19:37:15 -05:00
Fabian 23c5ebdf61 Reduce value of WASM_TABLE_SIZE and incraese JIT_THRESHOLD
Now that WASM_TABLE_SIZE may be capped, we set it slightly below the
limit under which chromium crashes: https://bugs.chromium.org/p/v8/issues/detail?id=8427

JIT_THRESHOLD is also reduced due to two reasons:

- With the lower WASM_TABLE_SIZE, we want to avoid compiling too many
  modules
- It has occasionally been observed that under node, the engine's wasm
  compiler can't catch up with the number of modules we produce, thus
  resulting in 100s of pending compiled modules. This most likely
  happens only under node as we don't render the screen and
  the main loop (based on setImmediate) is faster.
  The new value doesn't seem to exhibit this problem, but we may want to
  increase the threshold further if the problem appears again
2020-08-30 19:37:15 -05:00
Fabian 71093270cd Add stat to track running out of wasm indices 2020-08-30 19:37:15 -05:00
Fabian 0e16983dd3 Handle case when wasm table is full (fixes #35)
Also fix jit_empty_cache when callbacks are pending (fixes #53)

This is also a preparation for setting WASM_TABLE_SIZE to a low value to
work around memory limitations in browsers.
2020-08-30 19:37:15 -05:00
Fabian 8d6baff91c Fix rustfmt 2020-08-30 19:29:54 -05:00
Fabian b83ed1b7c1 Minor 2020-08-30 19:29:54 -05:00
Fabian 48e6843a87 Remove S_ prefix from profiler 2020-08-30 19:29:54 -05:00
Fabian 5b2aa69777 Use CachedStateFlags type in former C code 2020-08-30 19:29:54 -05:00
Fabian 0798a0b40e Don't create unnecessary entry points
This commit prevents creation of entry points for jumps within the same
page. In interpreted mode, execution is continued on these kinds of
jumps.

Since this prevents the old hotness detection from working efficiently,
hotness detection has also been changed to work based on instruction
counters, and is such more precise (longer basic blocks are compiled
earlier).

This also breaks the old detection loop safety mechanism and causes
Linux to sometimes loop forever on "calibrating delay loop", so
JIT_ALWAYS_USE_LOOP_SAFETY has been set to 1.
2020-08-30 19:29:54 -05:00
Fabian afcce9b371 Record compiled instructions per opcode 2020-08-30 19:29:54 -05:00
Fabian 7e1d398e05 Track last executed jump instruction, check for missed entry points while looking for compiled code 2020-08-30 19:29:54 -05:00
Fabian 3f9b32cdd8 Improve stats for run_interpreted 2020-08-30 19:29:54 -05:00
Fabian b98ff1612a Make profiler stat counters u64 2020-08-30 19:29:54 -05:00
Fabian 32699a3a7e Clear unused wasm modules earlier 2020-08-30 19:29:54 -05:00
Fabian 22ba923f9a Track number of module invalidations 2020-08-30 19:29:54 -05:00
Fabian 295985e8e0 Remove code section: Only a single buffer is used for generating code 2020-08-30 19:29:54 -05:00
Fabian 41b60d278c Accept builder in gen_jmp_rel16, simplifying 2020-08-30 19:29:54 -05:00
Fabian d691b311a2 Simplify some code 2020-08-30 19:29:54 -05:00
Fabian 46f9bc9d00 Remove non-faulting property of instructions (all instructions are non-faulting) 2020-08-30 19:29:54 -05:00
Fabian fa958d95c3 Fix warnings: Remove unused stuff 2020-08-30 19:29:54 -05:00
Fabian 8460d9e1e4 Clean up 2020-08-30 19:29:54 -05:00
Fabian 1d24c5952d Cleanup of codegen api 2020-08-30 19:29:54 -05:00
Fabian 71524d1d2c Use gen_jmp_rel16 for generating jumps in 16-bit mode 2020-08-30 19:29:54 -05:00
Fabian fbd5e136e1 Temporarily increase JIT_THRESHOLD to account for marking a lot of instructions as block boundary 2020-08-30 19:29:54 -05:00
Fabian d4d7d236d5 Make all instructions non-faulting; handle faulting case in gen_safe_{read,write} (#44) 2020-08-30 19:29:54 -05:00
Fabian 60d4a28e2c jit: Custom instructions can be block boundaries 2020-08-30 19:29:54 -05:00
Fabian dc37bac547 Analysis: Never emit empty basic blocks, track last instruction of basic block 2020-08-30 19:29:54 -05:00
Fabian c8b3d5a618 Add more information to .expect 2020-08-30 19:29:53 -05:00
Fabian a5cbf53da5 Fix jit in presence of new page fault handling
Makes the following a block boundary:

- push
- Any non-custom instruction that uses modrm encoding
- Any sse/fpu instruction

This commit affects performance negatively. In order to fix this, the
above instructions need to be implemented using custom code generators
for the memory access.
2020-08-30 19:29:53 -05:00
Fabian 11ee22176d Temporarily disable jit 2020-08-30 19:29:53 -05:00