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

jb/retained heap analysis #89

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions compiler/codegen.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public defn compile-entry-function (emitter:CodeEmitter, stubs:AsmStubs) :
#label(safepoint-table) ;safepoint-table:ptr<?>
#label(debug-table) ;debug-table:ptr<?>
#label(local-var-table) ;local-var-table:ptr<?>
#long() ;heap-dominator-tree:ptr<?>
#label(class-table) ;class-table:ptr<?>
#label(global-root-table) ;global-root-table:ptr<GlobalRoots>
#label(stackmap-table) ;stackmap-table:ptr<?>
Expand Down
1 change: 1 addition & 0 deletions compiler/vm-structures.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public lostanza deftype VMState :
var safepoint-table: ptr<?> ;(Permanent State)
var debug-table: ptr<?> ;(Permanent State)
var local-var-table: ptr<?> ;(Permanent State)
var heap-dominator-tree: ptr<?> ;(Variable State)
var class-table: ptr<?> ;(Permanent State)
;Interpreted Mode Tables
var instructions: ptr<byte> ;(Permanent State)
Expand Down
113 changes: 83 additions & 30 deletions core/core.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -214,31 +214,83 @@ protected lostanza deftype ArrayRecord :
;are used only in compiled mode.
;Permanent state changes in-between each code load.
;Variable state changes in-between each boundary change.
protected lostanza deftype VMState :
;Compiled and Interpreted Mode
global-offsets: ptr<long> ;(Permanent State)
global-mem: ptr<byte> ;(Permanent State)
var sig-handler: long ;(Permanent State)
var current-coroutine-ptr: ptr<long> ;[TODO] Change to long to represent reference.
var stepping-coroutine-ptr: ptr<long> ;[TODO] Change to long to represent reference.
const-table: ptr<long> ;(Permanent State)
const-mem: ptr<byte> ;(Permanent State)
data-offsets: ptr<int> ;(Permanent State)
data-mem: ptr<byte> ;(Permanent State)
code-offsets: ptr<int> ;(Permanent State)
registers: ptr<long> ;(Permanent State)
system-registers: ptr<long> ;(Permanent State)
var heap: Heap ;(Variable State)
safepoint-table: ptr<?> ;(Variable State)
debug-table: ptr<?> ;(Variable State)
local-var-table: ptr<?> ;(Variable State)
;Compiled Mode Tables
class-table: ptr<ClassDescriptor>
global-root-table: ptr<GlobalRoots>
stackmap-table: ptr<ptr<StackMap>>
stack-trace-table: ptr<StackTraceTable>
extern-table: ptr<ExternTable>
extern-defn-table: ptr<ExternDefnTable>
#if-defined(BOOTSTRAP) :

protected lostanza deftype VMState :
;Compiled and Interpreted Mode
global-offsets: ptr<long> ;(Permanent State)
global-mem: ptr<byte> ;(Permanent State)
var sig-handler: long ;(Permanent State)
var current-coroutine-ptr: ptr<long> ;[TODO] Change to long to represent reference.
var stepping-coroutine-ptr: ptr<long> ;[TODO] Change to long to represent reference.
const-table: ptr<long> ;(Permanent State)
const-mem: ptr<byte> ;(Permanent State)
data-offsets: ptr<int> ;(Permanent State)
data-mem: ptr<byte> ;(Permanent State)
code-offsets: ptr<int> ;(Permanent State)
registers: ptr<long> ;(Permanent State)
system-registers: ptr<long> ;(Permanent State)
var heap: Heap ;(Variable State)
safepoint-table: ptr<?> ;(Variable State)
debug-table: ptr<?> ;(Variable State)
local-var-table: ptr<?> ;(Variable State)
;Compiled Mode Tables
class-table: ptr<ClassDescriptor>
global-root-table: ptr<GlobalRoots>
stackmap-table: ptr<ptr<StackMap>>
stack-trace-table: ptr<StackTraceTable>
extern-table: ptr<ExternTable>
extern-defn-table: ptr<ExternDefnTable>

