Skip to content

Commit 65b2b1a

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[VM] Split handling of Code from non-Code in Thread::{CanLoadFromThread,OffsetFromThread}
Not only does it speed the two methods a bit up, it will also allow us to use the assembler before all of the stubs are initialized. Issue #31798 Change-Id: Ic14743ecd9d11ca4cbc5208cacad30beee0982ef Reviewed-on: https://dart-review.googlesource.com/44500 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]>
1 parent 2f10ab7 commit 65b2b1a

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

runtime/vm/thread.cc

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,19 +661,53 @@ void Thread::VisitObjectPointers(ObjectPointerVisitor* visitor,
661661
}
662662

663663
bool Thread::CanLoadFromThread(const Object& object) {
664+
// In order to allow us to use assembler helper routines with non-[Code]
665+
// objects *before* stubs are initialized, we only loop ver the stubs if the
666+
// [object] is in fact a [Code] object.
667+
if (object.IsCode()) {
664668
#define CHECK_OBJECT(type_name, member_name, expr, default_init_value) \
665-
if (object.raw() == expr) return true;
666-
CACHED_VM_OBJECTS_LIST(CHECK_OBJECT)
669+
if (object.raw() == expr) { \
670+
return true; \
671+
}
672+
CACHED_VM_STUBS_LIST(CHECK_OBJECT)
673+
#undef CHECK_OBJECT
674+
}
675+
676+
// For non [Code] objects we check if the object equals to any of the cached
677+
// non-stub entries.
678+
#define CHECK_OBJECT(type_name, member_name, expr, default_init_value) \
679+
if (object.raw() == expr) { \
680+
return true; \
681+
}
682+
CACHED_NON_VM_STUB_LIST(CHECK_OBJECT)
667683
#undef CHECK_OBJECT
668684
return false;
669685
}
670686

671687
intptr_t Thread::OffsetFromThread(const Object& object) {
688+
// In order to allow us to use assembler helper routines with non-[Code]
689+
// objects *before* stubs are initialized, we only loop ver the stubs if the
690+
// [object] is in fact a [Code] object.
691+
if (object.IsCode()) {
672692
#define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \
673693
ASSERT((expr)->IsVMHeapObject()); \
674-
if (object.raw() == expr) return Thread::member_name##offset();
675-
CACHED_VM_OBJECTS_LIST(COMPUTE_OFFSET)
694+
if (object.raw() == expr) { \
695+
return Thread::member_name##offset(); \
696+
}
697+
CACHED_VM_STUBS_LIST(COMPUTE_OFFSET)
698+
#undef COMPUTE_OFFSET
699+
}
700+
701+
// For non [Code] objects we check if the object equals to any of the cached
702+
// non-stub entries.
703+
#define COMPUTE_OFFSET(type_name, member_name, expr, default_init_value) \
704+
ASSERT((expr)->IsVMHeapObject()); \
705+
if (object.raw() == expr) { \
706+
return Thread::member_name##offset(); \
707+
}
708+
CACHED_NON_VM_STUB_LIST(COMPUTE_OFFSET)
676709
#undef COMPUTE_OFFSET
710+
677711
UNREACHABLE();
678712
return -1;
679713
}

runtime/vm/thread.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,15 @@ class Zone;
101101

102102
#endif
103103

104+
#define CACHED_NON_VM_STUB_LIST(V) \
105+
V(RawObject*, object_null_, Object::null(), NULL) \
106+
V(RawBool*, bool_true_, Object::bool_true().raw(), NULL) \
107+
V(RawBool*, bool_false_, Object::bool_false().raw(), NULL)
108+
104109
// List of VM-global objects/addresses cached in each Thread object.
105110
// Important: constant false must immediately follow constant true.
106111
#define CACHED_VM_OBJECTS_LIST(V) \
107-
V(RawObject*, object_null_, Object::null(), NULL) \
108-
V(RawBool*, bool_true_, Object::bool_true().raw(), NULL) \
109-
V(RawBool*, bool_false_, Object::bool_false().raw(), NULL) \
112+
CACHED_NON_VM_STUB_LIST(V) \
110113
CACHED_VM_STUBS_LIST(V)
111114

112115
// This assertion marks places which assume that boolean false immediate

0 commit comments

Comments
 (0)