Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: src/hydrogen-instructions.cc

Issue 12049012: Avoid handle dereference during graph optimization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 case kJSArray: return "array"; 335 case kJSArray: return "array";
336 case kJSObject: return "object"; 336 case kJSObject: return "object";
337 case kUninitialized: return "uninitialized"; 337 case kUninitialized: return "uninitialized";
338 } 338 }
339 UNREACHABLE(); 339 UNREACHABLE();
340 return "Unreachable code"; 340 return "Unreachable code";
341 } 341 }
342 342
343 343
344 HType HType::TypeFromValue(Handle<Object> value) { 344 HType HType::TypeFromValue(Handle<Object> value) {
345 // Handle dereferencing is safe here: an object's type as checked below
346 // never changes.
347 AllowHandleDereference allow_handle_deref;
348
345 HType result = HType::Tagged(); 349 HType result = HType::Tagged();
346 if (value->IsSmi()) { 350 if (value->IsSmi()) {
347 result = HType::Smi(); 351 result = HType::Smi();
348 } else if (value->IsHeapNumber()) { 352 } else if (value->IsHeapNumber()) {
349 result = HType::HeapNumber(); 353 result = HType::HeapNumber();
350 } else if (value->IsString()) { 354 } else if (value->IsString()) {
351 result = HType::String(); 355 result = HType::String();
352 } else if (value->IsBoolean()) { 356 } else if (value->IsBoolean()) {
353 result = HType::Boolean(); 357 result = HType::Boolean();
354 } else if (value->IsJSObject()) { 358 } else if (value->IsJSObject()) {
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 return this; 1116 return this;
1113 } 1117 }
1114 1118
1115 1119
1116 HValue* HCheckInstanceType::Canonicalize() { 1120 HValue* HCheckInstanceType::Canonicalize() {
1117 if (check_ == IS_STRING && 1121 if (check_ == IS_STRING &&
1118 !value()->type().IsUninitialized() && 1122 !value()->type().IsUninitialized() &&
1119 value()->type().IsString()) { 1123 value()->type().IsString()) {
1120 return NULL; 1124 return NULL;
1121 } 1125 }
1122 if (check_ == IS_SYMBOL && 1126
1123 value()->IsConstant() && 1127 if (check_ == IS_SYMBOL && value()->IsConstant()) {
1124 HConstant::cast(value())->handle()->IsSymbol()) { 1128 // Dereferencing is safe here: a symbol cannot become a non-symbol.
1125 return NULL; 1129 AllowHandleDereference allow_handle_deref;
1130 if (HConstant::cast(value())->handle()->IsSymbol()) return NULL;
1126 } 1131 }
1127 return this; 1132 return this;
1128 } 1133 }
1129 1134
1130 1135
1131 void HCheckInstanceType::GetCheckInterval(InstanceType* first, 1136 void HCheckInstanceType::GetCheckInterval(InstanceType* first,
1132 InstanceType* last) { 1137 InstanceType* last) {
1133 ASSERT(is_interval_check()); 1138 ASSERT(is_interval_check());
1134 switch (check_) { 1139 switch (check_) {
1135 case IS_SPEC_OBJECT: 1140 case IS_SPEC_OBJECT:
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 static bool IsInteger32(double value) { 1553 static bool IsInteger32(double value) {
1549 double roundtrip_value = static_cast<double>(static_cast<int32_t>(value)); 1554 double roundtrip_value = static_cast<double>(static_cast<int32_t>(value));
1550 return BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(value); 1555 return BitCast<int64_t>(roundtrip_value) == BitCast<int64_t>(value);
1551 } 1556 }
1552 1557
1553 1558
1554 HConstant::HConstant(Handle<Object> handle, Representation r) 1559 HConstant::HConstant(Handle<Object> handle, Representation r)
1555 : handle_(handle), 1560 : handle_(handle),
1556 has_int32_value_(false), 1561 has_int32_value_(false),
1557 has_double_value_(false) { 1562 has_double_value_(false) {
1563 // Dereferencing here is safe: the value of a number object does not change.
1564 AllowHandleDereference allow_handle_deref;
1558 SetFlag(kUseGVN); 1565 SetFlag(kUseGVN);
1559 if (handle_->IsNumber()) { 1566 if (handle_->IsNumber()) {
1560 double n = handle_->Number(); 1567 double n = handle_->Number();
1561 has_int32_value_ = IsInteger32(n); 1568 has_int32_value_ = IsInteger32(n);
1562 int32_value_ = DoubleToInt32(n); 1569 int32_value_ = DoubleToInt32(n);
1563 double_value_ = n; 1570 double_value_ = n;
1564 has_double_value_ = true; 1571 has_double_value_ = true;
1565 } 1572 }
1566 if (r.IsNone()) { 1573 if (r.IsNone()) {
1567 if (has_int32_value_) { 1574 if (has_int32_value_) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 1633
1627 1634
1628 bool HConstant::ToBoolean() { 1635 bool HConstant::ToBoolean() {
1629 // Converts the constant's boolean value according to 1636 // Converts the constant's boolean value according to
1630 // ECMAScript section 9.2 ToBoolean conversion. 1637 // ECMAScript section 9.2 ToBoolean conversion.
1631 if (HasInteger32Value()) return Integer32Value() != 0; 1638 if (HasInteger32Value()) return Integer32Value() != 0;
1632 if (HasDoubleValue()) { 1639 if (HasDoubleValue()) {
1633 double v = DoubleValue(); 1640 double v = DoubleValue();
1634 return v != 0 && !isnan(v); 1641 return v != 0 && !isnan(v);
1635 } 1642 }
1636 Handle<Object> literal = handle(); 1643 // Dereferencing is safe: singletons do not change and strings are
1637 if (literal->IsTrue()) return true; 1644 // immutable.
1638 if (literal->IsFalse()) return false; 1645 AllowHandleDereference allow_handle_deref;
1639 if (literal->IsUndefined()) return false; 1646 if (handle_->IsTrue()) return true;
1640 if (literal->IsNull()) return false; 1647 if (handle_->IsFalse()) return false;
1641 if (literal->IsString() && String::cast(*literal)->length() == 0) { 1648 if (handle_->IsUndefined()) return false;
1649 if (handle_->IsNull()) return false;
1650 if (handle_->IsString() && String::cast(*handle_)->length() == 0) {
1642 return false; 1651 return false;
1643 } 1652 }
1644 return true; 1653 return true;
1645 } 1654 }
1646 1655
1647 void HConstant::PrintDataTo(StringStream* stream) { 1656 void HConstant::PrintDataTo(StringStream* stream) {
1648 if (has_int32_value_) { 1657 if (has_int32_value_) {
1649 stream->Add("%d ", int32_value_); 1658 stream->Add("%d ", int32_value_);
1650 } else if (has_double_value_) { 1659 } else if (has_double_value_) {
1651 stream->Add("%f ", FmtElm(double_value_)); 1660 stream->Add("%f ", FmtElm(double_value_));
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2805 2814
2806 2815
2807 void HCheckFunction::Verify() { 2816 void HCheckFunction::Verify() {
2808 HInstruction::Verify(); 2817 HInstruction::Verify();
2809 ASSERT(HasNoUses()); 2818 ASSERT(HasNoUses());
2810 } 2819 }
2811 2820
2812 #endif 2821 #endif
2813 2822
2814 } } // namespace v8::internal 2823 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698