Update
This commit is contained in:
1 parent
3530afb854
commit
6903fcff27
2146 files changed
+112256
-190703
No files matched your search
+21
-8
@@ -384,7 +384,7 @@ func (s *addrSet) InsertWithoutMergingUnchecked(gap addrGapIterator, r addrRange
|
||||
if splitMaxGap {
|
||||
gap.node.updateMaxGapLeaf()
|
||||
}
|
||||
return addrIterator{gap.node, gap.index}
|
||||
return addrIterator(gap)
|
||||
}
|
||||
|
||||
// InsertRange inserts the given segment into the set. If the new segment can
|
||||
@@ -513,7 +513,7 @@ func (s *addrSet) Remove(seg addrIterator) addrGapIterator {
|
||||
if addrtrackGaps != 0 {
|
||||
seg.node.updateMaxGapLeaf()
|
||||
}
|
||||
return seg.node.rebalanceAfterRemove(addrGapIterator{seg.node, seg.index})
|
||||
return seg.node.rebalanceAfterRemove(addrGapIterator(seg))
|
||||
}
|
||||
|
||||
// RemoveAll removes all segments from the set. All existing iterators are
|
||||
@@ -598,6 +598,19 @@ func (s *addrSet) RemoveFullRangeWith(r addrRange, f func(seg addrIterator)) add
|
||||
}
|
||||
}
|
||||
|
||||
// MoveFrom moves all segments from s2 to s, replacing all existing segments in
|
||||
// s and leaving s2 empty.
|
||||
func (s *addrSet) MoveFrom(s2 *addrSet) {
|
||||
*s = *s2
|
||||
for _, child := range s.root.children {
|
||||
if child == nil {
|
||||
break
|
||||
}
|
||||
child.parent = &s.root
|
||||
}
|
||||
s2.RemoveAll()
|
||||
}
|
||||
|
||||
// Merge attempts to merge two neighboring segments. If successful, Merge
|
||||
// returns an iterator to the merged segment, and all existing iterators are
|
||||
// invalidated. Otherwise, Merge returns a terminal iterator.
|
||||
@@ -1609,7 +1622,7 @@ func (seg addrIterator) PrevGap() addrGapIterator {
|
||||
|
||||
return seg.node.children[seg.index].lastSegment().NextGap()
|
||||
}
|
||||
return addrGapIterator{seg.node, seg.index}
|
||||
return addrGapIterator(seg)
|
||||
}
|
||||
|
||||
// NextGap returns the gap immediately after the iterated segment.
|
||||
@@ -1901,26 +1914,26 @@ func (n *addrnode) String() string {
|
||||
func (n *addrnode) writeDebugString(buf *bytes.Buffer, prefix string) {
|
||||
if n.hasChildren != (n.nrSegments > 0 && n.children[0] != nil) {
|
||||
buf.WriteString(prefix)
|
||||
buf.WriteString(fmt.Sprintf("WARNING: inconsistent value of hasChildren: got %v, want %v\n", n.hasChildren, !n.hasChildren))
|
||||
fmt.Fprintf(buf, "WARNING: inconsistent value of hasChildren: got %v, want %v\n", n.hasChildren, !n.hasChildren)
|
||||
}
|
||||
for i := 0; i < n.nrSegments; i++ {
|
||||
if child := n.children[i]; child != nil {
|
||||
cprefix := fmt.Sprintf("%s- % 3d ", prefix, i)
|
||||
if child.parent != n || child.parentIndex != i {
|
||||
buf.WriteString(cprefix)
|
||||
buf.WriteString(fmt.Sprintf("WARNING: inconsistent linkage to parent: got (%p, %d), want (%p, %d)\n", child.parent, child.parentIndex, n, i))
|
||||
fmt.Fprintf(buf, "WARNING: inconsistent linkage to parent: got (%p, %d), want (%p, %d)\n", child.parent, child.parentIndex, n, i)
|
||||
}
|
||||
child.writeDebugString(buf, fmt.Sprintf("%s- % 3d ", prefix, i))
|
||||
}
|
||||
buf.WriteString(prefix)
|
||||
if n.hasChildren {
|
||||
if addrtrackGaps != 0 {
|
||||
buf.WriteString(fmt.Sprintf("- % 3d: %v => %v, maxGap: %d\n", i, n.keys[i], n.values[i], n.maxGap.Get()))
|
||||
fmt.Fprintf(buf, "- % 3d: %v => %v, maxGap: %d\n", i, n.keys[i], n.values[i], n.maxGap.Get())
|
||||
} else {
|
||||
buf.WriteString(fmt.Sprintf("- % 3d: %v => %v\n", i, n.keys[i], n.values[i]))
|
||||
fmt.Fprintf(buf, "- % 3d: %v => %v\n", i, n.keys[i], n.values[i])
|
||||
}
|
||||
} else {
|
||||
buf.WriteString(fmt.Sprintf("- % 3d: %v => %v\n", i, n.keys[i], n.values[i]))
|
||||
fmt.Fprintf(buf, "- % 3d: %v => %v\n", i, n.keys[i], n.values[i])
|
||||
}
|
||||
}
|
||||
if child := n.children[n.nrSegments]; child != nil {
|
||||
|
||||
+56
-49
@@ -32,7 +32,7 @@ type internalCallback interface {
|
||||
source() *objectDecodeState
|
||||
|
||||
// callbackRun executes the callback.
|
||||
callbackRun()
|
||||
callbackRun(ds *decodeState)
|
||||
}
|
||||
|
||||
// userCallback is an implementation of internalCallback.
|
||||
@@ -44,7 +44,7 @@ func (userCallback) source() *objectDecodeState {
|
||||
}
|
||||
|
||||
// callbackRun implements internalCallback.callbackRun.
|
||||
func (uc userCallback) callbackRun() {
|
||||
func (uc userCallback) callbackRun(*decodeState) {
|
||||
uc()
|
||||
}
|
||||
|
||||
@@ -84,7 +84,13 @@ type objectDecodeState struct {
|
||||
// callbacks is a set of callbacks to execute on load.
|
||||
callbacks []internalCallback
|
||||
|
||||
completeEntry
|
||||
pendingEntry odsListElem
|
||||
leafEntry odsListElem
|
||||
}
|
||||
|
||||
type odsListElem struct {
|
||||
ods *objectDecodeState
|
||||
odsEntry
|
||||
}
|
||||
|
||||
// addCallback adds a callback to the objectDecodeState.
|
||||
@@ -122,8 +128,13 @@ func (ods *objectDecodeState) source() *objectDecodeState {
|
||||
}
|
||||
|
||||
// callbackRun implements internalCallback.callbackRun.
|
||||
func (ods *objectDecodeState) callbackRun() {
|
||||
func (ods *objectDecodeState) callbackRun(ds *decodeState) {
|
||||
ods.blockedBy--
|
||||
if ods.blockedBy == 0 {
|
||||
ds.leaves.PushBack(&ods.leafEntry)
|
||||
} else if ods.blockedBy < 0 {
|
||||
Failf("object %d has negative blockedBy: %d", ods.id, ods.blockedBy)
|
||||
}
|
||||
}
|
||||
|
||||
// decodeState is a graph of objects in the process of being decoded.
|
||||
@@ -155,7 +166,11 @@ type decodeState struct {
|
||||
deferred map[objectID]wire.Object
|
||||
|
||||
// pending is the set of objects that are not yet complete.
|
||||
pending completeList
|
||||
pending odsList
|
||||
|
||||
// leaves is the set of objects that have no dependencies (blockedBy == 0).
|
||||
// leaves are consumed from the front and appended to the back.
|
||||
leaves odsList
|
||||
|
||||
// stats tracks time data.
|
||||
stats Stats
|
||||
@@ -185,20 +200,12 @@ func (ds *decodeState) checkComplete(ods *objectDecodeState) bool {
|
||||
|
||||
// Fire all callbacks.
|
||||
for _, ic := range ods.callbacks {
|
||||
ic.callbackRun()
|
||||
ic.callbackRun(ds)
|
||||
}
|
||||
|
||||
// Mark completed.
|
||||
cbs := ods.callbacks
|
||||
ods.callbacks = nil
|
||||
ds.pending.Remove(ods)
|
||||
|
||||
// Recursively check others.
|
||||
for _, ic := range cbs {
|
||||
if other := ic.source(); other != nil && other.blockedBy == 0 {
|
||||
ds.checkComplete(other)
|
||||
}
|
||||
}
|
||||
ds.pending.Remove(&ods.pendingEntry)
|
||||
|
||||
return true // All set.
|
||||
}
|
||||
@@ -223,6 +230,9 @@ func (ds *decodeState) wait(waiter *objectDecodeState, id objectID, callback fun
|
||||
|
||||
// Mark as blocked.
|
||||
waiter.blockedBy++
|
||||
if waiter.blockedBy == 1 {
|
||||
ds.leaves.Remove(&waiter.leafEntry)
|
||||
}
|
||||
|
||||
// No nil can be returned here.
|
||||
other := ds.lookup(id)
|
||||
@@ -280,6 +290,26 @@ func walkChild(path []wire.Dot, obj reflect.Value) reflect.Value {
|
||||
return obj
|
||||
}
|
||||
|
||||
func (ds *decodeState) growObjectsByID(id objectID) {
|
||||
if len(ds.objectsByID) < int(id) {
|
||||
ds.objectsByID = append(ds.objectsByID, make([]*objectDecodeState, int(id)-len(ds.objectsByID))...)
|
||||
}
|
||||
}
|
||||
|
||||
func (ds *decodeState) addObject(id objectID, obj reflect.Value) *objectDecodeState {
|
||||
ods := &objectDecodeState{
|
||||
id: id,
|
||||
obj: obj,
|
||||
}
|
||||
ods.pendingEntry.ods = ods
|
||||
ods.leafEntry.ods = ods
|
||||
ds.growObjectsByID(id)
|
||||
ds.objectsByID[id-1] = ods
|
||||
ds.pending.PushBack(&ods.pendingEntry)
|
||||
ds.leaves.PushBack(&ods.leafEntry)
|
||||
return ods
|
||||
}
|
||||
|
||||
// register registers a decode with a type.
|
||||
//
|
||||
// This type is only used to instantiate a new object if it has not been
|
||||
@@ -288,11 +318,9 @@ func walkChild(path []wire.Dot, obj reflect.Value) reflect.Value {
|
||||
func (ds *decodeState) register(r *wire.Ref, typ reflect.Type) reflect.Value {
|
||||
// Grow the objectsByID slice.
|
||||
id := objectID(r.Root)
|
||||
if len(ds.objectsByID) < int(id) {
|
||||
ds.objectsByID = append(ds.objectsByID, make([]*objectDecodeState, int(id)-len(ds.objectsByID))...)
|
||||
}
|
||||
|
||||
// Does this object already exist?
|
||||
ds.growObjectsByID(id)
|
||||
ods := ds.objectsByID[id-1]
|
||||
if ods != nil {
|
||||
return walkChild(r.Dots, ods.obj)
|
||||
@@ -303,12 +331,7 @@ func (ds *decodeState) register(r *wire.Ref, typ reflect.Type) reflect.Value {
|
||||
typ = ds.findType(r.Type)
|
||||
}
|
||||
v := reflect.New(typ)
|
||||
ods = &objectDecodeState{
|
||||
id: id,
|
||||
obj: v.Elem(),
|
||||
}
|
||||
ds.objectsByID[id-1] = ods
|
||||
ds.pending.PushBack(ods)
|
||||
ods = ds.addObject(id, v.Elem())
|
||||
|
||||
// Process any deferred objects & callbacks.
|
||||
if encoded, ok := ds.deferred[id]; ok {
|
||||
@@ -581,13 +604,8 @@ func (ds *decodeState) Load(obj reflect.Value) {
|
||||
return ds.types.LookupName(id)
|
||||
})
|
||||
|
||||
// Create the root object.
|
||||
rootOds := &objectDecodeState{
|
||||
id: 1,
|
||||
obj: obj,
|
||||
}
|
||||
ds.objectsByID = append(ds.objectsByID, rootOds)
|
||||
ds.pending.PushBack(rootOds)
|
||||
// Add the root object with ID 1.
|
||||
_ = ds.addObject(1, obj)
|
||||
|
||||
// Read the number of objects.
|
||||
numObjects, object, err := ReadHeader(&ds.r)
|
||||
@@ -603,7 +621,6 @@ func (ds *decodeState) Load(obj reflect.Value) {
|
||||
encoded wire.Object
|
||||
ods *objectDecodeState
|
||||
id objectID
|
||||
tid = typeID(1)
|
||||
)
|
||||
if err := safely(func() {
|
||||
// Decode all objects in the stream.
|
||||
@@ -616,7 +633,6 @@ func (ds *decodeState) Load(obj reflect.Value) {
|
||||
switch we := encoded.(type) {
|
||||
case *wire.Type:
|
||||
ds.types.Register(we)
|
||||
tid++
|
||||
encoded = nil
|
||||
continue
|
||||
case wire.Uint:
|
||||
@@ -673,22 +689,13 @@ func (ds *decodeState) Load(obj reflect.Value) {
|
||||
// objects become complete (there is a dependency cycle).
|
||||
//
|
||||
// Note that we iterate backwards here, because there will be a strong
|
||||
// tendendcy for blocking relationships to go from earlier objects to
|
||||
// tendency for blocking relationships to go from earlier objects to
|
||||
// later (deeper) objects in the graph. This will reduce the number of
|
||||
// iterations required to finish all objects.
|
||||
if err := safely(func() {
|
||||
for ds.pending.Back() != nil {
|
||||
thisCycle := false
|
||||
for ods = ds.pending.Back(); ods != nil; {
|
||||
if ds.checkComplete(ods) {
|
||||
thisCycle = true
|
||||
break
|
||||
}
|
||||
ods = ods.Prev()
|
||||
}
|
||||
if !thisCycle {
|
||||
break
|
||||
}
|
||||
for elem := ds.leaves.Front(); elem != nil; elem = elem.Next() {
|
||||
ods = elem.ods
|
||||
ds.checkComplete(elem.ods)
|
||||
}
|
||||
}); err != nil {
|
||||
Failf("error executing callbacks: %w\nfor object %#v", err, ods.obj.Interface())
|
||||
@@ -696,9 +703,9 @@ func (ds *decodeState) Load(obj reflect.Value) {
|
||||
|
||||
// Check if we have any remaining dependency cycles. If there are any
|
||||
// objects left in the pending list, then it must be due to a cycle.
|
||||
if ods := ds.pending.Front(); ods != nil {
|
||||
if elem := ds.pending.Front(); elem != nil {
|
||||
// This must be the result of a dependency cycle.
|
||||
cycle := ods.findCycle()
|
||||
cycle := elem.ods.findCycle()
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString("dependency cycle: {")
|
||||
for i, cycleOS := range cycle {
|
||||
@@ -708,7 +715,7 @@ func (ds *decodeState) Load(obj reflect.Value) {
|
||||
fmt.Fprintf(&buf, "%q", cycleOS.obj.Type())
|
||||
}
|
||||
buf.WriteString("}")
|
||||
Failf("incomplete graph: %s", string(buf.Bytes()))
|
||||
Failf("incomplete graph: %s", buf.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-5
@@ -770,8 +770,11 @@ func (es *encodeState) Save(obj reflect.Value) {
|
||||
es.encodeObject(oes.obj, oes.how, &oes.encoded)
|
||||
}
|
||||
}); err != nil {
|
||||
// Include the object in the error message.
|
||||
Failf("encoding error: %w\nfor object %#v", err, oes.obj.Interface())
|
||||
// Include the object in the error message, if available.
|
||||
if oes != nil && oes.obj.IsValid() {
|
||||
Failf("encoding error: %w\nfor object %#v", err, oes.obj.Interface())
|
||||
}
|
||||
Failf("encoding error: %w", err)
|
||||
}
|
||||
|
||||
// Check that we have objects to serialize.
|
||||
@@ -802,14 +805,19 @@ func (es *encodeState) Save(obj reflect.Value) {
|
||||
})
|
||||
for _, id := range ids {
|
||||
// Encode the id.
|
||||
oes = nil
|
||||
wire.Save(&es.w, wire.Uint(id))
|
||||
// Marshal the object.
|
||||
oes := es.pending[id]
|
||||
oes = es.pending[id]
|
||||
wire.Save(&es.w, oes.encoded)
|
||||
}
|
||||
}); err != nil {
|
||||
// Include the object and the error.
|
||||
Failf("error serializing object %#v: %w", oes.encoded, err)
|
||||
if oes != nil {
|
||||
// Include the object and the error.
|
||||
Failf("error serializing object %#v: %w", oes.encoded, err)
|
||||
} else {
|
||||
Failf("error serializing type or ID: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
vendor/gvisor.dev/gvisor/pkg/state/complete_list.go → vendor/gvisor.dev/gvisor/pkg/state/ods_list.go
Vendored
+42
-42
@@ -6,14 +6,14 @@ package state
|
||||
// objects, if they are not the same. An ElementMapper is not typically
|
||||
// required if: Linker is left as is, Element is left as is, or Linker and
|
||||
// Element are the same type.
|
||||
type completeElementMapper struct{}
|
||||
type odsElementMapper struct{}
|
||||
|
||||
// linkerFor maps an Element to a Linker.
|
||||
//
|
||||
// This default implementation should be inlined.
|
||||
//
|
||||
//go:nosplit
|
||||
func (completeElementMapper) linkerFor(elem *objectDecodeState) *objectDecodeState { return elem }
|
||||
func (odsElementMapper) linkerFor(elem *odsListElem) *odsListElem { return elem }
|
||||
|
||||
// List is an intrusive list. Entries can be added to or removed from the list
|
||||
// in O(1) time and with no additional memory allocations.
|
||||
@@ -27,13 +27,13 @@ func (completeElementMapper) linkerFor(elem *objectDecodeState) *objectDecodeSta
|
||||
// }
|
||||
//
|
||||
// +stateify savable
|
||||
type completeList struct {
|
||||
head *objectDecodeState
|
||||
tail *objectDecodeState
|
||||
type odsList struct {
|
||||
head *odsListElem
|
||||
tail *odsListElem
|
||||
}
|
||||
|
||||
// Reset resets list l to the empty state.
|
||||
func (l *completeList) Reset() {
|
||||
func (l *odsList) Reset() {
|
||||
l.head = nil
|
||||
l.tail = nil
|
||||
}
|
||||
@@ -41,21 +41,21 @@ func (l *completeList) Reset() {
|
||||
// Empty returns true iff the list is empty.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) Empty() bool {
|
||||
func (l *odsList) Empty() bool {
|
||||
return l.head == nil
|
||||
}
|
||||
|
||||
// Front returns the first element of list l or nil.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) Front() *objectDecodeState {
|
||||
func (l *odsList) Front() *odsListElem {
|
||||
return l.head
|
||||
}
|
||||
|
||||
// Back returns the last element of list l or nil.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) Back() *objectDecodeState {
|
||||
func (l *odsList) Back() *odsListElem {
|
||||
return l.tail
|
||||
}
|
||||
|
||||
@@ -64,8 +64,8 @@ func (l *completeList) Back() *objectDecodeState {
|
||||
// NOTE: This is an O(n) operation.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) Len() (count int) {
|
||||
for e := l.Front(); e != nil; e = (completeElementMapper{}.linkerFor(e)).Next() {
|
||||
func (l *odsList) Len() (count int) {
|
||||
for e := l.Front(); e != nil; e = (odsElementMapper{}.linkerFor(e)).Next() {
|
||||
count++
|
||||
}
|
||||
return count
|
||||
@@ -74,12 +74,12 @@ func (l *completeList) Len() (count int) {
|
||||
// PushFront inserts the element e at the front of list l.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) PushFront(e *objectDecodeState) {
|
||||
linker := completeElementMapper{}.linkerFor(e)
|
||||
func (l *odsList) PushFront(e *odsListElem) {
|
||||
linker := odsElementMapper{}.linkerFor(e)
|
||||
linker.SetNext(l.head)
|
||||
linker.SetPrev(nil)
|
||||
if l.head != nil {
|
||||
completeElementMapper{}.linkerFor(l.head).SetPrev(e)
|
||||
odsElementMapper{}.linkerFor(l.head).SetPrev(e)
|
||||
} else {
|
||||
l.tail = e
|
||||
}
|
||||
@@ -90,13 +90,13 @@ func (l *completeList) PushFront(e *objectDecodeState) {
|
||||
// PushFrontList inserts list m at the start of list l, emptying m.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) PushFrontList(m *completeList) {
|
||||
func (l *odsList) PushFrontList(m *odsList) {
|
||||
if l.head == nil {
|
||||
l.head = m.head
|
||||
l.tail = m.tail
|
||||
} else if m.head != nil {
|
||||
completeElementMapper{}.linkerFor(l.head).SetPrev(m.tail)
|
||||
completeElementMapper{}.linkerFor(m.tail).SetNext(l.head)
|
||||
odsElementMapper{}.linkerFor(l.head).SetPrev(m.tail)
|
||||
odsElementMapper{}.linkerFor(m.tail).SetNext(l.head)
|
||||
|
||||
l.head = m.head
|
||||
}
|
||||
@@ -107,12 +107,12 @@ func (l *completeList) PushFrontList(m *completeList) {
|
||||
// PushBack inserts the element e at the back of list l.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) PushBack(e *objectDecodeState) {
|
||||
linker := completeElementMapper{}.linkerFor(e)
|
||||
func (l *odsList) PushBack(e *odsListElem) {
|
||||
linker := odsElementMapper{}.linkerFor(e)
|
||||
linker.SetNext(nil)
|
||||
linker.SetPrev(l.tail)
|
||||
if l.tail != nil {
|
||||
completeElementMapper{}.linkerFor(l.tail).SetNext(e)
|
||||
odsElementMapper{}.linkerFor(l.tail).SetNext(e)
|
||||
} else {
|
||||
l.head = e
|
||||
}
|
||||
@@ -123,13 +123,13 @@ func (l *completeList) PushBack(e *objectDecodeState) {
|
||||
// PushBackList inserts list m at the end of list l, emptying m.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) PushBackList(m *completeList) {
|
||||
func (l *odsList) PushBackList(m *odsList) {
|
||||
if l.head == nil {
|
||||
l.head = m.head
|
||||
l.tail = m.tail
|
||||
} else if m.head != nil {
|
||||
completeElementMapper{}.linkerFor(l.tail).SetNext(m.head)
|
||||
completeElementMapper{}.linkerFor(m.head).SetPrev(l.tail)
|
||||
odsElementMapper{}.linkerFor(l.tail).SetNext(m.head)
|
||||
odsElementMapper{}.linkerFor(m.head).SetPrev(l.tail)
|
||||
|
||||
l.tail = m.tail
|
||||
}
|
||||
@@ -140,9 +140,9 @@ func (l *completeList) PushBackList(m *completeList) {
|
||||
// InsertAfter inserts e after b.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) InsertAfter(b, e *objectDecodeState) {
|
||||
bLinker := completeElementMapper{}.linkerFor(b)
|
||||
eLinker := completeElementMapper{}.linkerFor(e)
|
||||
func (l *odsList) InsertAfter(b, e *odsListElem) {
|
||||
bLinker := odsElementMapper{}.linkerFor(b)
|
||||
eLinker := odsElementMapper{}.linkerFor(e)
|
||||
|
||||
a := bLinker.Next()
|
||||
|
||||
@@ -151,7 +151,7 @@ func (l *completeList) InsertAfter(b, e *objectDecodeState) {
|
||||
bLinker.SetNext(e)
|
||||
|
||||
if a != nil {
|
||||
completeElementMapper{}.linkerFor(a).SetPrev(e)
|
||||
odsElementMapper{}.linkerFor(a).SetPrev(e)
|
||||
} else {
|
||||
l.tail = e
|
||||
}
|
||||
@@ -160,9 +160,9 @@ func (l *completeList) InsertAfter(b, e *objectDecodeState) {
|
||||
// InsertBefore inserts e before a.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) InsertBefore(a, e *objectDecodeState) {
|
||||
aLinker := completeElementMapper{}.linkerFor(a)
|
||||
eLinker := completeElementMapper{}.linkerFor(e)
|
||||
func (l *odsList) InsertBefore(a, e *odsListElem) {
|
||||
aLinker := odsElementMapper{}.linkerFor(a)
|
||||
eLinker := odsElementMapper{}.linkerFor(e)
|
||||
|
||||
b := aLinker.Prev()
|
||||
eLinker.SetNext(a)
|
||||
@@ -170,7 +170,7 @@ func (l *completeList) InsertBefore(a, e *objectDecodeState) {
|
||||
aLinker.SetPrev(e)
|
||||
|
||||
if b != nil {
|
||||
completeElementMapper{}.linkerFor(b).SetNext(e)
|
||||
odsElementMapper{}.linkerFor(b).SetNext(e)
|
||||
} else {
|
||||
l.head = e
|
||||
}
|
||||
@@ -179,19 +179,19 @@ func (l *completeList) InsertBefore(a, e *objectDecodeState) {
|
||||
// Remove removes e from l.
|
||||
//
|
||||
//go:nosplit
|
||||
func (l *completeList) Remove(e *objectDecodeState) {
|
||||
linker := completeElementMapper{}.linkerFor(e)
|
||||
func (l *odsList) Remove(e *odsListElem) {
|
||||
linker := odsElementMapper{}.linkerFor(e)
|
||||
prev := linker.Prev()
|
||||
next := linker.Next()
|
||||
|
||||
if prev != nil {
|
||||
completeElementMapper{}.linkerFor(prev).SetNext(next)
|
||||
odsElementMapper{}.linkerFor(prev).SetNext(next)
|
||||
} else if l.head == e {
|
||||
l.head = next
|
||||
}
|
||||
|
||||
if next != nil {
|
||||
completeElementMapper{}.linkerFor(next).SetPrev(prev)
|
||||
odsElementMapper{}.linkerFor(next).SetPrev(prev)
|
||||
} else if l.tail == e {
|
||||
l.tail = prev
|
||||
}
|
||||
@@ -205,35 +205,35 @@ func (l *completeList) Remove(e *objectDecodeState) {
|
||||
// methods needed by List.
|
||||
//
|
||||
// +stateify savable
|
||||
type completeEntry struct {
|
||||
next *objectDecodeState
|
||||
prev *objectDecodeState
|
||||
type odsEntry struct {
|
||||
next *odsListElem
|
||||
prev *odsListElem
|
||||
}
|
||||
|
||||
// Next returns the entry that follows e in the list.
|
||||
//
|
||||
//go:nosplit
|
||||
func (e *completeEntry) Next() *objectDecodeState {
|
||||
func (e *odsEntry) Next() *odsListElem {
|
||||
return e.next
|
||||
}
|
||||
|
||||
// Prev returns the entry that precedes e in the list.
|
||||
//
|
||||
//go:nosplit
|
||||
func (e *completeEntry) Prev() *objectDecodeState {
|
||||
func (e *odsEntry) Prev() *odsListElem {
|
||||
return e.prev
|
||||
}
|
||||
|
||||
// SetNext assigns 'entry' as the entry that follows e in the list.
|
||||
//
|
||||
//go:nosplit
|
||||
func (e *completeEntry) SetNext(elem *objectDecodeState) {
|
||||
func (e *odsEntry) SetNext(elem *odsListElem) {
|
||||
e.next = elem
|
||||
}
|
||||
|
||||
// SetPrev assigns 'entry' as the entry that precedes e in the list.
|
||||
//
|
||||
//go:nosplit
|
||||
func (e *completeEntry) SetPrev(elem *objectDecodeState) {
|
||||
func (e *odsEntry) SetPrev(elem *odsListElem) {
|
||||
e.prev = elem
|
||||
}
|
||||
+1
-1
@@ -188,7 +188,7 @@ func (s Sink) Context() context.Context {
|
||||
// Type is an interface that must be implemented by Struct objects. This allows
|
||||
// these objects to be serialized while minimizing runtime reflection required.
|
||||
//
|
||||
// All these methods can be automatically generated by the go_statify tool.
|
||||
// All these methods can be automatically generated by the go_stateify tool.
|
||||
type Type interface {
|
||||
// StateTypeName returns the type's name.
|
||||
//
|
||||
|
||||
+13
-11
@@ -19,6 +19,8 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/gohacks"
|
||||
)
|
||||
|
||||
type statEntry struct {
|
||||
@@ -48,13 +50,13 @@ type Stats struct {
|
||||
// on the stats object.
|
||||
names []string
|
||||
|
||||
// last is the last start time.
|
||||
last time.Time
|
||||
// last is the monotonic time of the last sample.
|
||||
last int64
|
||||
}
|
||||
|
||||
// init initializes statistics.
|
||||
func (s *Stats) init() {
|
||||
s.last = time.Now()
|
||||
s.last = gohacks.Nanotime()
|
||||
s.stack = append(s.stack, 0)
|
||||
}
|
||||
|
||||
@@ -72,12 +74,12 @@ func (s *Stats) fini(resolve func(id typeID) string) {
|
||||
|
||||
// sample adds the samples to the given object.
|
||||
func (s *Stats) sample(id typeID) {
|
||||
now := time.Now()
|
||||
now := gohacks.Nanotime()
|
||||
if len(s.byType) <= int(id) {
|
||||
// Allocate all the missing entries in one fell swoop.
|
||||
s.byType = append(s.byType, make([]statEntry, 1+int(id)-len(s.byType))...)
|
||||
}
|
||||
s.byType[id].total += now.Sub(s.last)
|
||||
s.byType[id].total += time.Duration(now - s.last)
|
||||
s.last = now
|
||||
}
|
||||
|
||||
@@ -124,7 +126,7 @@ func (s *Stats) String() string {
|
||||
total time.Duration
|
||||
)
|
||||
buf.WriteString("\n")
|
||||
buf.WriteString(fmt.Sprintf("% 16s | % 8s | % 16s | %s\n", "total", "count", "per", "type"))
|
||||
fmt.Fprintf(&buf, "% 16s | % 8s | % 16s | %s\n", "total", "count", "per", "type")
|
||||
buf.WriteString("-----------------+----------+------------------+----------------\n")
|
||||
for _, se := range ss {
|
||||
if se.entry.count == 0 {
|
||||
@@ -135,11 +137,11 @@ func (s *Stats) String() string {
|
||||
count += se.entry.count
|
||||
total += se.entry.total
|
||||
per := se.entry.total / time.Duration(se.entry.count)
|
||||
buf.WriteString(fmt.Sprintf("% 16s | %8d | % 16s | %s\n",
|
||||
se.entry.total, se.entry.count, per, se.name))
|
||||
fmt.Fprintf(&buf, "% 16s | %8d | % 16s | %s\n",
|
||||
se.entry.total, se.entry.count, per, se.name)
|
||||
}
|
||||
buf.WriteString("-----------------+----------+------------------+----------------\n")
|
||||
buf.WriteString(fmt.Sprintf("% 16s | % 8d | % 16s | [all]",
|
||||
total, count, total/time.Duration(count)))
|
||||
return string(buf.Bytes())
|
||||
fmt.Fprintf(&buf, "% 16s | % 8d | % 16s | [all]",
|
||||
total, count, total/time.Duration(count))
|
||||
return buf.String()
|
||||
}
|
||||
+17
-17
@@ -295,23 +295,23 @@ const interfaceType = "interface"
|
||||
var primitiveTypeDatabase = func() map[string]reflect.Type {
|
||||
r := make(map[string]reflect.Type)
|
||||
for _, t := range []reflect.Type{
|
||||
reflect.TypeOf(false),
|
||||
reflect.TypeOf(int(0)),
|
||||
reflect.TypeOf(int8(0)),
|
||||
reflect.TypeOf(int16(0)),
|
||||
reflect.TypeOf(int32(0)),
|
||||
reflect.TypeOf(int64(0)),
|
||||
reflect.TypeOf(uint(0)),
|
||||
reflect.TypeOf(uintptr(0)),
|
||||
reflect.TypeOf(uint8(0)),
|
||||
reflect.TypeOf(uint16(0)),
|
||||
reflect.TypeOf(uint32(0)),
|
||||
reflect.TypeOf(uint64(0)),
|
||||
reflect.TypeOf(""),
|
||||
reflect.TypeOf(float32(0.0)),
|
||||
reflect.TypeOf(float64(0.0)),
|
||||
reflect.TypeOf(complex64(0.0)),
|
||||
reflect.TypeOf(complex128(0.0)),
|
||||
reflect.TypeFor[bool](),
|
||||
reflect.TypeFor[int](),
|
||||
reflect.TypeFor[int8](),
|
||||
reflect.TypeFor[int16](),
|
||||
reflect.TypeFor[int32](),
|
||||
reflect.TypeFor[int64](),
|
||||
reflect.TypeFor[uint](),
|
||||
reflect.TypeFor[uintptr](),
|
||||
reflect.TypeFor[uint8](),
|
||||
reflect.TypeFor[uint16](),
|
||||
reflect.TypeFor[uint32](),
|
||||
reflect.TypeFor[uint64](),
|
||||
reflect.TypeFor[string](),
|
||||
reflect.TypeFor[float32](),
|
||||
reflect.TypeFor[float64](),
|
||||
reflect.TypeFor[complex64](),
|
||||
reflect.TypeFor[complex128](),
|
||||
} {
|
||||
r[t.Name()] = t
|
||||
}
|
||||
|
||||
+1
-1
@@ -509,7 +509,7 @@ func loadMap(r *Reader) Map {
|
||||
func (m *Map) save(w *Writer) {
|
||||
l := Uint(len(m.Keys))
|
||||
if int(l) != len(m.Values) {
|
||||
panic(fmt.Sprintf("mismatched keys (%d) Aand values (%d)", len(m.Keys), len(m.Values)))
|
||||
panic(fmt.Sprintf("mismatched keys (%d) and values (%d)", len(m.Keys), len(m.Values)))
|
||||
}
|
||||
l.save(w)
|
||||
if l == 0 {
|
||||
|
||||
Reference in new issue
Block a user