Minor buddy alloc tweaks; Share entire allocator testing infrastructure

This commit is contained in:
dcodeIO 2018-02-20 18:40:30 +01:00
parent d8cdb663cb
commit 16ffddc5d5
12 changed files with 953 additions and 1761 deletions

918
package-lock.json generated
View File

@ -659,9 +659,9 @@
"dev": true "dev": true
}, },
"binaryen": { "binaryen": {
"version": "42.0.0-nightly.20180213", "version": "44.0.0",
"resolved": "https://registry.npmjs.org/binaryen/-/binaryen-42.0.0-nightly.20180213.tgz", "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-44.0.0.tgz",
"integrity": "sha512-K+YMN7qLDUh3ULt5L33Nw/GOOhha4FBvaPMdPmjk+UjV3GsNqpjdi3FX0pG551cZnIZ0+eABrS9voR41QBcK+Q==" "integrity": "sha512-8teFxH0adnhbNv7aBS35scBzu9VIdIksxUPHN0p2ez+bg8VNQgAuizWZJohkejjuwiaC/ESP8Tfb0vD0BRJiqw=="
}, },
"bn.js": { "bn.js": {
"version": "4.11.8", "version": "4.11.8",
@ -874,7 +874,6 @@
"requires": { "requires": {
"anymatch": "1.3.2", "anymatch": "1.3.2",
"async-each": "1.0.1", "async-each": "1.0.1",
"fsevents": "1.1.3",
"glob-parent": "2.0.0", "glob-parent": "2.0.0",
"inherits": "2.0.3", "inherits": "2.0.3",
"is-binary-path": "1.0.1", "is-binary-path": "1.0.1",
@ -1539,910 +1538,6 @@
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
}, },
"fsevents": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.1.3.tgz",
"integrity": "sha512-WIr7iDkdmdbxu/Gh6eKEZJL6KPE74/5MEsf2whTOFNxbIoIixogroLdKYqB6FDav4Wavh/lZdzzd3b2KxIXC5Q==",
"dev": true,
"optional": true,
"requires": {
"nan": "2.8.0",
"node-pre-gyp": "0.6.39"
},
"dependencies": {
"abbrev": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
},
"ajv": {
"version": "4.11.8",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"co": "4.6.0",
"json-stable-stringify": "1.0.1"
}
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true
},
"aproba": {
"version": "1.1.1",
"bundled": true,
"dev": true,
"optional": true
},
"are-we-there-yet": {
"version": "1.1.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"delegates": "1.0.0",
"readable-stream": "2.2.9"
}
},
"asn1": {
"version": "0.2.3",
"bundled": true,
"dev": true,
"optional": true
},
"assert-plus": {
"version": "0.2.0",
"bundled": true,
"dev": true,
"optional": true
},
"asynckit": {
"version": "0.4.0",
"bundled": true,
"dev": true,
"optional": true
},
"aws-sign2": {
"version": "0.6.0",
"bundled": true,
"dev": true,
"optional": true
},
"aws4": {
"version": "1.6.0",
"bundled": true,
"dev": true,
"optional": true
},
"balanced-match": {
"version": "0.4.2",
"bundled": true,
"dev": true
},
"bcrypt-pbkdf": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"tweetnacl": "0.14.5"
}
},
"block-stream": {
"version": "0.0.9",
"bundled": true,
"dev": true,
"requires": {
"inherits": "2.0.3"
}
},
"boom": {
"version": "2.10.1",
"bundled": true,
"dev": true,
"requires": {
"hoek": "2.16.3"
}
},
"brace-expansion": {
"version": "1.1.7",
"bundled": true,
"dev": true,
"requires": {
"balanced-match": "0.4.2",
"concat-map": "0.0.1"
}
},
"buffer-shims": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"caseless": {
"version": "0.12.0",
"bundled": true,
"dev": true,
"optional": true
},
"co": {
"version": "4.6.0",
"bundled": true,
"dev": true,
"optional": true
},
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true
},
"combined-stream": {
"version": "1.0.5",
"bundled": true,
"dev": true,
"requires": {
"delayed-stream": "1.0.0"
}
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
},
"core-util-is": {
"version": "1.0.2",
"bundled": true,
"dev": true
},
"cryptiles": {
"version": "2.0.5",
"bundled": true,
"dev": true,
"requires": {
"boom": "2.10.1"
}
},
"dashdash": {
"version": "1.14.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"assert-plus": "1.0.0"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
}
}
},
"debug": {
"version": "2.6.8",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ms": "2.0.0"
}
},
"deep-extend": {
"version": "0.4.2",
"bundled": true,
"dev": true,
"optional": true
},
"delayed-stream": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"delegates": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
},
"detect-libc": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
},
"ecc-jsbn": {
"version": "0.1.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"jsbn": "0.1.1"
}
},
"extend": {
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true
},
"extsprintf": {
"version": "1.0.2",
"bundled": true,
"dev": true
},
"forever-agent": {
"version": "0.6.1",
"bundled": true,
"dev": true,
"optional": true
},
"form-data": {
"version": "2.1.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"asynckit": "0.4.0",
"combined-stream": "1.0.5",
"mime-types": "2.1.15"
}
},
"fs.realpath": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"fstream": {
"version": "1.0.11",
"bundled": true,
"dev": true,
"requires": {
"graceful-fs": "4.1.11",
"inherits": "2.0.3",
"mkdirp": "0.5.1",
"rimraf": "2.6.1"
}
},
"fstream-ignore": {
"version": "1.0.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"fstream": "1.0.11",
"inherits": "2.0.3",
"minimatch": "3.0.4"
}
},
"gauge": {
"version": "2.7.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"aproba": "1.1.1",
"console-control-strings": "1.1.0",
"has-unicode": "2.0.1",
"object-assign": "4.1.1",
"signal-exit": "3.0.2",
"string-width": "1.0.2",
"strip-ansi": "3.0.1",
"wide-align": "1.1.2"
}
},
"getpass": {
"version": "0.1.7",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"assert-plus": "1.0.0"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
}
}
},
"glob": {
"version": "7.1.2",
"bundled": true,
"dev": true,
"requires": {
"fs.realpath": "1.0.0",
"inflight": "1.0.6",
"inherits": "2.0.3",
"minimatch": "3.0.4",
"once": "1.4.0",
"path-is-absolute": "1.0.1"
}
},
"graceful-fs": {
"version": "4.1.11",
"bundled": true,
"dev": true
},
"har-schema": {
"version": "1.0.5",
"bundled": true,
"dev": true,
"optional": true
},
"har-validator": {
"version": "4.2.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ajv": "4.11.8",
"har-schema": "1.0.5"
}
},
"has-unicode": {
"version": "2.0.1",
"bundled": true,
"dev": true,
"optional": true
},
"hawk": {
"version": "3.1.3",
"bundled": true,
"dev": true,
"requires": {
"boom": "2.10.1",
"cryptiles": "2.0.5",
"hoek": "2.16.3",
"sntp": "1.0.9"
}
},
"hoek": {
"version": "2.16.3",
"bundled": true,
"dev": true
},
"http-signature": {
"version": "1.1.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"assert-plus": "0.2.0",
"jsprim": "1.4.0",
"sshpk": "1.13.0"
}
},
"inflight": {
"version": "1.0.6",
"bundled": true,
"dev": true,
"requires": {
"once": "1.4.0",
"wrappy": "1.0.2"
}
},
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true
},
"ini": {
"version": "1.3.4",
"bundled": true,
"dev": true,
"optional": true
},
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"requires": {
"number-is-nan": "1.0.1"
}
},
"is-typedarray": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
},
"isarray": {
"version": "1.0.0",
"bundled": true,
"dev": true
},
"isstream": {
"version": "0.1.2",
"bundled": true,
"dev": true,
"optional": true
},
"jodid25519": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"jsbn": "0.1.1"
}
},
"jsbn": {
"version": "0.1.1",
"bundled": true,
"dev": true,
"optional": true
},
"json-schema": {
"version": "0.2.3",
"bundled": true,
"dev": true,
"optional": true
},
"json-stable-stringify": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"jsonify": "0.0.0"
}
},
"json-stringify-safe": {
"version": "5.0.1",
"bundled": true,
"dev": true,
"optional": true
},
"jsonify": {
"version": "0.0.0",
"bundled": true,
"dev": true,
"optional": true
},
"jsprim": {
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"assert-plus": "1.0.0",
"extsprintf": "1.0.2",
"json-schema": "0.2.3",
"verror": "1.3.6"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
}
}
},
"mime-db": {
"version": "1.27.0",
"bundled": true,
"dev": true
},
"mime-types": {
"version": "2.1.15",
"bundled": true,
"dev": true,
"requires": {
"mime-db": "1.27.0"
}
},
"minimatch": {
"version": "3.0.4",
"bundled": true,
"dev": true,
"requires": {
"brace-expansion": "1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
},
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"dev": true,
"requires": {
"minimist": "0.0.8"
}
},
"ms": {
"version": "2.0.0",
"bundled": true,
"dev": true,
"optional": true
},
"node-pre-gyp": {
"version": "0.6.39",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"detect-libc": "1.0.2",
"hawk": "3.1.3",
"mkdirp": "0.5.1",
"nopt": "4.0.1",
"npmlog": "4.1.0",
"rc": "1.2.1",
"request": "2.81.0",
"rimraf": "2.6.1",
"semver": "5.3.0",
"tar": "2.2.1",
"tar-pack": "3.4.0"
}
},
"nopt": {
"version": "4.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"abbrev": "1.1.0",
"osenv": "0.1.4"
}
},
"npmlog": {
"version": "4.1.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"are-we-there-yet": "1.1.4",
"console-control-strings": "1.1.0",
"gauge": "2.7.4",
"set-blocking": "2.0.0"
}
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true
},
"oauth-sign": {
"version": "0.8.2",
"bundled": true,
"dev": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
"bundled": true,
"dev": true,
"optional": true
},
"once": {
"version": "1.4.0",
"bundled": true,
"dev": true,
"requires": {
"wrappy": "1.0.2"
}
},
"os-homedir": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
},
"os-tmpdir": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
},
"osenv": {
"version": "0.1.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"os-homedir": "1.0.2",
"os-tmpdir": "1.0.2"
}
},
"path-is-absolute": {
"version": "1.0.1",
"bundled": true,
"dev": true
},
"performance-now": {
"version": "0.2.0",
"bundled": true,
"dev": true,
"optional": true
},
"process-nextick-args": {
"version": "1.0.7",
"bundled": true,
"dev": true
},
"punycode": {
"version": "1.4.1",
"bundled": true,
"dev": true,
"optional": true
},
"qs": {
"version": "6.4.0",
"bundled": true,
"dev": true,
"optional": true
},
"rc": {
"version": "1.2.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"deep-extend": "0.4.2",
"ini": "1.3.4",
"minimist": "1.2.0",
"strip-json-comments": "2.0.1"
},
"dependencies": {
"minimist": {
"version": "1.2.0",
"bundled": true,
"dev": true,
"optional": true
}
}
},
"readable-stream": {
"version": "2.2.9",
"bundled": true,
"dev": true,
"requires": {
"buffer-shims": "1.0.0",
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "1.0.0",
"process-nextick-args": "1.0.7",
"string_decoder": "1.0.1",
"util-deprecate": "1.0.2"
}
},
"request": {
"version": "2.81.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"aws-sign2": "0.6.0",
"aws4": "1.6.0",
"caseless": "0.12.0",
"combined-stream": "1.0.5",
"extend": "3.0.1",
"forever-agent": "0.6.1",
"form-data": "2.1.4",
"har-validator": "4.2.1",
"hawk": "3.1.3",
"http-signature": "1.1.1",
"is-typedarray": "1.0.0",
"isstream": "0.1.2",
"json-stringify-safe": "5.0.1",
"mime-types": "2.1.15",
"oauth-sign": "0.8.2",
"performance-now": "0.2.0",
"qs": "6.4.0",
"safe-buffer": "5.0.1",
"stringstream": "0.0.5",
"tough-cookie": "2.3.2",
"tunnel-agent": "0.6.0",
"uuid": "3.0.1"
}
},
"rimraf": {
"version": "2.6.1",
"bundled": true,
"dev": true,
"requires": {
"glob": "7.1.2"
}
},
"safe-buffer": {
"version": "5.0.1",
"bundled": true,
"dev": true
},
"semver": {
"version": "5.3.0",
"bundled": true,
"dev": true,
"optional": true
},
"set-blocking": {
"version": "2.0.0",
"bundled": true,
"dev": true,
"optional": true
},
"signal-exit": {
"version": "3.0.2",
"bundled": true,
"dev": true,
"optional": true
},
"sntp": {
"version": "1.0.9",
"bundled": true,
"dev": true,
"requires": {
"hoek": "2.16.3"
}
},
"sshpk": {
"version": "1.13.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"asn1": "0.2.3",
"assert-plus": "1.0.0",
"bcrypt-pbkdf": "1.0.1",
"dashdash": "1.14.1",
"ecc-jsbn": "0.1.1",
"getpass": "0.1.7",
"jodid25519": "1.0.2",
"jsbn": "0.1.1",
"tweetnacl": "0.14.5"
},
"dependencies": {
"assert-plus": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
}
}
},
"string-width": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"requires": {
"code-point-at": "1.1.0",
"is-fullwidth-code-point": "1.0.0",
"strip-ansi": "3.0.1"
}
},
"string_decoder": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"requires": {
"safe-buffer": "5.0.1"
}
},
"stringstream": {
"version": "0.0.5",
"bundled": true,
"dev": true,
"optional": true
},
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"dev": true,
"requires": {
"ansi-regex": "2.1.1"
}
},
"strip-json-comments": {
"version": "2.0.1",
"bundled": true,
"dev": true,
"optional": true
},
"tar": {
"version": "2.2.1",
"bundled": true,
"dev": true,
"requires": {
"block-stream": "0.0.9",
"fstream": "1.0.11",
"inherits": "2.0.3"
}
},
"tar-pack": {
"version": "3.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"debug": "2.6.8",
"fstream": "1.0.11",
"fstream-ignore": "1.0.5",
"once": "1.4.0",
"readable-stream": "2.2.9",
"rimraf": "2.6.1",
"tar": "2.2.1",
"uid-number": "0.0.6"
}
},
"tough-cookie": {
"version": "2.3.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"punycode": "1.4.1"
}
},
"tunnel-agent": {
"version": "0.6.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "5.0.1"
}
},
"tweetnacl": {
"version": "0.14.5",
"bundled": true,
"dev": true,
"optional": true
},
"uid-number": {
"version": "0.0.6",
"bundled": true,
"dev": true,
"optional": true
},
"util-deprecate": {
"version": "1.0.2",
"bundled": true,
"dev": true
},
"uuid": {
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true
},
"verror": {
"version": "1.3.6",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"extsprintf": "1.0.2"
}
},
"wide-align": {
"version": "1.1.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"string-width": "1.0.2"
}
},
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true
}
}
},
"get-caller-file": { "get-caller-file": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.2.tgz", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.2.tgz",
@ -3225,13 +2320,6 @@
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true "dev": true
}, },
"nan": {
"version": "2.8.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.8.0.tgz",
"integrity": "sha1-7XFfP+neArV6XmJS2QqWZ14fCFo=",
"dev": true,
"optional": true
},
"nanomatch": { "nanomatch": {
"version": "1.2.7", "version": "1.2.7",
"resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.7.tgz", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.7.tgz",

View File

@ -11,7 +11,7 @@
"url": "https://github.com/AssemblyScript/assemblyscript/issues" "url": "https://github.com/AssemblyScript/assemblyscript/issues"
}, },
"dependencies": { "dependencies": {
"binaryen": "42.0.0-nightly.20180213", "binaryen": "44.0.0",
"glob": "^7.1.2", "glob": "^7.1.2",
"long": "^4.0.0", "long": "^4.0.0",
"minimist": "^1.2.0", "minimist": "^1.2.0",

View File

@ -89,12 +89,12 @@ class List {
* for that size. The bucket at index 0 corresponds to an allocation size of * for that size. The bucket at index 0 corresponds to an allocation size of
* MAX_ALLOC (i.e. the whole address space). * MAX_ALLOC (i.e. the whole address space).
*/ */
var BUCKET_START: usize = HEAP_BASE; var BUCKETS_START: usize = HEAP_BASE;
var BUCKET_END: usize = BUCKET_START + BUCKET_COUNT * List.SIZE; var BUCKETS_END: usize = BUCKETS_START + BUCKET_COUNT * List.SIZE;
function get_bucket(index: usize): List { function buckets$get(index: usize): List {
assert(index < BUCKET_COUNT); assert(index < BUCKET_COUNT);
return changetype<List>(BUCKET_START + index * List.SIZE); return changetype<List>(BUCKETS_START + index * List.SIZE);
} }
/* /*
@ -135,17 +135,17 @@ var bucket_limit: usize;
* since we only ever care about parent nodes. * since we only ever care about parent nodes.
*/ */
const SPLIT_COUNT: usize = (1 << (BUCKET_COUNT - 1)) / 8; const SPLIT_COUNT: usize = (1 << (BUCKET_COUNT - 1)) / 8;
var SPLIT_START: usize = BUCKET_END; var NODE_IS_SPLIT_START: usize = BUCKETS_END;
var SPLIT_END: usize = SPLIT_START + SPLIT_COUNT * sizeof<u8>(); var NODE_IS_SPLIT_END: usize = NODE_IS_SPLIT_START + SPLIT_COUNT * sizeof<u8>();
function node_is_split(index: usize): i32 { function node_is_split$get(index: usize): i32 {
assert(index < SPLIT_COUNT); assert(index < SPLIT_COUNT);
return load<u8>(SPLIT_START + index); return load<u8>(NODE_IS_SPLIT_START + index);
} }
function node_set_split(index: usize, state: i32): void { function node_is_split$set(index: usize, state: i32): void {
assert(index < SPLIT_COUNT); assert(index < SPLIT_COUNT);
store<u8>(SPLIT_START + index, state); store<u8>(NODE_IS_SPLIT_START + index, state);
} }
/* /*
@ -166,15 +166,21 @@ var max_ptr: usize;
* front. It's only reserved when it's needed by calling this function. This * front. It's only reserved when it's needed by calling this function. This
* will return false if the memory could not be reserved. * will return false if the memory could not be reserved.
*/ */
function update_max_ptr(new_value: usize): bool { function update_max_ptr(new_value: usize): i32 {
if (new_value > max_ptr) { if (new_value > max_ptr) {
var pages = (((new_value - max_ptr) + 0xffff) & ~0xffff) >>> 16; // if (brk(new_value)) {
if (grow_memory(pages) < 0) { // return 0;
return false; // }
var oldPages = current_memory();
var newPages = <u32>(((new_value + 0xffff) & ~0xffff) >> 16);
assert(newPages > oldPages);
if (grow_memory(newPages - oldPages) < 0) {
return 0;
} }
max_ptr = new_value; // max_ptr = new_value;
max_ptr = <usize>newPages << 16;
} }
return true; return 1;
} }
/* /*
@ -246,7 +252,7 @@ function node_for_ptr(ptr: usize, bucket: usize): usize {
*/ */
function parent_is_split(index: usize): i32 { function parent_is_split(index: usize): i32 {
index = (index - 1) / 2; index = (index - 1) / 2;
return (node_is_split(index / 8) >> <i32>(index % 8)) & 1; return (node_is_split$get(index / 8) >>> <i32>(index % 8)) & 1;
} }
/* /*
@ -255,7 +261,9 @@ function parent_is_split(index: usize): i32 {
function flip_parent_is_split(index: usize): void { function flip_parent_is_split(index: usize): void {
index = (index - 1) / 2; index = (index - 1) / 2;
var indexDiv8 = index / 8; var indexDiv8 = index / 8;
node_set_split(indexDiv8, node_is_split(indexDiv8) ^ <i32>(1 << (index % 8))); node_is_split$set(indexDiv8,
node_is_split$get(indexDiv8) ^ <i32>(1 << (index % 8))
);
} }
/* /*
@ -292,8 +300,8 @@ function lower_bucket_limit(bucket: usize): u32 {
*/ */
if (!parent_is_split(root)) { if (!parent_is_split(root)) {
list_remove(changetype<List>(base_ptr)); list_remove(changetype<List>(base_ptr));
list_init(get_bucket(--bucket_limit)); list_init(buckets$get(--bucket_limit));
list_push(get_bucket(bucket_limit), changetype<List>(base_ptr)); list_push(buckets$get(bucket_limit), changetype<List>(base_ptr));
continue; continue;
} }
@ -309,8 +317,8 @@ function lower_bucket_limit(bucket: usize): u32 {
if (!update_max_ptr(right_child + List.SIZE)) { if (!update_max_ptr(right_child + List.SIZE)) {
return 0; return 0;
} }
list_push(get_bucket(bucket_limit), changetype<List>(right_child)); list_push(buckets$get(bucket_limit), changetype<List>(right_child));
list_init(get_bucket(--bucket_limit)); list_init(buckets$get(--bucket_limit));
/* /*
* Set the grandparent's SPLIT flag so if we need to lower the bucket limit * Set the grandparent's SPLIT flag so if we need to lower the bucket limit
@ -325,8 +333,6 @@ function lower_bucket_limit(bucket: usize): u32 {
return 1; return 1;
} }
declare function logi(i: i32): void;
@global @global
function allocate_memory(request: usize): usize { function allocate_memory(request: usize): usize {
var original_bucket: usize, bucket: usize; var original_bucket: usize, bucket: usize;
@ -346,12 +352,15 @@ function allocate_memory(request: usize): usize {
* possible allocation size. More memory will be reserved later as needed. * possible allocation size. More memory will be reserved later as needed.
*/ */
if (base_ptr == 0) { if (base_ptr == 0) {
base_ptr = SPLIT_END; // base_ptr = max_ptr = (uint8_t *)sbrk(0);
max_ptr = <usize>current_memory() << 16; // differs, must grow first base_ptr = (NODE_IS_SPLIT_END + 7) & ~7; // must be aligned
max_ptr = <usize>current_memory() << 16; // must grow first
bucket_limit = BUCKET_COUNT - 1; bucket_limit = BUCKET_COUNT - 1;
update_max_ptr(base_ptr + List.SIZE); if (!update_max_ptr(base_ptr + List.SIZE)) {
list_init(get_bucket(BUCKET_COUNT - 1)); return 0;
list_push(get_bucket(BUCKET_COUNT - 1), changetype<List>(base_ptr)); }
list_init(buckets$get(BUCKET_COUNT - 1));
list_push(buckets$get(BUCKET_COUNT - 1), changetype<List>(base_ptr));
} }
/* /*
@ -382,7 +391,7 @@ function allocate_memory(request: usize): usize {
* Try to pop a block off the free list for this bucket. If the free list * Try to pop a block off the free list for this bucket. If the free list
* is empty, we're going to have to split a larger block instead. * is empty, we're going to have to split a larger block instead.
*/ */
ptr = changetype<usize>(list_pop(get_bucket(bucket))); ptr = changetype<usize>(list_pop(buckets$get(bucket)));
if (!ptr) { if (!ptr) {
/* /*
* If we're not at the root of the tree or it's impossible to grow the * If we're not at the root of the tree or it's impossible to grow the
@ -403,7 +412,7 @@ function allocate_memory(request: usize): usize {
if (!lower_bucket_limit(bucket - 1)) { if (!lower_bucket_limit(bucket - 1)) {
return 0; return 0;
} }
ptr = changetype<usize>(list_pop(get_bucket(bucket))); ptr = changetype<usize>(list_pop(buckets$get(bucket)));
} }
/* /*
@ -413,7 +422,7 @@ function allocate_memory(request: usize): usize {
size = 1 << (MAX_ALLOC_LOG2 - bucket); size = 1 << (MAX_ALLOC_LOG2 - bucket);
bytes_needed = bucket < original_bucket ? size / 2 + List.SIZE : size; bytes_needed = bucket < original_bucket ? size / 2 + List.SIZE : size;
if (!update_max_ptr(ptr + bytes_needed)) { if (!update_max_ptr(ptr + bytes_needed)) {
list_push(get_bucket(bucket), changetype<List>(ptr)); list_push(buckets$get(bucket), changetype<List>(ptr));
return 0; return 0;
} }
@ -444,7 +453,10 @@ function allocate_memory(request: usize): usize {
i = i * 2 + 1; i = i * 2 + 1;
bucket++; bucket++;
flip_parent_is_split(i); flip_parent_is_split(i);
list_push(get_bucket(bucket), changetype<List>(ptr_for_node(i + 1, bucket))); list_push(
buckets$get(bucket),
changetype<List>(ptr_for_node(i + 1, bucket))
);
} }
/* /*
@ -521,5 +533,5 @@ function free_memory(ptr: usize): void {
* followed by a "malloc" of the same size to ideally use the same address * followed by a "malloc" of the same size to ideally use the same address
* for better memory locality. * for better memory locality.
*/ */
list_push(get_bucket(bucket), changetype<List>(ptr_for_node(i, bucket))); list_push(buckets$get(bucket), changetype<List>(ptr_for_node(i, bucket)));
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@ function test(file) {
return String.fromCharCode.apply(String, str); return String.fromCharCode.apply(String, str);
} }
require("../runner")(exports, 20, 20000); require("../runner")(exports, 50, 20000);
console.log("mem final: " + exports.memory.buffer.byteLength); console.log("mem final: " + exports.memory.buffer.byteLength);
console.log(); console.log();

View File

@ -4,6 +4,7 @@
"build": "npm run build:untouched && npm run build:optimized", "build": "npm run build:untouched && npm run build:optimized",
"build:untouched": "asc assembly/index.ts -t buddy.untouched.wat -b buddy.untouched.wasm --validate --sourceMap --measure", "build:untouched": "asc assembly/index.ts -t buddy.untouched.wat -b buddy.untouched.wasm --validate --sourceMap --measure",
"build:optimized": "asc assembly/index.ts -t buddy.optimized.wat -b buddy.optimized.wasm --validate --sourceMap --measure --noDebug --noAssert --optimize", "build:optimized": "asc assembly/index.ts -t buddy.optimized.wat -b buddy.optimized.wasm --validate --sourceMap --measure --noDebug --noAssert --optimize",
"test": "node ./index" "test": "node ./index",
"test:forever": "node ../forever buddy"
} }
} }

View File

@ -5,7 +5,10 @@ var child_process = require("child_process");
var count = 0; var count = 0;
while (true) { while (true) {
console.log("[ #" + ++count + " ]\n"); console.log("[ #" + ++count + " ]\n");
var res = child_process.spawnSync("node", [ __dirname ], { stdio: "inherit" }); var script = process.argv.length > 2
? __dirname + "/" + process.argv[2]
: __dirname;
var res = child_process.spawnSync("node", [ script ], { stdio: "inherit" });
if (res.status !== 0) if (res.status !== 0)
throw Error("exited with " + res.status); throw Error("exited with " + res.status);
if (res.error) if (res.error)

View File

@ -35,7 +35,8 @@ function runner(allocator, runs, allocs) {
var base = allocator.allocate_memory(64); var base = allocator.allocate_memory(64);
console.log("base: " + base); console.log("base: " + base);
allocator.free_memory(base); allocator.free_memory(base);
console.log("mem initial: " + allocator.memory.buffer.byteLength); var currentMem = allocator.memory.buffer.byteLength;
console.log("mem initial: " + currentMem);
try { try {
for (var j = 0; j < runs; ++j) { for (var j = 0; j < runs; ++j) {
@ -64,6 +65,10 @@ function runner(allocator, runs, allocs) {
if (ptr !== base) if (ptr !== base)
throw Error("expected " + base + " but got " + ptr); throw Error("expected " + base + " but got " + ptr);
allocator.free_memory(ptr); allocator.free_memory(ptr);
if (allocator.memory.buffer.byteLength > currentMem) {
currentMem = allocator.memory.buffer.byteLength;
console.log("mem changed: " + currentMem);
}
} }
} finally { } finally {
// mem(allocator.memory, 0, 0x10000); // mem(allocator.memory, 0, 0x10000);

View File

@ -19,7 +19,7 @@ function test(file) {
return String.fromCharCode.apply(String, str); return String.fromCharCode.apply(String, str);
} }
require("../runner")(exports, 20, 20000); // picked so I/O isn't the bottleneck require("../runner")(exports, 50, 20000); // picked so I/O isn't the bottleneck
console.log("mem final: " + exports.memory.buffer.byteLength); console.log("mem final: " + exports.memory.buffer.byteLength);
console.log(); console.log();
} }

View File

@ -5,6 +5,6 @@
"build:untouched": "asc assembly/index.ts -t tlsf.untouched.wat -b tlsf.untouched.wasm --validate --sourceMap --measure", "build:untouched": "asc assembly/index.ts -t tlsf.untouched.wat -b tlsf.untouched.wasm --validate --sourceMap --measure",
"build:optimized": "asc assembly/index.ts -t tlsf.optimized.wat -b tlsf.optimized.wasm --validate --sourceMap --measure --noDebug --noAssert --optimize", "build:optimized": "asc assembly/index.ts -t tlsf.optimized.wat -b tlsf.optimized.wasm --validate --sourceMap --measure --noDebug --noAssert --optimize",
"test": "node ./index", "test": "node ./index",
"test:forever": "node ./forever" "test:forever": "node ../forever tlsf"
} }
} }

