Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V8 Release 12.4 #35

Merged
merged 16 commits into from
Jun 7, 2024
18 changes: 9 additions & 9 deletions BOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ gzip compressed binary from github.
on linux/x64

```shell
curl -L -o lo.gz https://github.com/just-js/lo/releases/download/0.0.15-pre/lo-linux-x64.gz
curl -L -o lo.gz https://github.com/just-js/lo/releases/download/0.0.16-pre/lo-linux-x64.gz
```

on linux/arm64

```shell
curl -L -o lo.gz https://github.com/just-js/lo/releases/download/0.0.15-pre/lo-linux-arm64.gz
curl -L -o lo.gz https://github.com/just-js/lo/releases/download/0.0.16-pre/lo-linux-arm64.gz
```

on macos/x64

```shell
curl -L -o lo.gz https://github.com/just-js/lo/releases/download/0.0.15-pre/lo-mac-x64.gz
curl -L -o lo.gz https://github.com/just-js/lo/releases/download/0.0.16-pre/lo-mac-x64.gz
```

on macos/arm64 (apple silicon)

```shell
curl -L -o lo.gz https://github.com/just-js/lo/releases/download/0.0.15-pre/lo-mac-arm64.gz
curl -L -o lo.gz https://github.com/just-js/lo/releases/download/0.0.16-pre/lo-mac-arm64.gz
```

Then, we need to decompress the downloaded file and make it executable
Expand Down Expand Up @@ -122,7 +122,7 @@ let's check the version number of lo and the embedded JS engine it is using
```shell
./lo --version

0.0.15-pre
0.0.16-pre
```

### evaluating JavaScript
Expand Down Expand Up @@ -165,9 +165,9 @@ lo has a very basic repl which you can invoke as follows
⬛⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛
⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛⬛

lo 0.0.15-pre v8 12.3.219.12
lo 0.0.16-pre v8 12.4.254.18
arch x64 os linux
boot 5.67 ms rss 34078720
boot 6.02 ms rss 34996224

