Skip to content

Commit

Permalink
preallocate StackTrace field Frames
Browse files Browse the repository at this point in the history
  • Loading branch information
zdyj3170101136 committed Aug 1, 2023
1 parent a0d5347 commit a1b27a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 12 additions & 0 deletions parser/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,20 @@ func (c *CheckpointEvent) Parse(r reader.Reader, classes ClassMap, cpools PoolMa
results[i] = &threads[i]
}
case "jdk.types.StackTrace":
var pointerToStackFrames []*StackFrame
indexPointerToStackFrames := 0
getPointerToStackFrames := func(n int) []*StackFrame {
if indexPointerToStackFrames+n > len(pointerToStackFrames) {
pointerToStackFrames = make([]*StackFrame, m)
indexPointerToStackFrames = 0
}
result := pointerToStackFrames[indexPointerToStackFrames : indexPointerToStackFrames+n]
indexPointerToStackFrames += n
return result[:0]
}
stackTraces := make([]StackTrace, m)
for i := range stackTraces {
stackTraces[i].getPointerToStackFrames = getPointerToStackFrames
stackTraces[i].constants = contantsSlice[i]
results[i] = &stackTraces[i]
}
Expand Down
11 changes: 6 additions & 5 deletions parser/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,10 +866,11 @@ func toStackFrame(p ParseResolvable) (*StackFrame, error) {
}

type StackTrace struct {
Truncated bool
Frames []*StackFrame
constants []constant
resolved bool
Truncated bool
Frames []*StackFrame
constants []constant
resolved bool
getPointerToStackFrames func(int) []*StackFrame
}

func (st *StackTrace) parseField(r reader.Reader, name string, p ParseResolvable) (err error) {
Expand All @@ -888,7 +889,7 @@ func (st *StackTrace) parseField(r reader.Reader, name string, p ParseResolvable
if err != nil {
return err
}
st.Frames = make([]*StackFrame, 0, frameLen)
st.Frames = st.getPointerToStackFrames(int(frameLen))
}
return err
}
Expand Down

0 comments on commit a1b27a8

Please sign in to comment.