Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ export class JClass {
}
return t.name === "java/lang/Object" || t.name === "java/lang/Cloneable" || t.name === "java/io/Serializable";
}
// Object, the one class without a superclass, as for stores into Object[]
if (t.superclass === null && !t.isInterface) return true;
return this.allSupers().has(t);
}

Expand Down
17 changes: 12 additions & 5 deletions src/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,18 @@ export class NativeFrame {

export type AnyFrame = Frame | NativeFrame;

// JavaThrow and PendingThrow are control flow: V8 would capture a JS stack
// trace for each, which costs more than the throw and is never read.
const limitTraces = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit")?.writable === true;

// A Java exception in flight through JS code.
export class JavaThrow extends Error {
readonly obj: JObject;
constructor(obj: JObject) {
const limit = Error.stackTraceLimit;
if (limitTraces) Error.stackTraceLimit = 0;
super("java exception");
if (limitTraces) Error.stackTraceLimit = limit;
this.obj = obj;
}
}
Expand All @@ -113,7 +120,10 @@ export class PendingThrow extends Error {
// the native method that threw it, which its stack trace starts with
native?: JMethod;
constructor(cls: string, msg: string | null = null, ctor?: { desc: string; args: any[] }) {
const limit = Error.stackTraceLimit;
if (limitTraces) Error.stackTraceLimit = 0;
super(`${cls}: ${msg}`);
if (limitTraces) Error.stackTraceLimit = limit;
this.cls = cls;
this.msg = msg;
this.ctor = ctor;
Expand Down Expand Up @@ -203,22 +213,19 @@ export class JThread {
// filled without holes, which would make V8 store it as a dictionary
while (this.pool.length <= d) this.pool.push(this.pooled(m, this.pool.length));
const f = this.pool[d] ?? (this.pool[d] = this.pooled(m, d));
// a pooled frame has nothing spilled, no monitor still to take and stays direct; a frame that changes those leaves the pool
f.m = m;
f.code = m.code!.code;
f.pc = 0;
f.sp = 0;
f.locals = null as any;
f.stack = null as any;
f.lock = lock;
f.needLock = false;
f.direct = true;
this.frames.push(f);
return f;
}

private pooled(m: JMethod, slot: number): Frame {
const f = new Frame(m, true);
f.poolSlot = slot;
f.direct = true;
return f;
}

Expand Down