lostanza defn initialize-dominator-tree () -> ref<False> :
return false

#else:

protected lostanza deftype HeapDominator :
var roots : ptr<LSLongVector>
var sizes : ptr<LSLongVector>
var addrs : ptr<LSLongVector>
var offs : ptr<LSLongVector>
var heap : ptr<LSLongVector>

protected lostanza deftype VMState :
;Compiled and Interpreted Mode
global-offsets: ptr<long> ;(Permanent State)
global-mem: ptr<byte> ;(Permanent State)
var sig-handler: long ;(Permanent State)
var current-coroutine-ptr: ptr<long> ;[TODO] Change to long to represent reference.
var stepping-coroutine-ptr: ptr<long> ;[TODO] Change to long to represent reference.
const-table: ptr<long> ;(Permanent State)
const-mem: ptr<byte> ;(Permanent State)
data-offsets: ptr<int> ;(Permanent State)
data-mem: ptr<byte> ;(Permanent State)
code-offsets: ptr<int> ;(Permanent State)
registers: ptr<long> ;(Permanent State)
system-registers: ptr<long> ;(Permanent State)
var heap: Heap ;(Variable State)
safepoint-table: ptr<?> ;(Variable State)
debug-table: ptr<?> ;(Variable State)
local-var-table: ptr<?> ;(Variable State)
var dom: ptr<HeapDominator> ;(Variable State)
;Compiled Mode Tables
class-table: ptr<ClassDescriptor>
global-root-table: ptr<GlobalRoots>
stackmap-table: ptr<ptr<StackMap>>
stack-trace-table: ptr<StackTraceTable>
extern-table: ptr<ExternTable>
extern-defn-table: ptr<ExternDefnTable>

lostanza defn initialize-dominator-tree () -> ref<False> :
val vms:ptr<core/VMState> = call-prim flush-vm()
val dom = (call-c clib/malloc(sizeof(HeapDominator))) as ptr<HeapDominator>
dom.roots = LSLongVector()
dom.sizes = LSLongVector()
dom.addrs = LSLongVector()
dom.offs = LSLongVector()
dom.heap = LSLongVector()
vms.dom = dom
return false

lostanza deftype ExternTable :
length: long
Expand Down Expand Up @@ -1614,9 +1666,9 @@ lostanza defn iterate-roots (f:ptr<((ptr<long>, ptr<VMState>) -> ref<False>)>,
return [vms.heap.iterate-roots](f, vms)

;Call f on all references stored in the object pointed to by p.
lostanza defn iterate-references (p:ptr<long>,
f:ptr<((ptr<long>, ptr<VMState>) -> ref<False>)>,
vms:ptr<VMState>) -> ref<False> :
protected lostanza defn iterate-references (p:ptr<long>,
f:ptr<((ptr<long>, ptr<VMState>) -> ref<False>)>,
vms:ptr<VMState>) -> ref<False> :
;Retrieve the object's tag.
val tag = get-tag(p)
;Fast path using fast descriptor table.
Expand Down Expand Up @@ -2632,8 +2684,8 @@ public lostanza defn clear (start:ptr<?>, size:long) -> ptr<?> :
return call-c clib/memset(start, 0, size)

;Call f on all root pointers.
lostanza defn core-iterate-roots (f:ptr<((ptr<long>, ptr<VMState>) -> ref<False>)>,
vms:ptr<VMState>) -> ref<False> :
protected lostanza defn core-iterate-roots (f:ptr<((ptr<long>, ptr<VMState>) -> ref<False>)>,
vms:ptr<VMState>) -> ref<False> :
;Scan globals
val globals = vms.global-mem as ptr<long>
val roots = vms.global-root-table
Expand Down Expand Up @@ -4203,6 +4255,7 @@ initialize-gc-notifiers()
initialize-gc-statistics()
initialize-liveness-handlers()
initialize-symbol-table()
initialize-dominator-tree()

;================================================================================
;========================== End of Boot Sequence ================================
Expand Down
Loading