View File

@ -2,16 +2,22 @@
(type $i (func (param i32) (result i32))) (type $i (func (param i32) (result i32)))
(memory $0 0) (memory $0 0)
(export "test/switch/case/eval" (func $test/switch/case/eval)) (export "test/switch/case/eval" (func $test/switch/case/eval))
(export "const" (func $test/switch/case/eval))
(import "env" "switch" (func $switch (param i32 i32 i32 i32))) (import "env" "switch" (func $switch (param i32 i32 i32 i32)))
(global $HEAP_BASE i32 (i32.const 4)) (global $INT i32 (i32.const 4))
(global $FLT i32 (f32.const -4.0)) (global $FLT i32 (f32.const -4.0))
(global $DBL i32 (f64.const -4.0)) (global $DBL i32 (f64.const -4.0))
(func $test/switch/case/eval (; 0 ;) (type $i) (param $0 i32) (result i32) (func $test/switch/case/eval (; 0 ;) (type $i) (param $0 i32) (result i32)
(if (result i32) (if (result i32)
(i32.eqz (i32.eq
(get_global $HEAP_BASE) (get_global $INT)
) (i32.load
(i32.const 0) (i32.const 0)
)
)
(i32.ctz
(i32.const 0)
)
(get_local $0) (get_local $0)
) )
) )