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

Side by Side Diff: src/runtime/runtime-compiler.cc

Issue 1764963002: [compiler] Reduce number of entry points into compiler API. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comment. Created 4 years, 9 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
« no previous file with comments | « src/compiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/compiler.h" 8 #include "src/compiler.h"
9 #include "src/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/frames-inl.h" 10 #include "src/frames-inl.h"
11 #include "src/full-codegen/full-codegen.h" 11 #include "src/full-codegen/full-codegen.h"
12 #include "src/isolate-inl.h" 12 #include "src/isolate-inl.h"
13 #include "src/messages.h" 13 #include "src/messages.h"
14 #include "src/v8threads.h" 14 #include "src/v8threads.h"
15 #include "src/vm-state-inl.h" 15 #include "src/vm-state-inl.h"
16 16
17 namespace v8 { 17 namespace v8 {
18 namespace internal { 18 namespace internal {
19 19
20 RUNTIME_FUNCTION(Runtime_CompileLazy) { 20 RUNTIME_FUNCTION(Runtime_CompileLazy) {
21 HandleScope scope(isolate); 21 HandleScope scope(isolate);
22 DCHECK(args.length() == 1); 22 DCHECK(args.length() == 1);
23 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 23 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
24
24 #ifdef DEBUG 25 #ifdef DEBUG
25 if (FLAG_trace_lazy && !function->shared()->is_compiled()) { 26 if (FLAG_trace_lazy && !function->shared()->is_compiled()) {
26 PrintF("[unoptimized: "); 27 PrintF("[unoptimized: ");
27 function->PrintName(); 28 function->PrintName();
28 PrintF("]\n"); 29 PrintF("]\n");
29 } 30 }
30 #endif 31 #endif
32
31 StackLimitCheck check(isolate); 33 StackLimitCheck check(isolate);
32 if (check.JsHasOverflowed(1 * KB)) return isolate->StackOverflow(); 34 if (check.JsHasOverflowed(1 * KB)) return isolate->StackOverflow();
33 35 if (!Compiler::Compile(function, KEEP_EXCEPTION)) {
34 // Compile the target function. 36 return isolate->heap()->exception();
35 DCHECK(function->shared()->allows_lazy_compilation());
36
37 Handle<Code> code;
38 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, code,
39 Compiler::GetLazyCode(function));
40 DCHECK(code->IsJavaScriptCode());
41
42 function->ReplaceCode(*code);
43 return *code;
44 }
45
46
47 namespace {
48
49 Object* CompileOptimized(Isolate* isolate, Handle<JSFunction> function,
50 Compiler::ConcurrencyMode mode) {
51 StackLimitCheck check(isolate);
52 if (check.JsHasOverflowed(1 * KB)) return isolate->StackOverflow();
53
54 Handle<Code> code;
55 if (Compiler::GetOptimizedCode(function, mode).ToHandle(&code)) {
56 // Optimization succeeded, return optimized code.
57 function->ReplaceCode(*code);
58 } else {
59 // Optimization failed, get unoptimized code.
60 if (isolate->has_pending_exception()) { // Possible stack overflow.
61 return isolate->heap()->exception();
62 }
63 code = Handle<Code>(function->shared()->code(), isolate);
64 if (code->kind() != Code::FUNCTION &&
65 code->kind() != Code::OPTIMIZED_FUNCTION) {
66 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
67 isolate, code, Compiler::GetUnoptimizedCode(function));
68 }
69 function->ReplaceCode(*code);
70 } 37 }
71 38 DCHECK(function->is_compiled());
72 DCHECK(function->code()->kind() == Code::FUNCTION ||
73 function->code()->kind() == Code::OPTIMIZED_FUNCTION ||
74 (function->code()->is_interpreter_entry_trampoline() &&
75 function->shared()->HasBytecodeArray()) ||
76 function->IsInOptimizationQueue());
77 return function->code(); 39 return function->code();
78 } 40 }
79 41
80 } // namespace
81
82 42
83 RUNTIME_FUNCTION(Runtime_CompileOptimized_Concurrent) { 43 RUNTIME_FUNCTION(Runtime_CompileOptimized_Concurrent) {
84 HandleScope scope(isolate); 44 HandleScope scope(isolate);
85 DCHECK(args.length() == 1); 45 DCHECK(args.length() == 1);
86 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 46 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
87 return CompileOptimized(isolate, function, Compiler::CONCURRENT); 47 StackLimitCheck check(isolate);
48 if (check.JsHasOverflowed(1 * KB)) return isolate->StackOverflow();
49 if (!Compiler::CompileOptimized(function, Compiler::CONCURRENT)) {
50 return isolate->heap()->exception();
51 }
52 DCHECK(function->is_compiled());
53 return function->code();
88 } 54 }
89 55
90 56
91 RUNTIME_FUNCTION(Runtime_CompileOptimized_NotConcurrent) { 57 RUNTIME_FUNCTION(Runtime_CompileOptimized_NotConcurrent) {
92 HandleScope scope(isolate); 58 HandleScope scope(isolate);
93 DCHECK(args.length() == 1); 59 DCHECK(args.length() == 1);
94 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 60 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
95 return CompileOptimized(isolate, function, Compiler::NOT_CONCURRENT); 61 StackLimitCheck check(isolate);
62 if (check.JsHasOverflowed(1 * KB)) return isolate->StackOverflow();
63 if (!Compiler::CompileOptimized(function, Compiler::NOT_CONCURRENT)) {
64 return isolate->heap()->exception();
65 }
66 DCHECK(function->is_compiled());
67 return function->code();
96 } 68 }
97 69
98 70
99 RUNTIME_FUNCTION(Runtime_NotifyStubFailure) { 71 RUNTIME_FUNCTION(Runtime_NotifyStubFailure) {
100 HandleScope scope(isolate); 72 HandleScope scope(isolate);
101 DCHECK(args.length() == 0); 73 DCHECK(args.length() == 0);
102 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate); 74 Deoptimizer* deoptimizer = Deoptimizer::Grab(isolate);
103 DCHECK(AllowHeapAllocation::IsAllowed()); 75 DCHECK(AllowHeapAllocation::IsAllowed());
104 delete deoptimizer; 76 delete deoptimizer;
105 return isolate->heap()->undefined_value(); 77 return isolate->heap()->undefined_value();
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 DCHECK(is_valid_language_mode(args.smi_at(3))); 402 DCHECK(is_valid_language_mode(args.smi_at(3)));
431 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3)); 403 LanguageMode language_mode = static_cast<LanguageMode>(args.smi_at(3));
432 DCHECK(args[4]->IsSmi()); 404 DCHECK(args[4]->IsSmi());
433 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), 405 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(),
434 isolate); 406 isolate);
435 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, 407 return CompileGlobalEval(isolate, args.at<String>(1), outer_info,
436 language_mode, args.smi_at(4)); 408 language_mode, args.smi_at(4));
437 } 409 }
438 } // namespace internal 410 } // namespace internal
439 } // namespace v8 411 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698