decisions

This commit is contained in:
dcode
2019-03-15 09:26:31 +01:00
parent 139cec0846
commit 968b0321a0
20 changed files with 619 additions and 557 deletions

View File

@ -1166,7 +1166,7 @@
local.get $2
call $~lib/allocator/tlsf/Root#use
)
(func $~lib/runtime/runtime.alloc (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(func $~lib/runtime/ALLOCATE (; 17 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(local $1 i32)
i32.const 1
i32.const 32
@ -2536,7 +2536,7 @@
end
end
)
(func $~lib/runtime/runtime.realloc (; 22 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/runtime/REALLOCATE (; 22 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
@ -2611,8 +2611,8 @@
if
i32.const 0
i32.const 184
i32.const 87
i32.const 10
i32.const 92
i32.const 8
call $~lib/env/abort
unreachable
end
@ -2641,34 +2641,32 @@
i32.store offset=4
local.get $0
)
(func $~lib/runtime/runtime.unrefUnregistered (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(func $~lib/runtime/ASSERT_UNREGISTERED (; 23 ;) (type $FUNCSIG$vi) (param $0 i32)
local.get $0
i32.const 232
i32.lt_u
i32.const 216
i32.le_u
if
i32.const 0
i32.const 184
i32.const 111
i32.const 4
i32.const 145
i32.const 2
call $~lib/env/abort
unreachable
end
local.get $0
i32.const 16
i32.sub
local.tee $0
i32.load
i32.const -1520547049
i32.ne
if
i32.const 0
i32.const 184
i32.const 113
i32.const 4
i32.const 146
i32.const 2
call $~lib/env/abort
unreachable
end
local.get $0
)
(func $start:std/runtime (; 24 ;) (type $FUNCSIG$v)
(local $0 i32)
@ -2710,7 +2708,7 @@
else
i32.const 0
i32.const 72
i32.const 30
i32.const 31
i32.const 2
call $~lib/env/abort
unreachable
@ -2808,7 +2806,7 @@
f64.const 0
call $~lib/env/trace
i32.const 1
call $~lib/runtime/runtime.alloc
call $~lib/runtime/ALLOCATE
global.set $std/runtime/ref1
global.get $std/runtime/ref1
i32.const 16
@ -2821,7 +2819,7 @@
if
i32.const 0
i32.const 72
i32.const 45
i32.const 46
i32.const 0
call $~lib/env/abort
unreachable
@ -2833,7 +2831,7 @@
if
i32.const 0
i32.const 72
i32.const 46
i32.const 47
i32.const 0
call $~lib/env/abort
unreachable
@ -2842,12 +2840,12 @@
local.tee $0
local.get $0
global.get $std/runtime/barrier1
call $~lib/runtime/runtime.realloc
call $~lib/runtime/REALLOCATE
i32.ne
if
i32.const 0
i32.const 72
i32.const 47
i32.const 48
i32.const 0
call $~lib/env/abort
unreachable
@ -2859,14 +2857,14 @@
if
i32.const 0
i32.const 72
i32.const 48
i32.const 49
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/runtime/ref1
global.get $std/runtime/barrier2
call $~lib/runtime/runtime.realloc
call $~lib/runtime/REALLOCATE
global.set $std/runtime/ref2
global.get $std/runtime/ref1
global.get $std/runtime/ref2
@ -2874,7 +2872,7 @@
if
i32.const 0
i32.const 72
i32.const 50
i32.const 51
i32.const 0
call $~lib/env/abort
unreachable
@ -2890,16 +2888,20 @@
if
i32.const 0
i32.const 72
i32.const 52
i32.const 53
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/runtime/ref2
call $~lib/runtime/runtime.unrefUnregistered
local.tee $0
call $~lib/runtime/ASSERT_UNREGISTERED
local.get $0
i32.const 16
i32.sub
call $~lib/memory/memory.free
global.get $std/runtime/barrier2
call $~lib/runtime/runtime.alloc
call $~lib/runtime/ALLOCATE
global.set $std/runtime/ref3
global.get $std/runtime/ref1
global.get $std/runtime/ref3
@ -2907,17 +2909,20 @@
if
i32.const 0
i32.const 72
i32.const 55
i32.const 56
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/runtime/barrier1
call $~lib/runtime/runtime.alloc
call $~lib/runtime/ALLOCATE
global.set $std/runtime/ref4
global.get $std/runtime/ref4
local.tee $0
call $~lib/runtime/runtime.unrefUnregistered
call $~lib/runtime/ASSERT_UNREGISTERED
local.get $0
i32.const 16
i32.sub
i32.const 2
i32.store
local.get $0
@ -2928,7 +2933,7 @@
if
i32.const 0
i32.const 72
i32.const 59
i32.const 60
i32.const 0
call $~lib/env/abort
unreachable
@ -2944,7 +2949,7 @@
if
i32.const 0
i32.const 72
i32.const 61
i32.const 62
i32.const 0
call $~lib/env/abort
unreachable
@ -2956,13 +2961,13 @@
if
i32.const 0
i32.const 72
i32.const 62
i32.const 63
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 10
call $~lib/runtime/runtime.alloc
call $~lib/runtime/ALLOCATE
global.set $std/runtime/ref5
global.get $std/runtime/ref5
i32.const 16
@ -2973,7 +2978,7 @@
if
i32.const 0
i32.const 72
i32.const 65
i32.const 66
i32.const 0
call $~lib/env/abort
unreachable
@ -2989,7 +2994,7 @@
if
i32.const 0
i32.const 72
i32.const 66
i32.const 67
i32.const 0
call $~lib/env/abort
unreachable

View File

@ -1,4 +1,5 @@
import "allocator/tlsf";
import { CLASSID, ADJUST, ALLOCATE, REALLOCATE, REGISTER, DISCARD, HEADER, HEADER_SIZE, HEADER_MAGIC } from "runtime";
var register_ref: usize = 0;
@ -19,48 +20,48 @@ var link_parentRef: usize = 0;
class A {}
class B {}
assert(gc.classId<A>() != gc.classId<B>());
assert(CLASSID<A>() != CLASSID<B>());
function isPowerOf2(x: i32): bool {
return x != 0 && (x & (x - 1)) == 0;
}
assert(runtime.adjust(0) > 0);
assert(ADJUST(0) > 0);
for (let i = 0; i < 9000; ++i) {
assert(isPowerOf2(runtime.adjust(i)));
assert(isPowerOf2(ADJUST(i)));
}
var barrier1 = runtime.adjust(0);
var barrier1 = ADJUST(0);
var barrier2 = barrier1 + 1;
while (runtime.adjust(barrier2 + 1) == runtime.adjust(barrier2)) ++barrier2;
while (ADJUST(barrier2 + 1) == ADJUST(barrier2)) ++barrier2;
var barrier3 = barrier2 + 1;
while (runtime.adjust(barrier3 + 1) == runtime.adjust(barrier3)) ++barrier3;
while (ADJUST(barrier3 + 1) == ADJUST(barrier3)) ++barrier3;
trace("barrier1", 1, barrier1);
trace("barrier2", 1, barrier2);
trace("barrier3", 1, barrier3);
var ref1 = runtime.alloc(1);
var header1 = changetype<runtime.Header>(ref1 - runtime.Header.SIZE);
assert(header1.classId == runtime.Header.MAGIC);
var ref1 = ALLOCATE(1);
var header1 = changetype<HEADER>(ref1 - HEADER_SIZE);
assert(header1.classId == HEADER_MAGIC);
assert(header1.payloadSize == 1);
assert(ref1 == runtime.realloc(ref1, barrier1)); // same segment
assert(ref1 == REALLOCATE(ref1, barrier1)); // same segment
assert(header1.payloadSize == barrier1);
var ref2 = runtime.realloc(ref1, barrier2);
var ref2 = REALLOCATE(ref1, barrier2);
assert(ref1 != ref2); // moves
var header2 = changetype<runtime.Header>(ref2 - runtime.Header.SIZE);
var header2 = changetype<HEADER>(ref2 - HEADER_SIZE);
assert(header2.payloadSize == barrier2);
runtime.freeUnregistered(ref2);
var ref3 = runtime.alloc(barrier2);
DISCARD(ref2);
var ref3 = ALLOCATE(barrier2);
assert(ref1 == ref3); // reuses space of ref1 (free'd in realloc), ref2 (explicitly free'd)
var ref4 = runtime.alloc(barrier1);
gc.register<A>(ref4); // should call __gc_register
var ref4 = ALLOCATE(barrier1);
REGISTER<A>(ref4); // should call __gc_register
assert(register_ref == ref4);
var header4 = changetype<runtime.Header>(register_ref - runtime.Header.SIZE);
assert(header4.classId == gc.classId<A>());
var header4 = changetype<HEADER>(register_ref - HEADER_SIZE);
assert(header4.classId == CLASSID<A>());
assert(header4.payloadSize == barrier1);
var ref5 = runtime.alloc(10);
var ref5 = ALLOCATE(10);
assert(changetype<ArrayBuffer>(ref5).byteLength == 10);
assert(changetype<String>(ref5).length == 5);

View File

@ -36,10 +36,12 @@
(global $~lib/allocator/tlsf/Root.HL_END i32 (i32.const 2912))
(global $~lib/allocator/tlsf/Root.SIZE i32 (i32.const 2916))
(global $~lib/allocator/tlsf/ROOT (mut i32) (i32.const 0))
(global $~lib/runtime/GC_IMPLEMENTED i32 (i32.const 1))
(global $~lib/runtime/HEADER_SIZE i32 (i32.const 16))
(global $~lib/runtime/HEADER_MAGIC i32 (i32.const -1520547049))
(global $std/runtime/register_ref (mut i32) (i32.const 0))
(global $std/runtime/link_ref (mut i32) (i32.const 0))
(global $std/runtime/link_parentRef (mut i32) (i32.const 0))
(global $~lib/gc/gc.implemented i32 (i32.const 1))
(global $std/runtime/barrier1 (mut i32) (i32.const 0))
(global $std/runtime/barrier2 (mut i32) (i32.const 0))
(global $std/runtime/barrier3 (mut i32) (i32.const 0))
@ -71,11 +73,11 @@
unreachable
end
)
(func $~lib/runtime/runtime.adjust (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(func $~lib/runtime/ADJUST (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
i32.const 1
i32.const 32
local.get $0
i32.const 16
global.get $~lib/runtime/HEADER_SIZE
i32.add
i32.const 1
i32.sub
@ -1467,14 +1469,14 @@
end
return
)
(func $~lib/runtime/runtime.alloc (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(func $~lib/runtime/ALLOCATE (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(local $1 i32)
local.get $0
call $~lib/runtime/runtime.adjust
call $~lib/runtime/ADJUST
call $~lib/memory/memory.allocate
local.set $1
local.get $1
i32.const -1520547049
global.get $~lib/runtime/HEADER_MAGIC
i32.store
local.get $1
local.get $0
@ -1486,7 +1488,7 @@
i32.const 0
i32.store offset=12
local.get $1
i32.const 16
global.get $~lib/runtime/HEADER_SIZE
i32.add
)
(func $~lib/util/memory/memcpy (; 24 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32)
@ -3243,14 +3245,14 @@
local.get $0
global.set $std/runtime/register_ref
)
(func $~lib/runtime/runtime.realloc (; 29 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(func $~lib/runtime/REALLOCATE (; 29 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
(local $5 i32)
(local $6 i32)
local.get $0
i32.const 16
global.get $~lib/runtime/HEADER_SIZE
i32.sub
local.set $2
local.get $2
@ -3261,10 +3263,10 @@
i32.lt_u
if
local.get $1
call $~lib/runtime/runtime.adjust
call $~lib/runtime/ADJUST
local.set $4
local.get $3
call $~lib/runtime/runtime.adjust
call $~lib/runtime/ADJUST
i32.const 0
local.get $0
global.get $~lib/memory/HEAP_BASE
@ -3287,7 +3289,7 @@
i32.const 0
i32.store offset=12
local.get $5
i32.const 16
global.get $~lib/runtime/HEADER_SIZE
i32.add
local.set $6
local.get $6
@ -3304,7 +3306,7 @@
call $~lib/memory/memory.fill
local.get $2
i32.load
i32.const -1520547049
global.get $~lib/runtime/HEADER_MAGIC
i32.eq
if
local.get $0
@ -3314,8 +3316,8 @@
if
i32.const 0
i32.const 184
i32.const 87
i32.const 10
i32.const 92
i32.const 8
call $~lib/env/abort
unreachable
end
@ -3347,55 +3349,52 @@
i32.store offset=4
local.get $0
)
(func $~lib/runtime/runtime.unrefUnregistered (; 30 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
(local $1 i32)
(func $~lib/runtime/ASSERT_UNREGISTERED (; 30 ;) (type $FUNCSIG$vi) (param $0 i32)
local.get $0
global.get $~lib/memory/HEAP_BASE
i32.const 16
i32.add
i32.ge_u
i32.gt_u
i32.eqz
if
i32.const 0
i32.const 184
i32.const 111
i32.const 4
i32.const 145
i32.const 2
call $~lib/env/abort
unreachable
end
local.get $0
i32.const 16
global.get $~lib/runtime/HEADER_SIZE
i32.sub
local.set $1
local.get $1
i32.load
i32.const -1520547049
global.get $~lib/runtime/HEADER_MAGIC
i32.eq
i32.eqz
if
i32.const 0
i32.const 184
i32.const 113
i32.const 4
i32.const 146
i32.const 2
call $~lib/env/abort
unreachable
end
local.get $1
)
(func $~lib/runtime/runtime.freeUnregistered<usize> (; 31 ;) (type $FUNCSIG$vi) (param $0 i32)
(func $~lib/runtime/DISCARD (; 31 ;) (type $FUNCSIG$vi) (param $0 i32)
local.get $0
call $~lib/runtime/runtime.unrefUnregistered
call $~lib/runtime/ASSERT_UNREGISTERED
local.get $0
global.get $~lib/runtime/HEADER_SIZE
i32.sub
call $~lib/memory/memory.free
)
(func $~lib/arraybuffer/ArrayBuffer#get:byteLength (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 16
global.get $~lib/runtime/HEADER_SIZE
i32.sub
i32.load offset=4
)
(func $~lib/string/String#get:length (; 33 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32)
local.get $0
i32.const 16
global.get $~lib/runtime/HEADER_SIZE
i32.sub
i32.load offset=4
i32.const 1
@ -3411,20 +3410,20 @@
if
i32.const 0
i32.const 72
i32.const 22
i32.const 23
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 0
call $~lib/runtime/runtime.adjust
call $~lib/runtime/ADJUST
i32.const 0
i32.gt_u
i32.eqz
if
i32.const 0
i32.const 72
i32.const 28
i32.const 29
i32.const 0
call $~lib/env/abort
unreachable
@ -3439,13 +3438,13 @@
i32.eqz
br_if $break|0
local.get $0
call $~lib/runtime/runtime.adjust
call $~lib/runtime/ADJUST
call $std/runtime/isPowerOf2
i32.eqz
if
i32.const 0
i32.const 72
i32.const 30
i32.const 31
i32.const 2
call $~lib/env/abort
unreachable
@ -3460,7 +3459,7 @@
unreachable
end
i32.const 0
call $~lib/runtime/runtime.adjust
call $~lib/runtime/ADJUST
global.set $std/runtime/barrier1
global.get $std/runtime/barrier1
i32.const 1
@ -3471,9 +3470,9 @@
global.get $std/runtime/barrier2
i32.const 1
i32.add
call $~lib/runtime/runtime.adjust
call $~lib/runtime/ADJUST
global.get $std/runtime/barrier2
call $~lib/runtime/runtime.adjust
call $~lib/runtime/ADJUST
i32.eq
if
global.get $std/runtime/barrier2
@ -3493,9 +3492,9 @@
global.get $std/runtime/barrier3
i32.const 1
i32.add
call $~lib/runtime/runtime.adjust
call $~lib/runtime/ADJUST
global.get $std/runtime/barrier3
call $~lib/runtime/runtime.adjust
call $~lib/runtime/ADJUST
i32.eq
if
global.get $std/runtime/barrier3
@ -3534,21 +3533,21 @@
f64.const 0
call $~lib/env/trace
i32.const 1
call $~lib/runtime/runtime.alloc
call $~lib/runtime/ALLOCATE
global.set $std/runtime/ref1
global.get $std/runtime/ref1
i32.const 16
global.get $~lib/runtime/HEADER_SIZE
i32.sub
global.set $std/runtime/header1
global.get $std/runtime/header1
i32.load
i32.const -1520547049
global.get $~lib/runtime/HEADER_MAGIC
i32.eq
i32.eqz
if
i32.const 0
i32.const 72
i32.const 45
i32.const 46
i32.const 0
call $~lib/env/abort
unreachable
@ -3561,7 +3560,7 @@
if
i32.const 0
i32.const 72
i32.const 46
i32.const 47
i32.const 0
call $~lib/env/abort
unreachable
@ -3569,13 +3568,13 @@
global.get $std/runtime/ref1
global.get $std/runtime/ref1
global.get $std/runtime/barrier1
call $~lib/runtime/runtime.realloc
call $~lib/runtime/REALLOCATE
i32.eq
i32.eqz
if
i32.const 0
i32.const 72
i32.const 47
i32.const 48
i32.const 0
call $~lib/env/abort
unreachable
@ -3588,14 +3587,14 @@
if
i32.const 0
i32.const 72
i32.const 48
i32.const 49
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/runtime/ref1
global.get $std/runtime/barrier2
call $~lib/runtime/runtime.realloc
call $~lib/runtime/REALLOCATE
global.set $std/runtime/ref2
global.get $std/runtime/ref1
global.get $std/runtime/ref2
@ -3604,13 +3603,13 @@
if
i32.const 0
i32.const 72
i32.const 50
i32.const 51
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/runtime/ref2
i32.const 16
global.get $~lib/runtime/HEADER_SIZE
i32.sub
global.set $std/runtime/header2
global.get $std/runtime/header2
@ -3621,15 +3620,15 @@
if
i32.const 0
i32.const 72
i32.const 52
i32.const 53
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/runtime/ref2
call $~lib/runtime/runtime.freeUnregistered<usize>
call $~lib/runtime/DISCARD
global.get $std/runtime/barrier2
call $~lib/runtime/runtime.alloc
call $~lib/runtime/ALLOCATE
global.set $std/runtime/ref3
global.get $std/runtime/ref1
global.get $std/runtime/ref3
@ -3638,19 +3637,22 @@
if
i32.const 0
i32.const 72
i32.const 55
i32.const 56
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/runtime/barrier1
call $~lib/runtime/runtime.alloc
call $~lib/runtime/ALLOCATE
global.set $std/runtime/ref4
block $~lib/gc/gc.register<A>|inlined.0 (result i32)
block $~lib/runtime/REGISTER<A>|inlined.0 (result i32)
global.get $std/runtime/ref4
local.set $0
local.get $0
call $~lib/runtime/runtime.unrefUnregistered
call $~lib/runtime/ASSERT_UNREGISTERED
local.get $0
global.get $~lib/runtime/HEADER_SIZE
i32.sub
i32.const 2
i32.store
local.get $0
@ -3665,13 +3667,13 @@
if
i32.const 0
i32.const 72
i32.const 59
i32.const 60
i32.const 0
call $~lib/env/abort
unreachable
end
global.get $std/runtime/register_ref
i32.const 16
global.get $~lib/runtime/HEADER_SIZE
i32.sub
global.set $std/runtime/header4
global.get $std/runtime/header4
@ -3682,7 +3684,7 @@
if
i32.const 0
i32.const 72
i32.const 61
i32.const 62
i32.const 0
call $~lib/env/abort
unreachable
@ -3695,13 +3697,13 @@
if
i32.const 0
i32.const 72
i32.const 62
i32.const 63
i32.const 0
call $~lib/env/abort
unreachable
end
i32.const 10
call $~lib/runtime/runtime.alloc
call $~lib/runtime/ALLOCATE
global.set $std/runtime/ref5
global.get $std/runtime/ref5
call $~lib/arraybuffer/ArrayBuffer#get:byteLength
@ -3711,7 +3713,7 @@
if
i32.const 0
i32.const 72
i32.const 65
i32.const 66
i32.const 0
call $~lib/env/abort
unreachable
@ -3724,7 +3726,7 @@
if
i32.const 0
i32.const 72
i32.const 66
i32.const 67
i32.const 0
call $~lib/env/abort
unreachable