Skip to content

Commit

Permalink
Don't create a handle to a non-object.
Browse files Browse the repository at this point in the history
Remove casts that disguised this, which have probably been unnecessary since tagged pointers became represented as C++ values instead of C++ pointers.
  • Loading branch information
rmacnak committed Jun 9, 2024
1 parent 84acb7d commit aaf9a78
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 54 deletions.
47 changes: 23 additions & 24 deletions vm/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,9 @@ void Interpreter::DNUSend(String selector,

Array arguments;
{
HandleScope h1(H, reinterpret_cast<Object*>(&selector));
HandleScope h1(H, &selector);
HandleScope h2(H, &receiver);
HandleScope h3(H, reinterpret_cast<Object*>(&method));
HandleScope h3(H, &method);
arguments = H->AllocateArray(num_args); // SAFEPOINT
}
for (intptr_t i = 0; i < num_args; i++) {
Expand All @@ -604,10 +604,10 @@ void Interpreter::DNUSend(String selector,
}
Message message;
{
HandleScope h1(H, reinterpret_cast<Object*>(&selector));
HandleScope h1(H, &selector);
HandleScope h2(H, &receiver);
HandleScope h3(H, reinterpret_cast<Object*>(&method));
HandleScope h4(H, reinterpret_cast<Object*>(&arguments));
HandleScope h3(H, &method);
HandleScope h4(H, &arguments);
message = H->AllocateMessage(); // SAFEPOINT
}

Expand Down Expand Up @@ -653,7 +653,7 @@ void Interpreter::SendAboutToReturnThrough(Object result, Activation unwind) {
Activation top;
{
HandleScope h1(H, &result);
HandleScope h2(H, reinterpret_cast<Object*>(&unwind));
HandleScope h2(H, &unwind);
top = EnsureActivation(fp_); // SAFEPOINT
}

Expand Down Expand Up @@ -780,7 +780,7 @@ void Interpreter::Activate(Method method, intptr_t num_args) {
PopNAndPush(2, receiver);
return;
} else {
HandleScope h1(H, reinterpret_cast<Object*>(&method));
HandleScope h1(H, &method);
if (Primitives::Invoke(prim, num_args, H, this)) { // SAFEPOINT
ASSERT(StackDepth() >= 0);
return;
Expand Down Expand Up @@ -931,7 +931,7 @@ void Interpreter::LocalBaseReturn(Object result) {
// Returning from the base frame.
Activation top;
{
HandleScope h(H, reinterpret_cast<Object*>(&result));
HandleScope h(H, &result);
top = FlushAllFrames(); // SAFEPOINT
}

Expand Down Expand Up @@ -993,8 +993,8 @@ void Interpreter::NonLocalReturn(Object result) {

Activation top;
{
HandleScope h1(H, reinterpret_cast<Object*>(&home));
HandleScope h2(H, reinterpret_cast<Object*>(&result));
HandleScope h1(H, &home);
HandleScope h2(H, &result);
top = FlushAllFrames(); // SAFEPOINT
}

Expand Down Expand Up @@ -1644,7 +1644,7 @@ Activation Interpreter::EnsureActivation(Object* fp) {

Activation Interpreter::FlushAllFrames() {
Activation top = EnsureActivation(fp_); // SAFEPOINT
HandleScope h1(H, reinterpret_cast<Object*>(&top));
HandleScope h1(H, &top);

while (fp_ != nullptr) {
EnsureActivation(fp_); // SAFEPOINT
Expand Down Expand Up @@ -1718,7 +1718,7 @@ void Interpreter::SetCurrentActivation(Activation new_activation) {
ASSERT(new_activation->IsActivation());

if (fp_ != nullptr) {
HandleScope h1(H, reinterpret_cast<Object*>(&new_activation));
HandleScope h1(H, &new_activation);
FlushAllFrames(); // SAFEPOINT
}

Expand All @@ -1745,8 +1745,8 @@ void Interpreter::ActivationSenderPut(Activation activation,
if (HasLivingFrame(activation)) {
Activation top;
{
HandleScope h1(H, reinterpret_cast<Object*>(&activation));
HandleScope h2(H, reinterpret_cast<Object*>(&new_sender));
HandleScope h1(H, &activation);
HandleScope h2(H, &new_sender);
top = FlushAllFrames(); // SAFEPOINT
}
activation->set_sender(new_sender);
Expand Down Expand Up @@ -1784,8 +1784,8 @@ void Interpreter::ActivationBCIPut(Activation activation,
if (HasLivingFrame(activation)) {
Activation top;
{
HandleScope h1(H, reinterpret_cast<Object*>(&activation));
HandleScope h2(H, reinterpret_cast<Object*>(&new_bci));
HandleScope h1(H, &activation);
HandleScope h2(H, &new_bci);
top = FlushAllFrames(); // SAFEPOINT
}
activation->set_bci(new_bci);
Expand All @@ -1800,8 +1800,8 @@ void Interpreter::ActivationMethodPut(Activation activation,
if (HasLivingFrame(activation)) {
Activation top;
{
HandleScope h1(H, reinterpret_cast<Object*>(&activation));
HandleScope h2(H, reinterpret_cast<Object*>(&new_method));
HandleScope h1(H, &activation);
HandleScope h2(H, &new_method);
top = FlushAllFrames(); // SAFEPOINT
}
activation->set_method(new_method);
Expand All @@ -1816,8 +1816,8 @@ void Interpreter::ActivationClosurePut(Activation activation,
if (HasLivingFrame(activation)) {
Activation top;
{
HandleScope h1(H, reinterpret_cast<Object*>(&activation));
HandleScope h2(H, reinterpret_cast<Object*>(&new_closure));
HandleScope h1(H, &activation);
HandleScope h2(H, &new_closure);
top = FlushAllFrames(); // SAFEPOINT
}
activation->set_closure(new_closure);
Expand All @@ -1832,8 +1832,8 @@ void Interpreter::ActivationReceiverPut(Activation activation,
if (HasLivingFrame(activation)) {
Activation top;
{
HandleScope h1(H, reinterpret_cast<Object*>(&activation));
HandleScope h2(H, reinterpret_cast<Object*>(&new_receiver));
HandleScope h1(H, &activation);
HandleScope h2(H, &new_receiver);
top = FlushAllFrames(); // SAFEPOINT
}
activation->set_receiver(new_receiver);
Expand Down Expand Up @@ -1892,8 +1892,7 @@ void Interpreter::ActivationTempSizePut(Activation activation,
if (HasLivingFrame(activation)) {
Activation top;
{
HandleScope h1(H, reinterpret_cast<Object*>(&activation));
HandleScope h2(H, reinterpret_cast<Object*>(&new_size));
HandleScope h1(H, &activation);
top = FlushAllFrames(); // SAFEPOINT
}
intptr_t old_size = activation->StackDepth();
Expand Down
2 changes: 1 addition & 1 deletion vm/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Interpreter {
void GCPrologue();
void RootPointers(Object** from, Object** to) {
*from = &nil_;
*to = reinterpret_cast<Object*>(&object_store_);
*to = &object_store_;
}
void StackPointers(Object** from, Object** to) {
*from = sp_;
Expand Down
4 changes: 2 additions & 2 deletions vm/isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void Isolate::ActivateMessage(IsolateMessage* isolate_message) {
strings->set_element(i, SmallInteger::New(0));
}

HandleScope h1(heap_, reinterpret_cast<Object*>(&strings));
HandleScope h1(heap_, &strings);
for (intptr_t i = 0; i < argc; i++) {
const char* cstr = isolate_message->argv()[i];
intptr_t length = strlen(cstr);
Expand All @@ -145,7 +145,7 @@ void Isolate::ActivateMessage(IsolateMessage* isolate_message) {
} else if (SmallInteger::IsSmiValue(port_id)) {
port = SmallInteger::New(static_cast<intptr_t>(port_id));
} else {
HandleScope h1(heap_, reinterpret_cast<Object*>(&message));
HandleScope h1(heap_, &message);
MediumInteger mint = heap_->AllocateMediumInteger(); // SAFEPOINT
mint->set_value(port_id);
port = mint;
Expand Down
36 changes: 18 additions & 18 deletions vm/large_integer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ static LargeInteger AddAbsolutesWithSign(LargeInteger left,
longer = left;
}

HandleScope h1(H, reinterpret_cast<Object*>(&shorter));
HandleScope h2(H, reinterpret_cast<Object*>(&longer));
HandleScope h1(H, &shorter);
HandleScope h2(H, &longer);
LargeInteger result = H->AllocateLargeInteger(longer->size() + 1);

ddigit_t carry = 0;
Expand Down Expand Up @@ -211,8 +211,8 @@ static LargeInteger SubtractAbsolutesWithSign(LargeInteger left,
ASSERT(left->size() >= right->size());
ASSERT(!AbsGreater(right, left));

HandleScope h1(H, reinterpret_cast<Object*>(&left));
HandleScope h2(H, reinterpret_cast<Object*>(&right));
HandleScope h1(H, &left);
HandleScope h2(H, &right);
LargeInteger result = H->AllocateLargeInteger(left->size());

sddigit_t borrow = 0;
Expand Down Expand Up @@ -263,8 +263,8 @@ LargeInteger MultiplyAbsolutesWithSign(LargeInteger left,
Verify(left);
Verify(right);

HandleScope h1(H, reinterpret_cast<Object*>(&left));
HandleScope h2(H, reinterpret_cast<Object*>(&right));
HandleScope h1(H, &left);
HandleScope h2(H, &right);
LargeInteger result = H->AllocateLargeInteger(left->size() + right->size());

for (intptr_t i = 0; i < left->size(); i++) {
Expand Down Expand Up @@ -360,8 +360,8 @@ LargeInteger LargeInteger::And(LargeInteger left,
}

intptr_t result_size = longer->size();
HandleScope h1(H, reinterpret_cast<Object*>(&shorter));
HandleScope h2(H, reinterpret_cast<Object*>(&longer));
HandleScope h1(H, &shorter);
HandleScope h2(H, &longer);
LargeInteger result = H->AllocateLargeInteger(result_size);

if (!shorter->negative() && !longer->negative()) {
Expand Down Expand Up @@ -465,8 +465,8 @@ LargeInteger LargeInteger::Or(LargeInteger left,
}

intptr_t result_size = longer->size();
HandleScope h1(H, reinterpret_cast<Object*>(&shorter));
HandleScope h2(H, reinterpret_cast<Object*>(&longer));
HandleScope h1(H, &shorter);
HandleScope h2(H, &longer);
LargeInteger result = H->AllocateLargeInteger(result_size);

if (!shorter->negative() && !longer->negative()) {
Expand Down Expand Up @@ -606,8 +606,8 @@ LargeInteger LargeInteger::Xor(LargeInteger left,
}

intptr_t result_size = longer->size();
HandleScope h1(H, reinterpret_cast<Object*>(&shorter));
HandleScope h2(H, reinterpret_cast<Object*>(&longer));
HandleScope h1(H, &shorter);
HandleScope h2(H, &longer);
LargeInteger result = H->AllocateLargeInteger(result_size);

if (!shorter->negative() && !longer->negative()) {
Expand Down Expand Up @@ -740,7 +740,7 @@ LargeInteger LargeInteger::ShiftLeft(LargeInteger left,
// This case is singled out not for performance but to avoid
// the undefined behavior of digit_t >> kDigitBits.
intptr_t result_size = left->size() + digit_shift;
HandleScope h1(H, reinterpret_cast<Object*>(&left));
HandleScope h1(H, &left);
LargeInteger result = H->AllocateLargeInteger(result_size);

for (intptr_t i = 0; i < digit_shift; i++) {
Expand All @@ -757,7 +757,7 @@ LargeInteger LargeInteger::ShiftLeft(LargeInteger left,
}

intptr_t result_size = left->size() + digit_shift + 1;
HandleScope h1(H, reinterpret_cast<Object*>(&left));
HandleScope h1(H, &left);
LargeInteger result = H->AllocateLargeInteger(result_size);

for (intptr_t i = 0; i < digit_shift; i++) {
Expand Down Expand Up @@ -795,7 +795,7 @@ LargeInteger LargeInteger::ShiftRight(LargeInteger left,
// This case is singled out not for performance but to avoid
// the undefined behavior of digit_t << kDigitBits.
intptr_t result_size = left->size() - digit_shift;
HandleScope h1(H, reinterpret_cast<Object*>(&left));
HandleScope h1(H, &left);
LargeInteger result = H->AllocateLargeInteger(result_size);

for (intptr_t i = 0; i < result_size; i++) {
Expand All @@ -820,7 +820,7 @@ LargeInteger LargeInteger::ShiftRight(LargeInteger left,
}

intptr_t result_size = left->size() - digit_shift;
HandleScope h1(H, reinterpret_cast<Object*>(&left));
HandleScope h1(H, &left);
LargeInteger result = H->AllocateLargeInteger(result_size);

digit_t carry = left->digit(digit_shift) >> bit_shift_down;
Expand Down Expand Up @@ -951,8 +951,8 @@ LargeInteger LargeInteger::Divide(DivOperationType op_type,
UNREACHABLE();
}

HandleScope h1(H, reinterpret_cast<Object*>(&dividend));
HandleScope h2(H, reinterpret_cast<Object*>(&divisor));
HandleScope h1(H, &dividend);
HandleScope h2(H, &divisor);
LargeInteger quoitent = H->AllocateLargeInteger(m - n + 1);
quoitent->set_negative(dividend->negative() != divisor->negative());

Expand Down
8 changes: 4 additions & 4 deletions vm/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -1134,10 +1134,10 @@ void Activation::set_temp(intptr_t index, Object o, Barrier barrier) {
Store(&ptr()->temps_[index], o, barrier);
}
Object* Activation::from() {
return reinterpret_cast<Object*>(&ptr()->sender_);
return &ptr()->sender_;
}
Object* Activation::to() {
return reinterpret_cast<Object*>(&ptr()->stack_depth_) + StackDepth();
return &ptr()->stack_depth_ + StackDepth();
}

double Float::value() const { return ptr()->value_; }
Expand Down Expand Up @@ -1174,10 +1174,10 @@ void Closure::set_copied(intptr_t index, Object o, Barrier barrier) {
Store(&ptr()->copied_[index], o, barrier);
}
Object* Closure::from() {
return reinterpret_cast<Object*>(&ptr()->num_copied_);
return &ptr()->num_copied_;
}
Object* Closure::to() {
return reinterpret_cast<Object*>(&ptr()->copied_[NumCopied() - 1]);
return &ptr()->copied_[NumCopied() - 1];
}

Behavior Behavior::superclass() const { return Load(&ptr()->superclass_); }
Expand Down
10 changes: 5 additions & 5 deletions vm/primitives.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ const bool kFailure = false;
LargeInteger large_left; \
LargeInteger large_right; \
{ \
HandleScope h1(H, reinterpret_cast<Object*>(&right)); \
HandleScope h1(H, &right); \
large_left = LargeInteger::Expand(left, H); \
HandleScope h2(H, reinterpret_cast<Object*>(&large_left)); \
HandleScope h2(H, &large_left); \
large_right = LargeInteger::Expand(right, H); \
}

Expand Down Expand Up @@ -3167,9 +3167,9 @@ DEFINE_PRIMITIVE(ZXChannel_read) {
RETURN_SMI(status);
}

HandleScope h1(H, reinterpret_cast<Object*>(&multiple_return));
HandleScope h1(H, &multiple_return);
ByteArray bytes = H->AllocateByteArray(actual_bytes);
HandleScope h2(H, reinterpret_cast<Object*>(&bytes));
HandleScope h2(H, &bytes);
Array handles = H->AllocateArray(actual_handles);

zx_handle_t raw_handles[ZX_CHANNEL_MAX_MSG_HANDLES];
Expand Down Expand Up @@ -3316,7 +3316,7 @@ DEFINE_PRIMITIVE(ZXVmo_read) {
if (!multiple_return->IsArray() || (multiple_return->Size() < 1)) {
return kFailure;
}
HandleScope h1(H, reinterpret_cast<Object*>(&multiple_return));
HandleScope h1(H, &multiple_return);
ByteArray buffer = H->AllocateByteArray(size->value()); // SAFEPOINT
zx_status_t status = zx_vmo_read(AsHandle(vmo), buffer->element_addr(0),
offset->value(), size->value());
Expand Down

0 comments on commit aaf9a78

Please # to comment.