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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
deps/build.log
docs/build/
test/results.md
Manifest.toml
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Documenter, JuliaInterpreter, Test, CodeTracking
DocMeta.setdocmeta!(JuliaInterpreter, :DocTestSetup, :(
begin
using JuliaInterpreter
empty!(JuliaInterpreter.junk)
JuliaInterpreter.clear_caches()
JuliaInterpreter.remove()
end); recursive=true)

Expand Down
2 changes: 1 addition & 1 deletion docs/src/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Sometimes you might have a whole sequence of expressions you want to run.
In such cases, your first thought should be `prepare_thunk`.
Here's a demonstration:

```jldoctest; setup=(using JuliaInterpreter; empty!(JuliaInterpreter.junk))
```jldoctest; setup=(using JuliaInterpreter; JuliaInterpreter.clear_caches())
using Test

ex = quote
Expand Down
23 changes: 15 additions & 8 deletions src/construct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ rather than recursed into via the interpreter.
"""
const compiled_modules = Set{Module}()

const junk = FrameData[] # to allow re-use of allocated memory (this is otherwise a bottleneck)
const debug_recycle = Base.RefValue(false)
@noinline _check_frame_not_in_junk(frame) = @assert frame.framedata ∉ junk
const junk_framedata = FrameData[] # to allow re-use of allocated memory (this is otherwise a bottleneck)
const junk_frames = Frame[]
debug_recycle() = false
@noinline function _check_frame_not_in_junk(frame)
@assert frame.framedata ∉ junk_framedata
@assert frame ∉ junk_frames
end

@inline function recycle(frame)
debug_recycle[] && _check_frame_not_in_junk(frame)
push!(junk, frame.framedata)
debug_recycle() && _check_frame_not_in_junk(frame)
push!(junk_framedata, frame.framedata)
push!(junk_frames, frame)
end

function return_from(frame::Frame)
Expand All @@ -42,9 +48,10 @@ function return_from(frame::Frame)
end

function clear_caches()
empty!(junk)
empty!(junk_framedata)
empty!(framedict)
empty!(genframedict)
empty!(junk_frames)
for bp in breakpoints()
empty!(bp.instances)
end
Expand Down Expand Up @@ -269,8 +276,8 @@ function prepare_framedata(framecode, argvals::Vector{Any}, lenv::SimpleVector=e
slotnames = src.slotnames::SlotNamesType
ssavt = src.ssavaluetypes
ng, ns = isa(ssavt, Int) ? ssavt : length(ssavt::Vector{Any}), length(src.slotflags)
if length(junk) > 0
olddata = pop!(junk)
if length(junk_framedata) > 0
olddata = pop!(junk_framedata)
locals, ssavalues, sparams = olddata.locals, olddata.ssavalues, olddata.sparams
exception_frames, last_reference = olddata.exception_frames, olddata.last_reference
last_exception = olddata.last_exception
Expand Down
15 changes: 14 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,20 @@ mutable struct Frame
caller::Union{Frame,Nothing}
callee::Union{Frame,Nothing}
end
Frame(framecode, framedata, pc=1, caller=nothing) = Frame(framecode, framedata, pc, 1, caller, nothing)
function Frame(framecode, framedata, pc=1, caller=nothing)
if length(junk_frames) > 0
frame = pop!(junk_frames)
frame.framecode = framecode
frame.framedata = framedata
frame.pc = pc
frame.assignment_counter = 1
frame.caller = caller
frame.callee = nothing
return frame
else
return Frame(framecode, framedata, pc, 1, caller, nothing)
end
end

caller(frame) = frame.caller
callee(frame) = frame.callee
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if !isdefined(@__MODULE__, :read_and_parse)
include("utils.jl")
end

JuliaInterpreter.debug_recycle[] = true
Core.eval(JuliaInterpreter, :(debug_recycle() = true))

@testset "Main tests" begin
include("interpret.jl")
Expand Down