@swf2es/codegen 0.1.35 → 0.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codegen.d.ts +69 -3
- package/dist/codegen.js +46 -6
- package/dist/codegen.wasm +0 -0
- package/dist/index.d.ts +31 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +160 -28
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +46 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +201 -0
- package/dist/keys.js.map +1 -0
- package/dist/sha256.d.ts +7 -0
- package/dist/sha256.d.ts.map +1 -0
- package/dist/sha256.js +111 -0
- package/dist/sha256.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +197 -37
- package/src/keys.ts +296 -0
- package/src/sha256.ts +127 -0
package/dist/codegen.d.ts
CHANGED
|
@@ -131,9 +131,10 @@ declare namespace __AdaptedExports {
|
|
|
131
131
|
export function domainChild(parent: number): number;
|
|
132
132
|
/**
|
|
133
133
|
* assembly/compile/domainCompact
|
|
134
|
+
* @param stepped `bool`
|
|
134
135
|
* @returns `bool`
|
|
135
136
|
*/
|
|
136
|
-
export function domainCompact(): boolean;
|
|
137
|
+
export function domainCompact(stepped?: boolean): boolean;
|
|
137
138
|
/**
|
|
138
139
|
* assembly/compile/domainContext
|
|
139
140
|
* @param index `i32`
|
|
@@ -162,12 +163,53 @@ declare namespace __AdaptedExports {
|
|
|
162
163
|
* @param asType `bool`
|
|
163
164
|
*/
|
|
164
165
|
export function domainFound(appDomain: number, nsKind: number, uri: string, name: string, abc: number, asType: boolean): void;
|
|
166
|
+
/**
|
|
167
|
+
* assembly/compile/domainKeyFork
|
|
168
|
+
* @param appDomain `i32`
|
|
169
|
+
* @returns `i32`
|
|
170
|
+
*/
|
|
171
|
+
export function domainKeyFork(appDomain: number): number;
|
|
172
|
+
/**
|
|
173
|
+
* assembly/compile/domainKeyHeaderBytes
|
|
174
|
+
* @param index `i32`
|
|
175
|
+
* @returns `usize`
|
|
176
|
+
*/
|
|
177
|
+
export function domainKeyHeaderBytes(index?: number): number;
|
|
178
|
+
/**
|
|
179
|
+
* assembly/compile/domainKeyLogBytes
|
|
180
|
+
* @param appDomain `i32`
|
|
181
|
+
* @param after `i32`
|
|
182
|
+
* @param from `i32`
|
|
183
|
+
* @param to `i32`
|
|
184
|
+
* @param block `i32`
|
|
185
|
+
* @param filled `i32`
|
|
186
|
+
* @returns `usize`
|
|
187
|
+
*/
|
|
188
|
+
export function domainKeyLogBytes(appDomain: number, after: number, from: number, to: number, block: number, filled: number): number;
|
|
165
189
|
/**
|
|
166
190
|
* assembly/compile/domainLinked
|
|
167
191
|
* @param index `i32`
|
|
168
192
|
* @returns `~lib/string/String`
|
|
169
193
|
*/
|
|
170
194
|
export function domainLinked(index?: number): string;
|
|
195
|
+
/**
|
|
196
|
+
* assembly/compile/domainLoad
|
|
197
|
+
* @param words `~lib/typedarray/Uint8Array`
|
|
198
|
+
* @returns `bool`
|
|
199
|
+
*/
|
|
200
|
+
export function domainLoad(words: Uint8Array): boolean;
|
|
201
|
+
/**
|
|
202
|
+
* assembly/compile/domainLoadAbc
|
|
203
|
+
* @param index `i32`
|
|
204
|
+
* @param bytes `~lib/typedarray/Uint8Array`
|
|
205
|
+
* @returns `i32`
|
|
206
|
+
*/
|
|
207
|
+
export function domainLoadAbc(index: number, bytes: Uint8Array): number;
|
|
208
|
+
/**
|
|
209
|
+
* assembly/compile/domainLoadRebuild
|
|
210
|
+
* @returns `bool`
|
|
211
|
+
*/
|
|
212
|
+
export function domainLoadRebuild(): boolean;
|
|
171
213
|
/**
|
|
172
214
|
* assembly/compile/domainLogMark
|
|
173
215
|
* @returns `i32`
|
|
@@ -213,6 +255,17 @@ declare namespace __AdaptedExports {
|
|
|
213
255
|
* @returns `usize`
|
|
214
256
|
*/
|
|
215
257
|
export function domainModuleMoreBytes(): number;
|
|
258
|
+
/**
|
|
259
|
+
* assembly/compile/domainParent
|
|
260
|
+
* @param appDomain `i32`
|
|
261
|
+
* @returns `i32`
|
|
262
|
+
*/
|
|
263
|
+
export function domainParent(appDomain: number): number;
|
|
264
|
+
/**
|
|
265
|
+
* assembly/compile/domainRebuildStep
|
|
266
|
+
* @returns `i32`
|
|
267
|
+
*/
|
|
268
|
+
export function domainRebuildStep(): number;
|
|
216
269
|
/**
|
|
217
270
|
* assembly/compile/domainReplay
|
|
218
271
|
* @param log `~lib/string/String`
|
|
@@ -240,9 +293,21 @@ declare namespace __AdaptedExports {
|
|
|
240
293
|
/**
|
|
241
294
|
* assembly/compile/domainRevive
|
|
242
295
|
* @param appDomain `i32`
|
|
296
|
+
* @param stepped `bool`
|
|
243
297
|
* @returns `i32`
|
|
244
298
|
*/
|
|
245
|
-
export function domainRevive(appDomain: number): number;
|
|
299
|
+
export function domainRevive(appDomain: number, stepped?: boolean): number;
|
|
300
|
+
/**
|
|
301
|
+
* assembly/compile/domainSaveBytes
|
|
302
|
+
* @returns `usize`
|
|
303
|
+
*/
|
|
304
|
+
export function domainSaveBytes(): number;
|
|
305
|
+
/**
|
|
306
|
+
* assembly/compile/domainSavedAbcBytes
|
|
307
|
+
* @param index `i32`
|
|
308
|
+
* @returns `usize`
|
|
309
|
+
*/
|
|
310
|
+
export function domainSavedAbcBytes(index: number): number;
|
|
246
311
|
/**
|
|
247
312
|
* assembly/compile/domainSourceMap
|
|
248
313
|
* @returns `~lib/string/String`
|
|
@@ -261,9 +326,10 @@ declare namespace __AdaptedExports {
|
|
|
261
326
|
export function domainUsage(): string;
|
|
262
327
|
/**
|
|
263
328
|
* assembly/compile/domainWantsCompact
|
|
329
|
+
* @param want `i32`
|
|
264
330
|
* @returns `bool`
|
|
265
331
|
*/
|
|
266
|
-
export function domainWantsCompact(): boolean;
|
|
332
|
+
export function domainWantsCompact(want?: number): boolean;
|
|
267
333
|
/**
|
|
268
334
|
* assembly/output/outputLength
|
|
269
335
|
* @returns `u32`
|
package/dist/codegen.js
CHANGED
|
@@ -124,9 +124,11 @@ export async function instantiate(module, imports = {}) {
|
|
|
124
124
|
exports.__setArgumentsLength(arguments.length);
|
|
125
125
|
return exports.domainAdd(bytes, builtin, appDomain);
|
|
126
126
|
},
|
|
127
|
-
domainCompact() {
|
|
128
|
-
// assembly/compile/domainCompact() => bool
|
|
129
|
-
|
|
127
|
+
domainCompact(stepped) {
|
|
128
|
+
// assembly/compile/domainCompact(bool?) => bool
|
|
129
|
+
stepped = stepped ? 1 : 0;
|
|
130
|
+
exports.__setArgumentsLength(arguments.length);
|
|
131
|
+
return exports.domainCompact(stepped) != 0;
|
|
130
132
|
},
|
|
131
133
|
domainContext(index, after, upTo) {
|
|
132
134
|
// assembly/compile/domainContext(i32?, i32?, i32?) => ~lib/string/String
|
|
@@ -144,11 +146,34 @@ export async function instantiate(module, imports = {}) {
|
|
|
144
146
|
__release(uri);
|
|
145
147
|
}
|
|
146
148
|
},
|
|
149
|
+
domainKeyHeaderBytes(index) {
|
|
150
|
+
// assembly/compile/domainKeyHeaderBytes(i32?) => usize
|
|
151
|
+
exports.__setArgumentsLength(arguments.length);
|
|
152
|
+
return exports.domainKeyHeaderBytes(index) >>> 0;
|
|
153
|
+
},
|
|
154
|
+
domainKeyLogBytes(appDomain, after, from, to, block, filled) {
|
|
155
|
+
// assembly/compile/domainKeyLogBytes(i32, i32, i32, i32, i32, i32) => usize
|
|
156
|
+
return exports.domainKeyLogBytes(appDomain, after, from, to, block, filled) >>> 0;
|
|
157
|
+
},
|
|
147
158
|
domainLinked(index) {
|
|
148
159
|
// assembly/compile/domainLinked(i32?) => ~lib/string/String
|
|
149
160
|
exports.__setArgumentsLength(arguments.length);
|
|
150
161
|
return __liftString(exports.domainLinked(index) >>> 0);
|
|
151
162
|
},
|
|
163
|
+
domainLoad(words) {
|
|
164
|
+
// assembly/compile/domainLoad(~lib/typedarray/Uint8Array) => bool
|
|
165
|
+
words = __lowerTypedArray(Uint8Array, 27, 0, words) || __notnull();
|
|
166
|
+
return exports.domainLoad(words) != 0;
|
|
167
|
+
},
|
|
168
|
+
domainLoadAbc(index, bytes) {
|
|
169
|
+
// assembly/compile/domainLoadAbc(i32, ~lib/typedarray/Uint8Array) => i32
|
|
170
|
+
bytes = __lowerTypedArray(Uint8Array, 27, 0, bytes) || __notnull();
|
|
171
|
+
return exports.domainLoadAbc(index, bytes);
|
|
172
|
+
},
|
|
173
|
+
domainLoadRebuild() {
|
|
174
|
+
// assembly/compile/domainLoadRebuild() => bool
|
|
175
|
+
return exports.domainLoadRebuild() != 0;
|
|
176
|
+
},
|
|
152
177
|
domainLogSince(mark, index) {
|
|
153
178
|
// assembly/compile/domainLogSince(i32, i32?) => ~lib/string/String
|
|
154
179
|
exports.__setArgumentsLength(arguments.length);
|
|
@@ -197,6 +222,20 @@ export async function instantiate(module, imports = {}) {
|
|
|
197
222
|
// assembly/compile/domainRevision() => ~lib/string/String
|
|
198
223
|
return __liftString(exports.domainRevision() >>> 0);
|
|
199
224
|
},
|
|
225
|
+
domainRevive(appDomain, stepped) {
|
|
226
|
+
// assembly/compile/domainRevive(i32, bool?) => i32
|
|
227
|
+
stepped = stepped ? 1 : 0;
|
|
228
|
+
exports.__setArgumentsLength(arguments.length);
|
|
229
|
+
return exports.domainRevive(appDomain, stepped);
|
|
230
|
+
},
|
|
231
|
+
domainSaveBytes() {
|
|
232
|
+
// assembly/compile/domainSaveBytes() => usize
|
|
233
|
+
return exports.domainSaveBytes() >>> 0;
|
|
234
|
+
},
|
|
235
|
+
domainSavedAbcBytes(index) {
|
|
236
|
+
// assembly/compile/domainSavedAbcBytes(i32) => usize
|
|
237
|
+
return exports.domainSavedAbcBytes(index) >>> 0;
|
|
238
|
+
},
|
|
200
239
|
domainSourceMap() {
|
|
201
240
|
// assembly/compile/domainSourceMap() => ~lib/string/String
|
|
202
241
|
return __liftString(exports.domainSourceMap() >>> 0);
|
|
@@ -205,9 +244,10 @@ export async function instantiate(module, imports = {}) {
|
|
|
205
244
|
// assembly/compile/domainUsage() => ~lib/string/String
|
|
206
245
|
return __liftString(exports.domainUsage() >>> 0);
|
|
207
246
|
},
|
|
208
|
-
domainWantsCompact() {
|
|
209
|
-
// assembly/compile/domainWantsCompact() => bool
|
|
210
|
-
|
|
247
|
+
domainWantsCompact(want) {
|
|
248
|
+
// assembly/compile/domainWantsCompact(i32?) => bool
|
|
249
|
+
exports.__setArgumentsLength(arguments.length);
|
|
250
|
+
return exports.domainWantsCompact(want) != 0;
|
|
211
251
|
},
|
|
212
252
|
outputLength() {
|
|
213
253
|
// assembly/output/outputLength() => u32
|
package/dist/codegen.wasm
CHANGED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
* so both produce identical output. See docs/architecture/overview.md.
|
|
8
8
|
*/
|
|
9
9
|
import { AIR_API_VERSION, API_VERSION } from "@swf2es/format";
|
|
10
|
+
import { type KeyContext } from "./keys.js";
|
|
11
|
+
export { KeyChains, type KeyContext, type KeyLog } from "./keys.js";
|
|
12
|
+
export { hex, sha256Here } from "./sha256.js";
|
|
10
13
|
/** Bumped whenever generated code or the runtime ABI it calls changes. */
|
|
11
14
|
export declare const COMPILER_VERSION = "0.0.0";
|
|
12
15
|
export { AIR_API_VERSION, API_VERSION };
|
|
@@ -34,9 +37,11 @@ export declare function libraryLog(codegen: Codegen, index: number, count: numbe
|
|
|
34
37
|
* SWFs of several versions share the libraries' modules), every ABC its
|
|
35
38
|
* domain sees, by hash and whether it is a library, those added after it
|
|
36
39
|
* included, its own place among them, and the compiler's log about them
|
|
37
|
-
* (see Codegen.context), the libraries' part by its digest once taken
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
+
* (see Codegen.context), the libraries' part by its digest once taken and
|
|
41
|
+
* the rest by the chained digests of its blocks of entries but the last
|
|
42
|
+
* few (see Codegen.keyContext). The player's module cache and the swf2es
|
|
43
|
+
* command both key by it, so that the command's modules are the cache's.
|
|
44
|
+
* Null where there is no context.
|
|
40
45
|
*/
|
|
41
46
|
export declare function moduleKey(codegen: Codegen, index: number, abcs: AddedAbcs, libraries: LibraryDigest | null): string | null;
|
|
42
47
|
/**
|
|
@@ -189,22 +194,29 @@ export interface Codegen {
|
|
|
189
194
|
/**
|
|
190
195
|
* Rebuild the domain without the ABCs of dropped and evicted domains, if
|
|
191
196
|
* memory would otherwise grow and they hold enough to keep it from
|
|
192
|
-
* growing
|
|
193
|
-
*
|
|
194
|
-
*
|
|
197
|
+
* growing, or memory is far above what the live ones need: whether it
|
|
198
|
+
* did. Done in a new instance of the compiler, made ahead, which takes
|
|
199
|
+
* the old one's place, so that its memory goes with it, where that takes
|
|
200
|
+
* less memory or a rebuild in place would not fit; else in place, only
|
|
201
|
+
* where the new tables fit beside the old. A rebuild links every live
|
|
202
|
+
* ABC again and verifies them again, seconds for a large application, so
|
|
203
|
+
* a host calls this when it has time, as when idle; nothing else does.
|
|
195
204
|
*/
|
|
196
205
|
compact(): boolean;
|
|
197
206
|
/**
|
|
198
207
|
* What the ABCs hold of codegen's memory, roughly, in bytes: the live
|
|
199
208
|
* ones', and the dropped and evicted domains' that compact would free;
|
|
200
|
-
*
|
|
209
|
+
* the size of codegen's memory, which grows and never shrinks but when
|
|
210
|
+
* compact moves the domain to a new instance; and how many such moves
|
|
211
|
+
* failed, each leaving the domain as it was, rebuilt in place if at all.
|
|
201
212
|
*/
|
|
202
213
|
usage(): {
|
|
203
214
|
live: number;
|
|
204
215
|
dead: number;
|
|
205
216
|
memory: number;
|
|
217
|
+
failedMoves: number;
|
|
206
218
|
};
|
|
207
|
-
/** The size of codegen's memory in bytes,
|
|
219
|
+
/** The size of codegen's memory in bytes, as usage gives it: cheap, for a host that shows it often. */
|
|
208
220
|
memoryBytes(): number;
|
|
209
221
|
/**
|
|
210
222
|
* Evict application domain `appDomain` and its descendants while the host
|
|
@@ -249,6 +261,17 @@ export interface Codegen {
|
|
|
249
261
|
* for an ABC never added.
|
|
250
262
|
*/
|
|
251
263
|
context(index?: number, after?: number, upTo?: number): ModuleContext | null;
|
|
264
|
+
/**
|
|
265
|
+
* ABC `index`'s context as a module key names it, the log's entries
|
|
266
|
+
* made with `after` ABCs added or fewer left out: the log by the chained
|
|
267
|
+
* digests of its blocks of entries, those made before the last ABC was
|
|
268
|
+
* added, and the text of the entries after them. Each application
|
|
269
|
+
* domain keeps its last digest, so a key reads and digests only the
|
|
270
|
+
* entries made since the last, or since its parent's. The same domain
|
|
271
|
+
* gives the same however its keys were taken. Null for an ABC never
|
|
272
|
+
* added, or of a domain not live.
|
|
273
|
+
*/
|
|
274
|
+
keyContext(index?: number, after?: number): KeyContext | null;
|
|
252
275
|
/**
|
|
253
276
|
* A string that changes whenever a context might: a host that took one
|
|
254
277
|
* and finds this the same since need not take it again.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAoC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,eAAe,EAAE,WAAW,EAAoC,MAAM,gBAAgB,CAAC;AAEhG,OAAO,EAAa,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,0EAA0E;AAC1E,eAAO,MAAM,gBAAgB,UAAU,CAAC;AAMxC,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,CAAC;AAExC,8GAA8G;AAC9G,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,SAAS,OA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MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAqehF"}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { AIR_API_VERSION, API_VERSION, checkApiVersion, isAirApiVersion } from "@swf2es/format";
|
|
10
10
|
import { instantiate } from "./codegen.js";
|
|
11
|
+
import { KeyChains } from "./keys.js";
|
|
12
|
+
export { KeyChains } from "./keys.js";
|
|
13
|
+
export { hex, sha256Here } from "./sha256.js";
|
|
11
14
|
/** Bumped whenever generated code or the runtime ABI it calls changes. */
|
|
12
15
|
export const COMPILER_VERSION = "0.0.0";
|
|
13
16
|
// The API versions the player and the swf2es command reset the compiler
|
|
@@ -27,12 +30,14 @@ export function libraryLog(codegen, index, count) {
|
|
|
27
30
|
* SWFs of several versions share the libraries' modules), every ABC its
|
|
28
31
|
* domain sees, by hash and whether it is a library, those added after it
|
|
29
32
|
* included, its own place among them, and the compiler's log about them
|
|
30
|
-
* (see Codegen.context), the libraries' part by its digest once taken
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
+
* (see Codegen.context), the libraries' part by its digest once taken and
|
|
34
|
+
* the rest by the chained digests of its blocks of entries but the last
|
|
35
|
+
* few (see Codegen.keyContext). The player's module cache and the swf2es
|
|
36
|
+
* command both key by it, so that the command's modules are the cache's.
|
|
37
|
+
* Null where there is no context.
|
|
33
38
|
*/
|
|
34
39
|
export function moduleKey(codegen, index, abcs, libraries) {
|
|
35
|
-
const context = codegen.
|
|
40
|
+
const context = codegen.keyContext(index, libraries?.count ?? 0);
|
|
36
41
|
if (!context) {
|
|
37
42
|
return null;
|
|
38
43
|
}
|
|
@@ -44,7 +49,8 @@ export function moduleKey(codegen, index, abcs, libraries) {
|
|
|
44
49
|
abcs: context.abcs.map((i) => `${abcs.builtins[i] ? "builtin " : ""}${abcs.hashes[i]}`),
|
|
45
50
|
own: context.own,
|
|
46
51
|
libraries,
|
|
47
|
-
|
|
52
|
+
blocks: context.blocks,
|
|
53
|
+
log: context.rest,
|
|
48
54
|
});
|
|
49
55
|
}
|
|
50
56
|
/**
|
|
@@ -63,7 +69,7 @@ export function actionsKey(codegen, hash, version) {
|
|
|
63
69
|
* this package free of I/O. The file ships as `@swf2es/codegen/codegen.wasm`.
|
|
64
70
|
*/
|
|
65
71
|
export async function createCodegen(module) {
|
|
66
|
-
|
|
72
|
+
let wasm = await instantiate(module, { env: {} });
|
|
67
73
|
const version = wasm.compilerVersion();
|
|
68
74
|
if (version !== COMPILER_VERSION) {
|
|
69
75
|
throw new Error(`codegen.wasm is version ${version} but the wrapper expects ${COMPILER_VERSION}`);
|
|
@@ -74,9 +80,12 @@ export async function createCodegen(module) {
|
|
|
74
80
|
if (!WebAssembly.Module.exports(module).some((e) => e.name === "outputLength")) {
|
|
75
81
|
throw new Error("codegen.wasm has no outputLength export, which the wrapper expects: it is older than the wrapper");
|
|
76
82
|
}
|
|
77
|
-
// Or before it wrote a module a part at a time
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
// Or before it wrote a module a part at a time, or rebuilt its domain a
|
|
84
|
+
// part at a time and in another instance.
|
|
85
|
+
for (const name of ["domainModuleMoreBytes", "domainRebuildStep", "domainSaveBytes"]) {
|
|
86
|
+
if (!WebAssembly.Module.exports(module).some((e) => e.name === name)) {
|
|
87
|
+
throw new Error(`codegen.wasm has no ${name} export, which the wrapper expects: it is older than the wrapper`);
|
|
88
|
+
}
|
|
80
89
|
}
|
|
81
90
|
// codegen.wasm uses AssemblyScript's minimal runtime, which collects
|
|
82
91
|
// garbage only when asked. Nothing runs in wasm between calls, so that is
|
|
@@ -186,6 +195,110 @@ export async function createCodegen(module) {
|
|
|
186
195
|
const identity = stamps.length ? String.fromCharCode(...new Uint8Array(stamps[0])) : null;
|
|
187
196
|
let epoch = 0;
|
|
188
197
|
let apiVersion = API_VERSION;
|
|
198
|
+
// Read where they are in codegen's memory, digested before the next call in.
|
|
199
|
+
const chains = new KeyChains({
|
|
200
|
+
header(index) {
|
|
201
|
+
const address = wasm.domainKeyHeaderBytes(index);
|
|
202
|
+
return address === 0 ? "" : handed(address, wasm.outputLength());
|
|
203
|
+
},
|
|
204
|
+
parent: (appDomain) => wasm.domainParent(appDomain),
|
|
205
|
+
fork: (appDomain) => wasm.domainKeyFork(appDomain),
|
|
206
|
+
log(appDomain, after, from, to, block, filled) {
|
|
207
|
+
const address = wasm.domainKeyLogBytes(appDomain, after, from, to, block, filled);
|
|
208
|
+
return address === 0
|
|
209
|
+
? null
|
|
210
|
+
: new Uint8Array(wasm.memory.buffer, address, wasm.outputLength());
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
// The rebuild domainCompact, domainRevive or domainLoadRebuild started in
|
|
214
|
+
// `into`, a part a call, each part's garbage collected before the next
|
|
215
|
+
// (see domainRebuildStep), and the old tables once it is done, before the
|
|
216
|
+
// next call's allocations would grow memory past them: whether it was done.
|
|
217
|
+
const rebuild = (into = wasm) => {
|
|
218
|
+
let step = into.domainRebuildStep();
|
|
219
|
+
while (step === 0) {
|
|
220
|
+
into.__collect();
|
|
221
|
+
step = into.domainRebuildStep();
|
|
222
|
+
}
|
|
223
|
+
into.__collect();
|
|
224
|
+
size = wasm.memory.buffer.byteLength;
|
|
225
|
+
calls = 0;
|
|
226
|
+
return step > 0;
|
|
227
|
+
};
|
|
228
|
+
// A second instance of the compiler, made ahead as instantiating is
|
|
229
|
+
// asynchronous, that the next rebuild is done in (see moved): wasm memory
|
|
230
|
+
// never shrinks, so one done in place keeps, for good, as much as the
|
|
231
|
+
// dead tables and the old and the new took together. Made only once a
|
|
232
|
+
// move will be due before long (WANT_Spare), not for every compiler, and
|
|
233
|
+
// taken by the move; and how many moves failed, which usage tells.
|
|
234
|
+
let spare = null;
|
|
235
|
+
let making = false;
|
|
236
|
+
let failedMoves = 0;
|
|
237
|
+
const prepare = () => {
|
|
238
|
+
if (spare === null && !making) {
|
|
239
|
+
making = true;
|
|
240
|
+
instantiate(module, { env: {} }).then((made) => {
|
|
241
|
+
spare = made;
|
|
242
|
+
making = false;
|
|
243
|
+
}, () => {
|
|
244
|
+
making = false;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
// The domain rebuilt in `into`, a new instance, from what this one saves
|
|
249
|
+
// of it and its live ABCs' bytes, read where they are: whether it was. The
|
|
250
|
+
// ABCs' copies in it are its garbage once parsed, collected every few
|
|
251
|
+
// megabytes.
|
|
252
|
+
const rebuiltIn = (into) => {
|
|
253
|
+
const saved = wasm.domainSaveBytes();
|
|
254
|
+
if (!into.domainLoad(new Uint8Array(wasm.memory.buffer, saved, wasm.outputLength()))) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
into.__collect();
|
|
258
|
+
let copied = 0;
|
|
259
|
+
for (let i = 0; i < added; i++) {
|
|
260
|
+
const at = wasm.domainSavedAbcBytes(i);
|
|
261
|
+
const length = wasm.outputLength();
|
|
262
|
+
if (at !== 0 && into.domainLoadAbc(i, new Uint8Array(wasm.memory.buffer, at, length)) !== 0) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
copied += length;
|
|
266
|
+
if (copied >= COPIED_BETWEEN_COLLECTIONS) {
|
|
267
|
+
into.__collect();
|
|
268
|
+
copied = 0;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return into.domainLoadRebuild() && rebuild(into);
|
|
272
|
+
};
|
|
273
|
+
// The domain rebuilt in the spare instance, which then takes this one's
|
|
274
|
+
// place, whose memory goes with it: whether it was. One that failed, or
|
|
275
|
+
// trapped as its memory could not grow, is let go of, the domain left
|
|
276
|
+
// here as it was, and another made.
|
|
277
|
+
const moved = () => {
|
|
278
|
+
const into = spare;
|
|
279
|
+
if (into === null) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
spare = null;
|
|
283
|
+
let done = false;
|
|
284
|
+
try {
|
|
285
|
+
done = rebuiltIn(into);
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
done = false;
|
|
289
|
+
}
|
|
290
|
+
if (!done) {
|
|
291
|
+
failedMoves++;
|
|
292
|
+
size = wasm.memory.buffer.byteLength;
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
// The held SWFs' copies were the old instance's (see hold).
|
|
296
|
+
holds.length = 0;
|
|
297
|
+
wasm = into;
|
|
298
|
+
size = wasm.memory.buffer.byteLength;
|
|
299
|
+
calls = 0;
|
|
300
|
+
return true;
|
|
301
|
+
};
|
|
189
302
|
const collected = (result, reclaim = false) => {
|
|
190
303
|
const grown = wasm.memory.buffer.byteLength;
|
|
191
304
|
if (reclaim || grown > size || ++calls >= COLLECT_EVERY) {
|
|
@@ -208,6 +321,7 @@ export async function createCodegen(module) {
|
|
|
208
321
|
checkApiVersion(version);
|
|
209
322
|
added = 0;
|
|
210
323
|
epoch++;
|
|
324
|
+
chains.clear();
|
|
211
325
|
apiVersion = version;
|
|
212
326
|
collected(wasm.domainReset(version));
|
|
213
327
|
},
|
|
@@ -234,6 +348,7 @@ export async function createCodegen(module) {
|
|
|
234
348
|
dropDomain(appDomain, of = epoch) {
|
|
235
349
|
if (of === epoch) {
|
|
236
350
|
collected(wasm.domainDrop(appDomain));
|
|
351
|
+
chains.forget((d) => wasm.domainState(d) === 2);
|
|
237
352
|
}
|
|
238
353
|
},
|
|
239
354
|
evictDomain(appDomain) {
|
|
@@ -241,34 +356,42 @@ export async function createCodegen(module) {
|
|
|
241
356
|
},
|
|
242
357
|
usage() {
|
|
243
358
|
const [live, dead, memory] = collected(wasm.domainUsage()).split(" ").map(Number);
|
|
244
|
-
return { live, dead, memory };
|
|
359
|
+
return { live, dead, memory, failedMoves };
|
|
245
360
|
},
|
|
246
361
|
memoryBytes() {
|
|
247
362
|
return wasm.memory.buffer.byteLength;
|
|
248
363
|
},
|
|
249
364
|
compact() {
|
|
250
|
-
//
|
|
251
|
-
//
|
|
252
|
-
//
|
|
253
|
-
|
|
254
|
-
|
|
365
|
+
// Done in the spare instance, once there is one and that would take
|
|
366
|
+
// less memory, or in place would not fit; else in place, where the
|
|
367
|
+
// new tables are made while the old are live, only where they fit
|
|
368
|
+
// and, beside a spare made or being made, a move would not do better:
|
|
369
|
+
// what earlier calls left is collected first, and the old tables once
|
|
370
|
+
// it is done, before the next call's allocations would grow memory
|
|
371
|
+
// past them.
|
|
372
|
+
if (spare === null && !making && collected(wasm.domainWantsCompact(WANT_Spare))) {
|
|
373
|
+
prepare();
|
|
255
374
|
}
|
|
256
|
-
wasm.
|
|
257
|
-
|
|
258
|
-
|
|
375
|
+
if (spare !== null && collected(wasm.domainWantsCompact(WANT_Move))) {
|
|
376
|
+
wasm.__collect();
|
|
377
|
+
if (moved()) {
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const beside = spare !== null || making;
|
|
382
|
+
if (!collected(wasm.domainWantsCompact(beside ? WANT_InPlaceBesideSpare : WANT_InPlace))) {
|
|
259
383
|
return false;
|
|
260
384
|
}
|
|
261
385
|
wasm.__collect();
|
|
262
|
-
size = wasm.memory.buffer.byteLength;
|
|
263
386
|
calls = 0;
|
|
264
|
-
return true;
|
|
387
|
+
return wasm.domainCompact(true) && rebuild();
|
|
265
388
|
},
|
|
266
389
|
isLive(appDomain) {
|
|
267
390
|
return collected(wasm.domainState(appDomain)) === 0;
|
|
268
391
|
},
|
|
269
392
|
reviveDomain(appDomain, abcs) {
|
|
270
393
|
// Its ABCs' bytes are copied into the compiler only if a rebuild let go of them.
|
|
271
|
-
let revived = collected(wasm.domainRevive(appDomain));
|
|
394
|
+
let revived = collected(wasm.domainRevive(appDomain, true));
|
|
272
395
|
if (revived < 0) {
|
|
273
396
|
for (const [index, bytes] of abcs) {
|
|
274
397
|
const error = collected(wasm.domainRestore(index, bytes));
|
|
@@ -276,16 +399,12 @@ export async function createCodegen(module) {
|
|
|
276
399
|
throw new Error(`ABC ${index}: not of an evicted domain, or rejected (${error})`);
|
|
277
400
|
}
|
|
278
401
|
}
|
|
279
|
-
revived = collected(wasm.domainRevive(appDomain));
|
|
402
|
+
revived = collected(wasm.domainRevive(appDomain, true));
|
|
280
403
|
}
|
|
281
|
-
|
|
404
|
+
// Revived by a rebuild in place, mid-load: a compaction moves it later.
|
|
405
|
+
if (revived < 0 || (revived > 0 && !rebuild())) {
|
|
282
406
|
throw new Error(`application domain ${appDomain}: not evicted, its parent not live, or an ABC of it not given`);
|
|
283
407
|
}
|
|
284
|
-
if (revived > 0) {
|
|
285
|
-
wasm.__collect();
|
|
286
|
-
size = wasm.memory.buffer.byteLength;
|
|
287
|
-
calls = 0;
|
|
288
|
-
}
|
|
289
408
|
},
|
|
290
409
|
found(d) {
|
|
291
410
|
collected(wasm.domainFound(d.domain, d.nsKind, d.uri, d.name, d.abc, d.asType));
|
|
@@ -320,6 +439,12 @@ export async function createCodegen(module) {
|
|
|
320
439
|
log: second < 0 ? "" : text.slice(second + 1),
|
|
321
440
|
};
|
|
322
441
|
},
|
|
442
|
+
keyContext(index = -1, after = 0) {
|
|
443
|
+
if (added === 0) {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
return collected(chains.context(indexOf(index), after));
|
|
447
|
+
},
|
|
323
448
|
revision() {
|
|
324
449
|
return `${epoch} ${wasm.domainRevision()}`;
|
|
325
450
|
},
|
|
@@ -397,6 +522,13 @@ function parseEntries(text) {
|
|
|
397
522
|
return entries;
|
|
398
523
|
}
|
|
399
524
|
const COLLECT_EVERY = 64;
|
|
525
|
+
/** What domainWantsCompact is asked (see wantsRebuild in assembly/avm2/link/lifetime.ts). */
|
|
526
|
+
const WANT_InPlace = 0;
|
|
527
|
+
const WANT_InPlaceBesideSpare = 1;
|
|
528
|
+
const WANT_Move = 2;
|
|
529
|
+
const WANT_Spare = 3;
|
|
530
|
+
/** How many bytes of ABCs a rebuild in the spare instance copies in between its collections. */
|
|
531
|
+
const COPIED_BETWEEN_COLLECTIONS = 4 << 20;
|
|
400
532
|
/** How many SWFs whose blocks or units are compiled codegen holds a copy of at most. */
|
|
401
533
|
const HELD_SWFS = 4;
|
|
402
534
|
const utf8 = new TextDecoder();
|