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

Side by Side Diff: src/ic/x64/ic-x64.cc

Issue 1168093002: [strong] Implement strong mode restrictions on property access (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix arm64 port Created 5 years, 6 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #if V8_TARGET_ARCH_X64 7 #if V8_TARGET_ARCH_X64
8 8
9 #include "src/codegen.h" 9 #include "src/codegen.h"
10 #include "src/ic/ic.h" 10 #include "src/ic/ic.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 FieldOperand(map, Map::kBitFieldOffset), 164 FieldOperand(map, Map::kBitFieldOffset),
165 Immediate((1 << Map::kIsAccessCheckNeeded) | (1 << interceptor_bit))); 165 Immediate((1 << Map::kIsAccessCheckNeeded) | (1 << interceptor_bit)));
166 __ j(not_zero, slow); 166 __ j(not_zero, slow);
167 } 167 }
168 168
169 169
170 // Loads an indexed element from a fast case array. 170 // Loads an indexed element from a fast case array.
171 static void GenerateFastArrayLoad(MacroAssembler* masm, Register receiver, 171 static void GenerateFastArrayLoad(MacroAssembler* masm, Register receiver,
172 Register key, Register elements, 172 Register key, Register elements,
173 Register scratch, Register result, 173 Register scratch, Register result,
174 Label* slow) { 174 Label* slow, Strength strength) {
175 // Register use: 175 // Register use:
176 // 176 //
177 // receiver - holds the receiver on entry. 177 // receiver - holds the receiver on entry.
178 // Unchanged unless 'result' is the same register. 178 // Unchanged unless 'result' is the same register.
179 // 179 //
180 // key - holds the smi key on entry. 180 // key - holds the smi key on entry.
181 // Unchanged unless 'result' is the same register. 181 // Unchanged unless 'result' is the same register.
182 // 182 //
183 // result - holds the result on exit if the load succeeded. 183 // result - holds the result on exit if the load succeeded.
184 // Allowed to be the the same as 'receiver' or 'key'. 184 // Allowed to be the the same as 'receiver' or 'key'.
185 // Unchanged on bailout so 'receiver' and 'key' can be safely 185 // Unchanged on bailout so 'receiver' and 'key' can be safely
186 // used by further computation. 186 // used by further computation.
187 // 187 //
188 // Scratch registers: 188 // Scratch registers:
189 // 189 //
190 // elements - holds the elements of the receiver and its prototypes. 190 // elements - holds the elements of the receiver and its prototypes.
191 // 191 //
192 // scratch - used to hold maps, prototypes, and the loaded value. 192 // scratch - used to hold maps, prototypes, and the loaded value.
193 Label check_prototypes, check_next_prototype; 193 Label check_prototypes, check_next_prototype;
194 Label done, in_bounds, return_undefined; 194 Label done, in_bounds, return_absent;
195 195
196 __ movp(elements, FieldOperand(receiver, JSObject::kElementsOffset)); 196 __ movp(elements, FieldOperand(receiver, JSObject::kElementsOffset));
197 __ AssertFastElements(elements); 197 __ AssertFastElements(elements);
198 // Check that the key (index) is within bounds. 198 // Check that the key (index) is within bounds.
199 __ SmiCompare(key, FieldOperand(elements, FixedArray::kLengthOffset)); 199 __ SmiCompare(key, FieldOperand(elements, FixedArray::kLengthOffset));
200 // Unsigned comparison rejects negative indices. 200 // Unsigned comparison rejects negative indices.
201 __ j(below, &in_bounds); 201 __ j(below, &in_bounds);
202 202
203 // Out-of-bounds. Check the prototype chain to see if we can just return 203 // Out-of-bounds. Check the prototype chain to see if we can just return
204 // 'undefined'. 204 // 'undefined'.
205 __ SmiCompare(key, Smi::FromInt(0)); 205 __ SmiCompare(key, Smi::FromInt(0));
206 __ j(less, slow); // Negative keys can't take the fast OOB path. 206 __ j(less, slow); // Negative keys can't take the fast OOB path.
207 __ bind(&check_prototypes); 207 __ bind(&check_prototypes);
208 __ movp(scratch, FieldOperand(receiver, HeapObject::kMapOffset)); 208 __ movp(scratch, FieldOperand(receiver, HeapObject::kMapOffset));
209 __ bind(&check_next_prototype); 209 __ bind(&check_next_prototype);
210 __ movp(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); 210 __ movp(scratch, FieldOperand(scratch, Map::kPrototypeOffset));
211 // scratch: current prototype 211 // scratch: current prototype
212 __ CompareRoot(scratch, Heap::kNullValueRootIndex); 212 __ CompareRoot(scratch, Heap::kNullValueRootIndex);
213 __ j(equal, &return_undefined); 213 __ j(equal, &return_absent);
214 __ movp(elements, FieldOperand(scratch, JSObject::kElementsOffset)); 214 __ movp(elements, FieldOperand(scratch, JSObject::kElementsOffset));
215 __ movp(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); 215 __ movp(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
216 // elements: elements of current prototype 216 // elements: elements of current prototype
217 // scratch: map of current prototype 217 // scratch: map of current prototype
218 __ CmpInstanceType(scratch, JS_OBJECT_TYPE); 218 __ CmpInstanceType(scratch, JS_OBJECT_TYPE);
219 __ j(below, slow); 219 __ j(below, slow);
220 __ testb(FieldOperand(scratch, Map::kBitFieldOffset), 220 __ testb(FieldOperand(scratch, Map::kBitFieldOffset),
221 Immediate((1 << Map::kIsAccessCheckNeeded) | 221 Immediate((1 << Map::kIsAccessCheckNeeded) |
222 (1 << Map::kHasIndexedInterceptor))); 222 (1 << Map::kHasIndexedInterceptor)));
223 __ j(not_zero, slow); 223 __ j(not_zero, slow);
224 __ CompareRoot(elements, Heap::kEmptyFixedArrayRootIndex); 224 __ CompareRoot(elements, Heap::kEmptyFixedArrayRootIndex);
225 __ j(not_equal, slow); 225 __ j(not_equal, slow);
226 __ jmp(&check_next_prototype); 226 __ jmp(&check_next_prototype);
227 227
228 __ bind(&return_undefined); 228 __ bind(&return_absent);
229 __ LoadRoot(result, Heap::kUndefinedValueRootIndex); 229 if (is_strong(strength)) {
230 __ jmp(&done); 230 // Strong mode accesses must throw in this case, so call the runtime.
231 __ jmp(slow);
232 } else {
233 __ LoadRoot(result, Heap::kUndefinedValueRootIndex);
234 __ jmp(&done);
235 }
231 236
232 __ bind(&in_bounds); 237 __ bind(&in_bounds);
233 // Fast case: Do the load. 238 // Fast case: Do the load.
234 SmiIndex index = masm->SmiToIndex(scratch, key, kPointerSizeLog2); 239 SmiIndex index = masm->SmiToIndex(scratch, key, kPointerSizeLog2);
235 __ movp(scratch, FieldOperand(elements, index.reg, index.scale, 240 __ movp(scratch, FieldOperand(elements, index.reg, index.scale,
236 FixedArray::kHeaderSize)); 241 FixedArray::kHeaderSize));
237 __ CompareRoot(scratch, Heap::kTheHoleValueRootIndex); 242 __ CompareRoot(scratch, Heap::kTheHoleValueRootIndex);
238 // In case the loaded value is the_hole we have to check the prototype chain. 243 // In case the loaded value is the_hole we have to check the prototype chain.
239 __ j(equal, &check_prototypes); 244 __ j(equal, &check_prototypes);
240 __ Move(result, scratch); 245 __ Move(result, scratch);
(...skipping 26 matching lines...) Expand all
267 // bit test is enough. 272 // bit test is enough.
268 STATIC_ASSERT(kNotInternalizedTag != 0); 273 STATIC_ASSERT(kNotInternalizedTag != 0);
269 __ testb(FieldOperand(map, Map::kInstanceTypeOffset), 274 __ testb(FieldOperand(map, Map::kInstanceTypeOffset),
270 Immediate(kIsNotInternalizedMask)); 275 Immediate(kIsNotInternalizedMask));
271 __ j(not_zero, not_unique); 276 __ j(not_zero, not_unique);
272 277
273 __ bind(&unique); 278 __ bind(&unique);
274 } 279 }
275 280
276 281
277 void KeyedLoadIC::GenerateMegamorphic(MacroAssembler* masm) { 282 void KeyedLoadIC::GenerateMegamorphic(MacroAssembler* masm, Strength strength) {
278 // The return address is on the stack. 283 // The return address is on the stack.
279 Label slow, check_name, index_smi, index_name, property_array_property; 284 Label slow, check_name, index_smi, index_name, property_array_property;
280 Label probe_dictionary, check_number_dictionary; 285 Label probe_dictionary, check_number_dictionary;
281 286
282 Register receiver = LoadDescriptor::ReceiverRegister(); 287 Register receiver = LoadDescriptor::ReceiverRegister();
283 Register key = LoadDescriptor::NameRegister(); 288 Register key = LoadDescriptor::NameRegister();
284 DCHECK(receiver.is(rdx)); 289 DCHECK(receiver.is(rdx));
285 DCHECK(key.is(rcx)); 290 DCHECK(key.is(rcx));
286 291
287 // Check that the key is a smi. 292 // Check that the key is a smi.
288 __ JumpIfNotSmi(key, &check_name); 293 __ JumpIfNotSmi(key, &check_name);
289 __ bind(&index_smi); 294 __ bind(&index_smi);
290 // Now the key is known to be a smi. This place is also jumped to from below 295 // Now the key is known to be a smi. This place is also jumped to from below
291 // where a numeric string is converted to a smi. 296 // where a numeric string is converted to a smi.
292 297
293 GenerateKeyedLoadReceiverCheck(masm, receiver, rax, 298 GenerateKeyedLoadReceiverCheck(masm, receiver, rax,
294 Map::kHasIndexedInterceptor, &slow); 299 Map::kHasIndexedInterceptor, &slow);
295 300
296 // Check the receiver's map to see if it has fast elements. 301 // Check the receiver's map to see if it has fast elements.
297 __ CheckFastElements(rax, &check_number_dictionary); 302 __ CheckFastElements(rax, &check_number_dictionary);
298 303
299 GenerateFastArrayLoad(masm, receiver, key, rax, rbx, rax, &slow); 304 GenerateFastArrayLoad(masm, receiver, key, rax, rbx, rax, &slow, strength);
300 Counters* counters = masm->isolate()->counters(); 305 Counters* counters = masm->isolate()->counters();
301 __ IncrementCounter(counters->keyed_load_generic_smi(), 1); 306 __ IncrementCounter(counters->keyed_load_generic_smi(), 1);
302 __ ret(0); 307 __ ret(0);
303 308
304 __ bind(&check_number_dictionary); 309 __ bind(&check_number_dictionary);
305 __ SmiToInteger32(rbx, key); 310 __ SmiToInteger32(rbx, key);
306 __ movp(rax, FieldOperand(receiver, JSObject::kElementsOffset)); 311 __ movp(rax, FieldOperand(receiver, JSObject::kElementsOffset));
307 312
308 // Check whether the elements is a number dictionary. 313 // Check whether the elements is a number dictionary.
309 // rbx: key as untagged int32 314 // rbx: key as untagged int32
310 // rax: elements 315 // rax: elements
311 __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset), 316 __ CompareRoot(FieldOperand(rax, HeapObject::kMapOffset),
312 Heap::kHashTableMapRootIndex); 317 Heap::kHashTableMapRootIndex);
313 __ j(not_equal, &slow); 318 __ j(not_equal, &slow);
314 __ LoadFromNumberDictionary(&slow, rax, key, rbx, r9, rdi, rax); 319 __ LoadFromNumberDictionary(&slow, rax, key, rbx, r9, rdi, rax);
315 __ ret(0); 320 __ ret(0);
316 321
317 __ bind(&slow); 322 __ bind(&slow);
318 // Slow case: Jump to runtime. 323 // Slow case: Jump to runtime.
319 __ IncrementCounter(counters->keyed_load_generic_slow(), 1); 324 __ IncrementCounter(counters->keyed_load_generic_slow(), 1);
320 GenerateRuntimeGetProperty(masm); 325 GenerateSlow(masm);
321 326
322 __ bind(&check_name); 327 __ bind(&check_name);
323 GenerateKeyNameCheck(masm, key, rax, rbx, &index_name, &slow); 328 GenerateKeyNameCheck(masm, key, rax, rbx, &index_name, &slow);
324 329
325 GenerateKeyedLoadReceiverCheck(masm, receiver, rax, Map::kHasNamedInterceptor, 330 GenerateKeyedLoadReceiverCheck(masm, receiver, rax, Map::kHasNamedInterceptor,
326 &slow); 331 &slow);
327 332
328 // If the receiver is a fast-case object, check the stub cache. Otherwise 333 // If the receiver is a fast-case object, check the stub cache. Otherwise
329 // probe the dictionary. 334 // probe the dictionary.
330 __ movp(rbx, FieldOperand(receiver, JSObject::kPropertiesOffset)); 335 __ movp(rbx, FieldOperand(receiver, JSObject::kPropertiesOffset));
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 Label slow; 621 Label slow;
617 622
618 __ movp(dictionary, FieldOperand(LoadDescriptor::ReceiverRegister(), 623 __ movp(dictionary, FieldOperand(LoadDescriptor::ReceiverRegister(),
619 JSObject::kPropertiesOffset)); 624 JSObject::kPropertiesOffset));
620 GenerateDictionaryLoad(masm, &slow, dictionary, 625 GenerateDictionaryLoad(masm, &slow, dictionary,
621 LoadDescriptor::NameRegister(), rbx, rdi, rax); 626 LoadDescriptor::NameRegister(), rbx, rdi, rax);
622 __ ret(0); 627 __ ret(0);
623 628
624 // Dictionary load failed, go slow (but don't miss). 629 // Dictionary load failed, go slow (but don't miss).
625 __ bind(&slow); 630 __ bind(&slow);
626 GenerateRuntimeGetProperty(masm); 631 GenerateSlow(masm);
627 } 632 }
628 633
629 634
630 static void LoadIC_PushArgs(MacroAssembler* masm) { 635 static void LoadIC_PushArgs(MacroAssembler* masm) {
631 Register receiver = LoadDescriptor::ReceiverRegister(); 636 Register receiver = LoadDescriptor::ReceiverRegister();
632 Register name = LoadDescriptor::NameRegister(); 637 Register name = LoadDescriptor::NameRegister();
633 Register slot = LoadDescriptor::SlotRegister(); 638 Register slot = LoadDescriptor::SlotRegister();
634 Register vector = LoadWithVectorDescriptor::VectorRegister(); 639 Register vector = LoadWithVectorDescriptor::VectorRegister();
635 DCHECK(!rdi.is(receiver) && !rdi.is(name) && !rdi.is(slot) && 640 DCHECK(!rdi.is(receiver) && !rdi.is(name) && !rdi.is(slot) &&
636 !rdi.is(vector)); 641 !rdi.is(vector));
(...skipping 16 matching lines...) Expand all
653 LoadIC_PushArgs(masm); 658 LoadIC_PushArgs(masm);
654 659
655 // Perform tail call to the entry. 660 // Perform tail call to the entry.
656 ExternalReference ref = 661 ExternalReference ref =
657 ExternalReference(IC_Utility(kLoadIC_Miss), masm->isolate()); 662 ExternalReference(IC_Utility(kLoadIC_Miss), masm->isolate());
658 int arg_count = 4; 663 int arg_count = 4;
659 __ TailCallExternalReference(ref, arg_count, 1); 664 __ TailCallExternalReference(ref, arg_count, 1);
660 } 665 }
661 666
662 667
663 void LoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { 668 void LoadIC::GenerateSlow(MacroAssembler* masm) {
664 // The return address is on the stack. 669 // The return address is on the stack.
665 Register receiver = LoadDescriptor::ReceiverRegister(); 670 Register receiver = LoadDescriptor::ReceiverRegister();
666 Register name = LoadDescriptor::NameRegister(); 671 Register name = LoadDescriptor::NameRegister();
667 DCHECK(!rbx.is(receiver) && !rbx.is(name)); 672 DCHECK(!rbx.is(receiver) && !rbx.is(name));
668 673
669 __ PopReturnAddressTo(rbx); 674 __ PopReturnAddressTo(rbx);
670 __ Push(receiver); 675 __ Push(receiver);
671 __ Push(name); 676 __ Push(name);
672 __ PushReturnAddressFrom(rbx); 677 __ PushReturnAddressFrom(rbx);
673 678
674 // Perform tail call to the entry. 679 // Perform tail call to the entry.
675 __ TailCallRuntime(Runtime::kGetProperty, 2, 1); 680 ExternalReference ref =
681 ExternalReference(IC_Utility(kLoadIC_Slow), masm->isolate());
682 int arg_count = 2;
683 __ TailCallExternalReference(ref, arg_count, 1);
676 } 684 }
677 685
678 686
679 void KeyedLoadIC::GenerateMiss(MacroAssembler* masm) { 687 void KeyedLoadIC::GenerateMiss(MacroAssembler* masm) {
680 // The return address is on the stack. 688 // The return address is on the stack.
681 Counters* counters = masm->isolate()->counters(); 689 Counters* counters = masm->isolate()->counters();
682 __ IncrementCounter(counters->keyed_load_miss(), 1); 690 __ IncrementCounter(counters->keyed_load_miss(), 1);
683 691
684 LoadIC_PushArgs(masm); 692 LoadIC_PushArgs(masm);
685 693
686 // Perform tail call to the entry. 694 // Perform tail call to the entry.
687 ExternalReference ref = 695 ExternalReference ref =
688 ExternalReference(IC_Utility(kKeyedLoadIC_Miss), masm->isolate()); 696 ExternalReference(IC_Utility(kKeyedLoadIC_Miss), masm->isolate());
689 int arg_count = 4; 697 int arg_count = 4;
690 __ TailCallExternalReference(ref, arg_count, 1); 698 __ TailCallExternalReference(ref, arg_count, 1);
691 } 699 }
692 700
693 701
694 void KeyedLoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { 702 void KeyedLoadIC::GenerateSlow(MacroAssembler* masm) {
695 // The return address is on the stack. 703 // The return address is on the stack.
696 Register receiver = LoadDescriptor::ReceiverRegister(); 704 Register receiver = LoadDescriptor::ReceiverRegister();
697 Register name = LoadDescriptor::NameRegister(); 705 Register name = LoadDescriptor::NameRegister();
698 DCHECK(!rbx.is(receiver) && !rbx.is(name)); 706 DCHECK(!rbx.is(receiver) && !rbx.is(name));
699 707
700 __ PopReturnAddressTo(rbx); 708 __ PopReturnAddressTo(rbx);
701 __ Push(receiver); 709 __ Push(receiver);
702 __ Push(name); 710 __ Push(name);
703 __ PushReturnAddressFrom(rbx); 711 __ PushReturnAddressFrom(rbx);
704 712
705 // Perform tail call to the entry. 713 // Perform tail call to the entry.
706 __ TailCallRuntime(Runtime::kKeyedGetProperty, 2, 1); 714 ExternalReference ref =
715 ExternalReference(IC_Utility(kKeyedLoadIC_Slow), masm->isolate());
716 int arg_count = 2;
717 __ TailCallExternalReference(ref, arg_count, 1);
707 } 718 }
708 719
709 720
710 void StoreIC::GenerateMegamorphic(MacroAssembler* masm) { 721 void StoreIC::GenerateMegamorphic(MacroAssembler* masm) {
711 // The return address is on the stack. 722 // The return address is on the stack.
712 723
713 // Get the receiver from the stack and probe the stub cache. 724 // Get the receiver from the stack and probe the stub cache.
714 Code::Flags flags = Code::RemoveTypeAndHolderFromFlags( 725 Code::Flags flags = Code::RemoveTypeAndHolderFromFlags(
715 Code::ComputeHandlerFlags(Code::STORE_IC)); 726 Code::ComputeHandlerFlags(Code::STORE_IC));
716 masm->isolate()->stub_cache()->GenerateProbe( 727 masm->isolate()->stub_cache()->GenerateProbe(
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 Condition cc = 857 Condition cc =
847 (check == ENABLE_INLINED_SMI_CHECK) 858 (check == ENABLE_INLINED_SMI_CHECK)
848 ? (*jmp_address == Assembler::kJncShortOpcode ? not_zero : zero) 859 ? (*jmp_address == Assembler::kJncShortOpcode ? not_zero : zero)
849 : (*jmp_address == Assembler::kJnzShortOpcode ? not_carry : carry); 860 : (*jmp_address == Assembler::kJnzShortOpcode ? not_carry : carry);
850 *jmp_address = static_cast<byte>(Assembler::kJccShortPrefix | cc); 861 *jmp_address = static_cast<byte>(Assembler::kJccShortPrefix | cc);
851 } 862 }
852 } // namespace internal 863 } // namespace internal
853 } // namespace v8 864 } // namespace v8
854 865
855 #endif // V8_TARGET_ARCH_X64 866 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698