>
```
Expand All @@ -181,8 +181,8 @@ we downloaded.

{
version: {
lo: "0.0.15-pre",
v8: "12.3.219.12"
lo: "0.0.16-pre",
v8: "12.4.254.18"
},
...
}
Expand Down
16 changes: 6 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ CCARGS=-std=c++17 -c -fno-omit-frame-pointer -fno-rtti -fno-exceptions
CARGS=-c -fno-omit-frame-pointer
WARN=-Werror -Wpedantic -Wall -Wextra -Wno-unused-parameter
OPT=-O3
VERSION=0.0.15-pre
V8_VERSION=12.3
VERSION=0.0.16-pre
V8_VERSION=12.4
RUNTIME=lo
LO_HOME=$(shell pwd)
BINDINGS=core.o inflate.a curl.o
ARCH=x64
os=linux
TARGET=${RUNTIME}
LIBS=-ldl -lcurl -lssl -lz
V8_FLAGS=-DV8_COMPRESS_POINTERS -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=0 -DV8_INTL_SUPPORT=1
V8_FLAGS=-DV8_COMPRESS_POINTERS -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=0 -DV8_INTL_SUPPORT=1 -DENABLE_HUGEPAGE
LIB_DIRS=

ifeq ($(OS),Windows_NT)
Expand All @@ -41,7 +41,7 @@ else
endif
endif

.PHONY: help clean
.PHONY: help clean cleanall check install

help:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9\/_\.-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
Expand All @@ -65,10 +65,8 @@ v8/libv8_monolith.a: ## download the v8 static libary for linux/macos
gzip -d v8/libv8_monolith.a.gz
rm -f v8/libv8_monolith.a.gz

v8/v8_monolith.lib.zip: ## download the v8 static library for windows
v8/v8_monolith.lib: ## download the v8 static library for windows
curl -L -o v8/v8_monolith.lib.zip https://github.com/just-js/v8/releases/download/${V8_VERSION}/libv8_monolith-${os}-${ARCH}.zip

v8/v8_monolith.lib: v8/v8_monolith.lib.zip ## download the v8 static library for windows
tar -C v8 -xf v8/v8_monolith.lib.zip

main.o: ## compile the main.cc object file
Expand Down Expand Up @@ -111,10 +109,8 @@ lib/inflate/em_inflate.c:
lib/inflate/em_inflate.o: lib/inflate/em_inflate.h lib/inflate/em_inflate.c ## build the em_inflate object
$(CC) -fPIC $(CARGS) $(OPT) -I. -I./v8 -I./v8/include -Ilib/inflate -o lib/inflate/em_inflate.o lib/inflate/em_inflate.c

inflate.o: lib/inflate/inflate.cc lib/inflate/em_inflate.h ## build the em_inflate object
inflate.a: lib/inflate/em_inflate.o ## build the inflate binding
$(CXX) -fPIC $(CCARGS) $(OPT) -I. -I./v8 -I./v8/include -Ilib/inflate $(WARN) ${V8_FLAGS} -o inflate.o lib/inflate/inflate.cc

inflate.a: inflate.o lib/inflate/em_inflate.o ## build the inflate binding
ar crsT inflate.a inflate.o lib/inflate/em_inflate.o

check: ## run the runtime sanity tests
Expand Down
9 changes: 6 additions & 3 deletions globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,12 @@ interface Core {
prot: number,
flags: number,
fd: number,
offset: number,
buf: Uint32Array
): void;
offset: number
): number;
calloc(num: number, size: number): number;
memcpy(dest: number, src: number, size: number): number;
aligned_alloc(alignment: number, size: number): number;
memmove(dest: number, src: number, size: number): number;
fork(): number;
sysconf(num: number): number;
times(buf: TypedArray): number;
Expand Down
24 changes: 14 additions & 10 deletions lib/ada/api.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
import { lib_api_typed } from 'lib/@typify/typify.js';

const api = lib_api_typed({
ada_parse: {
parse: {
parameters: ['pointer', 'u32'],
pointers: ['const char*'],
result: 'pointer'
result: 'pointer',
name: 'ada_parse'
},
ada_parse_str: {
parse_str: {
parameters: ['string', 'u32'],
pointers: ['const char*'],
result: 'pointer',
name: 'ada_parse'
},
ada_can_parse: {
can_parse: {
parameters: ['pointer', 'u32'],
pointers: ['const char*'],
result: 'u32'
result: 'u32',
name: 'ada_can_parse'
},
ada_can_parse_str: {
can_parse_str: {
parameters: ['string', 'u32'],
pointers: ['const char*'],
result: 'u32',
name: 'ada_can_parse'
},
ada_get_components: {
get_components: {
parameters: ['pointer'],
result: 'pointer',
rpointer: 'const void*'
rpointer: 'const void*',
name: 'ada_get_components'
},
ada_free: {
free: {
parameters: ['pointer'],
result: 'void'
result: 'void',
name: 'ada_free'
}
})

Expand Down
3 changes: 1 addition & 2 deletions lib/asm.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ function compile (code) {
const address = mmap(0, code.length, PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE,
-1, u32)
assert(address)
memcpy(address, code.ptr, code.length, u32)
assert(addr(u32) === address)
assert(memcpy(address, code.ptr, code.length) === address)
assert(mprotect(address, code.length, PROT_EXEC | PROT_READ) === 0)
return address
}
Expand Down
27 changes: 21 additions & 6 deletions lib/asm/assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ class Assembler {
this.#instr.push(`push %${reg}`)
if (idx < 8) {
this.#codes.push([op_push_r64 + idx])
return
return this
}
this.#codes.push([rex(0, 0, 0, 1), op_push_r64 + (idx % 8)])
return this
}

// url: https://www.felixcloutier.com/x86/pop
Expand All @@ -211,19 +212,22 @@ class Assembler {
this.#instr.push(`pop %${reg}`)
if (idx < 8) {
this.#codes.push([op_pop_r64 + idx])
return
return this
}
this.#codes.push([rex(0, 0, 0, 1), op_pop_r64 + (idx % 8)])
return this
}

// url: https://www.felixcloutier.com/x86/add
add (reg, bytes) {
return this.#add_or_sub(reg, bytes, 'add')
this.#add_or_sub(reg, bytes, 'add')
return this
}

// url: https://www.felixcloutier.com/x86/sub
sub (reg, bytes) {
return this.#add_or_sub(reg, bytes, 'sub')
this.#add_or_sub(reg, bytes, 'sub')
return this
}

// url: https://www.felixcloutier.com/x86/call
Expand All @@ -233,6 +237,7 @@ class Assembler {
// Op/En: M
// 1: ModRM:r/m (r)
this.#call_or_jmp(address, reg, 'call')
return this
}

// url: https://www.felixcloutier.com/x86/jmp
Expand All @@ -242,6 +247,7 @@ class Assembler {
// Op/En: M
// 1: ModRM:r/m (r)
this.#call_or_jmp(address, reg, 'jmp')
return this
}

// url: https://www.felixcloutier.com/x86/mov
Expand All @@ -255,6 +261,7 @@ class Assembler {
this.#instr.push(`movabs $${address}, %${reg}`)
this.#codes.push([rex(1, 0, 0, idx < 8 ? 0 : 1), op_mov_imm64 + (idx % 8),
...as_eight_bytes(address)])
return this
}

movreg (src, dest) {
Expand All @@ -268,6 +275,7 @@ class Assembler {
this.#instr.push(`mov %${src}, %${dest}`)
this.#codes.push([rex(1, src_idx > 7 ? 1 : 0, 0, dest_idx > 7 ? 1 : 0),
op_mov_reg_reg, mod_rm(dest_idx % 8, src_idx % 8)])
return this
}

movsrc (src, dest, off) {
Expand All @@ -282,7 +290,7 @@ class Assembler {
this.#instr.push(`mov (%${src}), %${dest}`)
this.#codes.push([rex(1, dest_idx > 7 ? 1 : 0, 0, src_idx > 7 ? 1 : 0),
op_mov_mem_reg, mod_rm(src_idx % 8, dest_idx % 8, funny_registers.includes(src) ? 1 : 0)])
return
return this
}
this.#instr.push(`mov ${off}(%${src}), %${dest}`)
if (src === 'rsp' || src === 'r12') {
Expand All @@ -302,6 +310,7 @@ class Assembler {
op_mov_mem_reg, mod_rm(src_idx % 8, dest_idx % 8, 0b10), ...as_four_bytes(off)])
}
}
return this
}

movdest (src, dest, off) {
Expand All @@ -316,7 +325,7 @@ class Assembler {
this.#instr.push(`mov %${src}, (%${dest})`)
this.#codes.push([rex(1, src_idx > 7 ? 1 : 0, 0, dest_idx > 7 ? 1 : 0),
op_mov_reg_mem, mod_rm(dest_idx % 8, src_idx % 8, funny_registers.includes(dest) ? 1 : 0)])
return
return this
}
this.#instr.push(`mov %${src}, ${off}(%${dest})`)
if (dest === 'rsp' || dest === 'r12') {
Expand All @@ -336,11 +345,13 @@ class Assembler {
op_mov_reg_mem, mod_rm(dest_idx % 8, src_idx % 8, 0b10), ...as_four_bytes(off)])
}
}
return this
}

ret () {
this.#instr.push('ret')
this.#codes.push([0xc3])
return this
}

reset () {
Expand All @@ -349,6 +360,10 @@ class Assembler {
return this
}

bytes () {
return new Uint8Array(this.#codes.flat())
}

get src () {
const { codes, instr } = this
return instr.map((v, i) => [`# ${codes[i].map(v => '0x' + v.toString(16))}`, v]).flat().join('\n') + '\n'
Expand Down
3 changes: 1 addition & 2 deletions lib/asm/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class Compiler {
const address = mmap(0, code.length, PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE,
-1, u32)
assert(address)
memcpy(address, code.ptr, code.length, u32)
assert(addr(u32) === address)
assert(memcpy(address, code.ptr, code.length) === address)
assert(mprotect(address, code.length, PROT_EXEC | PROT_READ) === 0)
return address
}
Expand Down
Loading
Loading