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

Side by Side Diff: src/hydrogen.cc

Issue 258243004: Harden some INLINE_OPTIMIZED runtime bultins. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 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.h ('k') | src/objects.h » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 8621 matching lines...) Expand 10 before | Expand all | Expand 10 after
8632 8632
8633 CHECK_ALIVE(VisitForValue(arguments->at(1))); 8633 CHECK_ALIVE(VisitForValue(arguments->at(1)));
8634 HValue* buffer = Pop(); 8634 HValue* buffer = Pop();
8635 8635
8636 CHECK_ALIVE(VisitForValue(arguments->at(2))); 8636 CHECK_ALIVE(VisitForValue(arguments->at(2)));
8637 HValue* byte_offset = Pop(); 8637 HValue* byte_offset = Pop();
8638 8638
8639 CHECK_ALIVE(VisitForValue(arguments->at(3))); 8639 CHECK_ALIVE(VisitForValue(arguments->at(3)));
8640 HValue* byte_length = Pop(); 8640 HValue* byte_length = Pop();
8641 8641
8642 IfBuilder checker(this);
8643 checker.If<HHasInstanceTypeAndBranch>(obj, JS_DATA_VIEW_TYPE);
8644 checker.AndIf<HHasInstanceTypeAndBranch>(buffer, JS_ARRAY_BUFFER_TYPE);
8645 checker.AndIf<HIsSmiAndBranch>(byte_offset);
8646 checker.AndIf<HIsSmiAndBranch>(byte_length);
8647 checker.And();
8648 HValue* zero = graph()->GetConstant0();
8649 HValue* buffer_length =
8650 Add<HLoadNamedField>(buffer,
8651 static_cast<HValue*>(NULL),
8652 HObjectAccess::ForJSArrayBufferByteLength());
8653 checker.If<HIsSmiAndBranch>(buffer_length);
8654 checker.And();
8655 HValue* smi_byte_offset =
8656 AddUncasted<HForceRepresentation>(byte_offset, Representation::Smi());
8657 HValue* smi_byte_length =
8658 AddUncasted<HForceRepresentation>(byte_length, Representation::Smi());
8659 HValue* smi_buffer_length =
8660 AddUncasted<HForceRepresentation>(buffer_length, Representation::Smi());
8661 checker.If<HCompareNumericAndBranch>(smi_byte_offset, zero, Token::GTE);
8662 checker.And();
8663 checker.If<HCompareNumericAndBranch>(
8664 smi_byte_length, zero, Token::GTE);
8665 checker.And();
8666 checker.If<HCompareNumericAndBranch>(
8667 smi_byte_offset, smi_buffer_length, Token::LTE);
8668 checker.And();
8669 HValue* view_length = AddUncasted<HAdd>(byte_offset, byte_length);
8670 checker.If<HCompareNumericAndBranch>(
8671 view_length, smi_buffer_length, Token::LTE);
8672
8673 checker.Then();
8642 BuildArrayBufferViewInitialization<JSDataView>( 8674 BuildArrayBufferViewInitialization<JSDataView>(
8643 obj, buffer, byte_offset, byte_length); 8675 obj, buffer, byte_offset, byte_length);
8676
8677 checker.Else();
8678 Push(obj);
8679 Push(buffer);
8680 Push(byte_offset);
8681 Push(byte_length);
8682 PushArgumentsFromEnvironment(4);
8683 Add<HCallRuntime>(expr->name(), expr->function(), 4);
8684 checker.End();
8644 } 8685 }
8645 8686
8646 8687
8647 static Handle<Map> TypedArrayMap(Isolate* isolate, 8688 static Handle<Map> TypedArrayMap(Isolate* isolate,
8648 ExternalArrayType array_type, 8689 ExternalArrayType array_type,
8649 ElementsKind target_kind) { 8690 ElementsKind target_kind) {
8650 Handle<Context> native_context = isolate->native_context(); 8691 Handle<Context> native_context = isolate->native_context();
8651 Handle<JSFunction> fun; 8692 Handle<JSFunction> fun;
8652 switch (array_type) { 8693 switch (array_type) {
8653 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ 8694 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
8654 case kExternal##Type##Array: \ 8695 case kExternal##Type##Array: \
8655 fun = Handle<JSFunction>(native_context->type##_array_fun()); \ 8696 fun = Handle<JSFunction>(native_context->type##_array_fun()); \
8656 break; 8697 break;
8657 8698
8658 TYPED_ARRAYS(TYPED_ARRAY_CASE) 8699 TYPED_ARRAYS(TYPED_ARRAY_CASE)
8659 #undef TYPED_ARRAY_CASE 8700 #undef TYPED_ARRAY_CASE
8660 } 8701 }
8661 Handle<Map> map(fun->initial_map()); 8702 Handle<Map> map(fun->initial_map());
8662 return Map::AsElementsKind(map, target_kind); 8703 return Map::AsElementsKind(map, target_kind);
8663 } 8704 }
8664 8705
8665
8666 HValue* HOptimizedGraphBuilder::BuildAllocateExternalElements( 8706 HValue* HOptimizedGraphBuilder::BuildAllocateExternalElements(
8667 ExternalArrayType array_type, 8707 ExternalArrayType array_type,
8668 bool is_zero_byte_offset, 8708 bool is_zero_byte_offset,
8669 HValue* buffer, HValue* byte_offset, HValue* length) { 8709 HValue* buffer, HValue* byte_offset, HValue* length) {
8670 Handle<Map> external_array_map( 8710 Handle<Map> external_array_map(
8671 isolate()->heap()->MapForExternalArrayType(array_type)); 8711 isolate()->heap()->MapForExternalArrayType(array_type));
8672 8712
8673 // The HForceRepresentation is to prevent possible deopt on int-smi 8713 // The HForceRepresentation is to prevent possible deopt on int-smi
8674 // conversion after allocation but before the new object fields are set. 8714 // conversion after allocation but before the new object fields are set.
8675 length = AddUncasted<HForceRepresentation>(length, Representation::Smi()); 8715 length = AddUncasted<HForceRepresentation>(length, Representation::Smi());
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
8882 8922
8883 void HOptimizedGraphBuilder::GenerateTypedArrayMaxSizeInHeap( 8923 void HOptimizedGraphBuilder::GenerateTypedArrayMaxSizeInHeap(
8884 CallRuntime* expr) { 8924 CallRuntime* expr) {
8885 ASSERT(expr->arguments()->length() == 0); 8925 ASSERT(expr->arguments()->length() == 0);
8886 HConstant* result = New<HConstant>(static_cast<int32_t>( 8926 HConstant* result = New<HConstant>(static_cast<int32_t>(
8887 FLAG_typed_array_max_size_in_heap)); 8927 FLAG_typed_array_max_size_in_heap));
8888 return ast_context()->ReturnInstruction(result, expr->id()); 8928 return ast_context()->ReturnInstruction(result, expr->id());
8889 } 8929 }
8890 8930
8891 8931
8932 void HOptimizedGraphBuilder::GenerateSimpleGetter(
8933 CallRuntime* expr,
8934 InstanceType instance_type,
8935 HObjectAccess object_access) {
8936 NoObservableSideEffectsScope scope(this);
8937 ASSERT(expr->arguments()->length() == 1);
8938 CHECK_ALIVE(VisitForValue(expr->arguments()->at(0)));
8939 HValue* buffer = Pop();
8940 IfBuilder check_instance_type(this);
8941 check_instance_type.If<HHasInstanceTypeAndBranch>(
8942 buffer,
8943 instance_type);
8944 check_instance_type.Then();
8945 HInstruction* result = Add<HLoadNamedField>(
8946 buffer,
8947 static_cast<HValue*>(NULL),
8948 object_access);
8949 Push(result);
8950
8951 check_instance_type.Else();
8952 Push(buffer);
8953 PushArgumentsFromEnvironment(1);
8954 Push(Add<HCallRuntime>(expr->name(), expr->function(), 1));
8955 check_instance_type.End();
8956 return ast_context()->ReturnValue(Pop());
8957 }
8958
8959
8892 void HOptimizedGraphBuilder::GenerateArrayBufferGetByteLength( 8960 void HOptimizedGraphBuilder::GenerateArrayBufferGetByteLength(
8893 CallRuntime* expr) { 8961 CallRuntime* expr) {
8894 ASSERT(expr->arguments()->length() == 1); 8962 GenerateSimpleGetter(
8895 CHECK_ALIVE(VisitForValue(expr->arguments()->at(0))); 8963 expr,
8896 HValue* buffer = Pop(); 8964 JS_ARRAY_BUFFER_TYPE,
8897 HInstruction* result = New<HLoadNamedField>( 8965 HObjectAccess::ForJSArrayBufferByteLength());
8898 buffer,
8899 static_cast<HValue*>(NULL),
8900 HObjectAccess::ForJSArrayBufferByteLength());
8901 return ast_context()->ReturnInstruction(result, expr->id());
8902 } 8966 }
8903 8967
8904 8968
8905 void HOptimizedGraphBuilder::GenerateArrayBufferViewGetByteLength( 8969 void HOptimizedGraphBuilder::GenerateTypedArrayGetByteLength(
8906 CallRuntime* expr) { 8970 CallRuntime* expr) {
8907 ASSERT(expr->arguments()->length() == 1); 8971 GenerateSimpleGetter(
8908 CHECK_ALIVE(VisitForValue(expr->arguments()->at(0))); 8972 expr,
8909 HValue* buffer = Pop(); 8973 JS_TYPED_ARRAY_TYPE,
8910 HInstruction* result = New<HLoadNamedField>( 8974 HObjectAccess::ForJSArrayBufferViewByteLength());
8911 buffer,
8912 static_cast<HValue*>(NULL),
8913 HObjectAccess::ForJSArrayBufferViewByteLength());
8914 return ast_context()->ReturnInstruction(result, expr->id());
8915 } 8975 }
8916 8976
8917 8977
8918 void HOptimizedGraphBuilder::GenerateArrayBufferViewGetByteOffset( 8978 void HOptimizedGraphBuilder::GenerateTypedArrayGetByteOffset(
8919 CallRuntime* expr) { 8979 CallRuntime* expr) {
8920 ASSERT(expr->arguments()->length() == 1); 8980 GenerateSimpleGetter(
8921 CHECK_ALIVE(VisitForValue(expr->arguments()->at(0))); 8981 expr,
8922 HValue* buffer = Pop(); 8982 JS_TYPED_ARRAY_TYPE,
8923 HInstruction* result = New<HLoadNamedField>( 8983 HObjectAccess::ForJSArrayBufferViewByteOffset());
8924 buffer, 8984 }
8925 static_cast<HValue*>(NULL), 8985
8926 HObjectAccess::ForJSArrayBufferViewByteOffset()); 8986
8927 return ast_context()->ReturnInstruction(result, expr->id()); 8987 void HOptimizedGraphBuilder::GenerateDataViewGetByteLength(
8988 CallRuntime* expr) {
8989 GenerateSimpleGetter(
8990 expr,
8991 JS_DATA_VIEW_TYPE,
8992 HObjectAccess::ForJSArrayBufferViewByteLength());
8993 }
8994
8995
8996 void HOptimizedGraphBuilder::GenerateDataViewGetByteOffset(
8997 CallRuntime* expr) {
8998 GenerateSimpleGetter(
8999 expr,
9000 JS_DATA_VIEW_TYPE,
9001 HObjectAccess::ForJSArrayBufferViewByteOffset());
8928 } 9002 }
8929 9003
8930 9004
8931 void HOptimizedGraphBuilder::GenerateTypedArrayGetLength( 9005 void HOptimizedGraphBuilder::GenerateTypedArrayGetLength(
8932 CallRuntime* expr) { 9006 CallRuntime* expr) {
8933 ASSERT(expr->arguments()->length() == 1); 9007 GenerateSimpleGetter(
8934 CHECK_ALIVE(VisitForValue(expr->arguments()->at(0))); 9008 expr,
8935 HValue* buffer = Pop(); 9009 JS_TYPED_ARRAY_TYPE,
8936 HInstruction* result = New<HLoadNamedField>( 9010 HObjectAccess::ForJSTypedArrayLength());
8937 buffer,
8938 static_cast<HValue*>(NULL),
8939 HObjectAccess::ForJSTypedArrayLength());
8940 return ast_context()->ReturnInstruction(result, expr->id());
8941 } 9011 }
8942 9012
8943 9013
8944 void HOptimizedGraphBuilder::VisitCallRuntime(CallRuntime* expr) { 9014 void HOptimizedGraphBuilder::VisitCallRuntime(CallRuntime* expr) {
8945 ASSERT(!HasStackOverflow()); 9015 ASSERT(!HasStackOverflow());
8946 ASSERT(current_block() != NULL); 9016 ASSERT(current_block() != NULL);
8947 ASSERT(current_block()->HasPredecessor()); 9017 ASSERT(current_block()->HasPredecessor());
8948 if (expr->is_jsruntime()) { 9018 if (expr->is_jsruntime()) {
8949 return Bailout(kCallToAJavaScriptRuntimeFunction); 9019 return Bailout(kCallToAJavaScriptRuntimeFunction);
8950 } 9020 }
(...skipping 2738 matching lines...) Expand 10 before | Expand all | Expand 10 after
11689 if (ShouldProduceTraceOutput()) { 11759 if (ShouldProduceTraceOutput()) {
11690 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 11760 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
11691 } 11761 }
11692 11762
11693 #ifdef DEBUG 11763 #ifdef DEBUG
11694 graph_->Verify(false); // No full verify. 11764 graph_->Verify(false); // No full verify.
11695 #endif 11765 #endif
11696 } 11766 }
11697 11767
11698 } } // namespace v8::internal 11768 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698