OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/bootstrapper.h" |
5 #include "src/code-stubs.h" | 6 #include "src/code-stubs.h" |
| 7 #include "src/compiler/common-operator.h" |
6 #include "src/compiler/graph.h" | 8 #include "src/compiler/graph.h" |
7 #include "src/compiler/linkage.h" | 9 #include "src/compiler/linkage.h" |
8 #include "src/compiler/pipeline.h" | 10 #include "src/compiler/pipeline.h" |
9 #include "src/compiler/raw-machine-assembler.h" | 11 #include "src/parser.h" |
10 #include "src/globals.h" | |
11 #include "src/handles.h" | |
12 #include "test/cctest/compiler/function-tester.h" | 12 #include "test/cctest/compiler/function-tester.h" |
13 | 13 |
14 #if V8_TURBOFAN_TARGET | 14 #if V8_TURBOFAN_TARGET |
15 | 15 |
16 using namespace v8::internal; | 16 using namespace v8::internal; |
17 using namespace v8::internal::compiler; | 17 using namespace v8::internal::compiler; |
18 | 18 |
19 | 19 |
| 20 static Handle<JSFunction> GetFunction(Isolate* isolate, const char* name) { |
| 21 v8::ExtensionConfiguration no_extensions; |
| 22 Handle<Context> ctx = isolate->bootstrapper()->CreateEnvironment( |
| 23 MaybeHandle<JSGlobalProxy>(), v8::Handle<v8::ObjectTemplate>(), |
| 24 &no_extensions); |
| 25 Handle<JSBuiltinsObject> builtins = handle(ctx->builtins()); |
| 26 MaybeHandle<Object> fun = Object::GetProperty(isolate, builtins, name); |
| 27 Handle<JSFunction> function = Handle<JSFunction>::cast(fun.ToHandleChecked()); |
| 28 // Just to make sure nobody calls this... |
| 29 function->set_code(isolate->builtins()->builtin(Builtins::kIllegal)); |
| 30 return function; |
| 31 } |
| 32 |
| 33 |
20 class StringLengthStubTF : public CodeStub { | 34 class StringLengthStubTF : public CodeStub { |
21 public: | 35 public: |
22 explicit StringLengthStubTF(Isolate* isolate) : CodeStub(isolate) {} | 36 explicit StringLengthStubTF(Isolate* isolate) : CodeStub(isolate) {} |
23 | 37 |
24 StringLengthStubTF(uint32_t key, Isolate* isolate) : CodeStub(key, isolate) {} | 38 StringLengthStubTF(uint32_t key, Isolate* isolate) : CodeStub(key, isolate) {} |
25 | 39 |
26 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE { | 40 CallInterfaceDescriptor GetCallInterfaceDescriptor() OVERRIDE { |
27 return LoadDescriptor(isolate()); | 41 return LoadDescriptor(isolate()); |
28 }; | 42 }; |
29 | 43 |
30 Handle<Code> GenerateCode() OVERRIDE { | 44 Handle<Code> GenerateCode() OVERRIDE { |
31 CompilationInfoWithZone info(this, isolate()); | 45 // Build a "hybrid" CompilationInfo for a JSFunction/CodeStub pair. |
32 Graph graph(info.zone()); | 46 CompilationInfoWithZone info(GetFunction(isolate(), "STRING_LENGTH_STUB")); |
33 CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info); | 47 info.SetStub(this); |
34 RawMachineAssembler m(isolate(), &graph, descriptor->GetMachineSignature()); | 48 // Run a "mini pipeline", extracted from compiler.cc. |
35 | 49 CHECK(Parser::ParseStatic(info.parse_info())); |
36 Node* str = m.Load(kMachAnyTagged, m.Parameter(0), | 50 CHECK(Compiler::Analyze(info.parse_info())); |
37 m.Int32Constant(JSValue::kValueOffset - kHeapObjectTag)); | 51 return Pipeline(&info).GenerateCode(); |
38 Node* len = m.Load(kMachAnyTagged, str, | |
39 m.Int32Constant(String::kLengthOffset - kHeapObjectTag)); | |
40 m.Return(len); | |
41 | |
42 return Pipeline::GenerateCodeForTesting(&info, &graph, m.Export()); | |
43 } | 52 } |
44 | 53 |
45 Major MajorKey() const OVERRIDE { return StringLength; }; | 54 Major MajorKey() const OVERRIDE { return StringLength; }; |
46 Code::Kind GetCodeKind() const OVERRIDE { return Code::HANDLER; } | 55 Code::Kind GetCodeKind() const OVERRIDE { return Code::HANDLER; } |
47 InlineCacheState GetICState() const OVERRIDE { return MONOMORPHIC; } | 56 InlineCacheState GetICState() const OVERRIDE { return MONOMORPHIC; } |
48 ExtraICState GetExtraICState() const OVERRIDE { return Code::LOAD_IC; } | 57 ExtraICState GetExtraICState() const OVERRIDE { return Code::LOAD_IC; } |
49 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; } | 58 Code::StubType GetStubType() const OVERRIDE { return Code::FAST; } |
50 | 59 |
51 private: | 60 private: |
52 DISALLOW_COPY_AND_ASSIGN(StringLengthStubTF); | 61 DISALLOW_COPY_AND_ASSIGN(StringLengthStubTF); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // Actuall call through to the stub, verifying its result. | 95 // Actuall call through to the stub, verifying its result. |
87 const char* testString = "Und das Lamm schrie HURZ!"; | 96 const char* testString = "Und das Lamm schrie HURZ!"; |
88 Handle<JSReceiver> receiverArg = | 97 Handle<JSReceiver> receiverArg = |
89 Object::ToObject(isolate, ft.Val(testString)).ToHandleChecked(); | 98 Object::ToObject(isolate, ft.Val(testString)).ToHandleChecked(); |
90 Handle<String> nameArg = ft.Val("length"); | 99 Handle<String> nameArg = ft.Val("length"); |
91 Handle<Object> result = ft.Call(receiverArg, nameArg).ToHandleChecked(); | 100 Handle<Object> result = ft.Call(receiverArg, nameArg).ToHandleChecked(); |
92 CHECK_EQ(static_cast<int>(strlen(testString)), Smi::cast(*result)->value()); | 101 CHECK_EQ(static_cast<int>(strlen(testString)), Smi::cast(*result)->value()); |
93 } | 102 } |
94 | 103 |
95 #endif // V8_TURBOFAN_TARGET | 104 #endif // V8_TURBOFAN_TARGET |
OLD | NEW |