OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 17 matching lines...) Expand all Loading... |
28 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "bootstrapper.h" | 30 #include "bootstrapper.h" |
31 #include "codegen-inl.h" | 31 #include "codegen-inl.h" |
32 #include "compilation-cache.h" | 32 #include "compilation-cache.h" |
33 #include "compiler.h" | 33 #include "compiler.h" |
34 #include "debug.h" | 34 #include "debug.h" |
35 #include "scopes.h" | 35 #include "scopes.h" |
36 #include "rewriter.h" | 36 #include "rewriter.h" |
37 #include "usage-analyzer.h" | 37 #include "usage-analyzer.h" |
| 38 #include "oprofile-agent.h" |
38 | 39 |
39 namespace v8 { namespace internal { | 40 namespace v8 { namespace internal { |
40 | 41 |
41 static Handle<Code> MakeCode(FunctionLiteral* literal, | 42 static Handle<Code> MakeCode(FunctionLiteral* literal, |
42 Handle<Script> script, | 43 Handle<Script> script, |
43 Handle<Context> context, | 44 Handle<Context> context, |
44 bool is_eval) { | 45 bool is_eval) { |
45 ASSERT(literal != NULL); | 46 ASSERT(literal != NULL); |
46 | 47 |
47 // Rewrite the AST by introducing .result assignments where needed. | 48 // Rewrite the AST by introducing .result assignments where needed. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 117 |
117 // Compile the code. | 118 // Compile the code. |
118 Handle<Code> code = MakeCode(lit, script, context, is_eval); | 119 Handle<Code> code = MakeCode(lit, script, context, is_eval); |
119 | 120 |
120 // Check for stack-overflow exceptions. | 121 // Check for stack-overflow exceptions. |
121 if (code.is_null()) { | 122 if (code.is_null()) { |
122 Top::StackOverflow(); | 123 Top::StackOverflow(); |
123 return Handle<JSFunction>::null(); | 124 return Handle<JSFunction>::null(); |
124 } | 125 } |
125 | 126 |
126 #ifdef ENABLE_LOGGING_AND_PROFILING | 127 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT |
127 // Log the code generation for the script. Check explicit whether logging is | 128 // Log the code generation for the script. Check explicit whether logging is |
128 // to avoid allocating when not required. | 129 // to avoid allocating when not required. |
129 if (Logger::is_enabled()) { | 130 if (Logger::is_enabled() || OProfileAgent::is_enabled()) { |
130 if (script->name()->IsString()) { | 131 if (script->name()->IsString()) { |
131 SmartPointer<char> data = | 132 SmartPointer<char> data = |
132 String::cast(script->name())->ToCString(DISALLOW_NULLS); | 133 String::cast(script->name())->ToCString(DISALLOW_NULLS); |
133 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, *data)); | 134 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, *data)); |
| 135 OProfileAgent::CreateNativeCodeRegion(*data, code->address(), |
| 136 code->ExecutableSize()); |
134 } else { | 137 } else { |
135 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, "")); | 138 LOG(CodeCreateEvent(is_eval ? "Eval" : "Script", *code, "")); |
| 139 OProfileAgent::CreateNativeCodeRegion(is_eval ? "Eval" : "Script", |
| 140 code->address(), code->ExecutableSize()); |
136 } | 141 } |
137 } | 142 } |
138 #endif | 143 #endif |
139 | 144 |
140 // Allocate function. | 145 // Allocate function. |
141 Handle<JSFunction> fun = | 146 Handle<JSFunction> fun = |
142 Factory::NewFunctionBoilerplate(lit->name(), | 147 Factory::NewFunctionBoilerplate(lit->name(), |
143 lit->materialized_literal_count(), | 148 lit->materialized_literal_count(), |
144 lit->contains_array_literal(), | 149 lit->contains_array_literal(), |
145 code); | 150 code); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 304 |
300 // Compile the code. | 305 // Compile the code. |
301 Handle<Code> code = MakeCode(lit, script, Handle<Context>::null(), false); | 306 Handle<Code> code = MakeCode(lit, script, Handle<Context>::null(), false); |
302 | 307 |
303 // Check for stack-overflow exception. | 308 // Check for stack-overflow exception. |
304 if (code.is_null()) { | 309 if (code.is_null()) { |
305 Top::StackOverflow(); | 310 Top::StackOverflow(); |
306 return false; | 311 return false; |
307 } | 312 } |
308 | 313 |
309 #ifdef ENABLE_LOGGING_AND_PROFILING | 314 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT |
310 // Log the code generation. If source information is available include script | 315 // Log the code generation. If source information is available include script |
311 // name and line number. Check explicit whether logging is enabled as finding | 316 // name and line number. Check explicit whether logging is enabled as finding |
312 // the line number is not for free. | 317 // the line number is not for free. |
313 if (Logger::is_enabled()) { | 318 if (Logger::is_enabled() || OProfileAgent::is_enabled()) { |
314 if (script->name()->IsString()) { | 319 if (script->name()->IsString()) { |
315 int line_num = script->GetLineNumber(start_position); | 320 int line_num = script->GetLineNumber(start_position); |
316 if (line_num > 0) { | 321 if (line_num > 0) { |
317 line_num += script->line_offset()->value() + 1; | 322 line_num += script->line_offset()->value() + 1; |
318 } | 323 } |
319 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name(), | 324 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name(), |
320 String::cast(script->name()), line_num)); | 325 String::cast(script->name()), line_num)); |
| 326 OProfileAgent::CreateNativeCodeRegion(*lit->name(), |
| 327 String::cast(script->name()), |
| 328 line_num, code->address(), |
| 329 code->ExecutableSize()); |
321 } else { | 330 } else { |
322 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name())); | 331 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name())); |
| 332 OProfileAgent::CreateNativeCodeRegion(*lit->name(), code->address(), |
| 333 code->ExecutableSize()); |
323 } | 334 } |
324 } | 335 } |
325 #endif | 336 #endif |
326 | 337 |
327 // Update the shared function info with the compiled code. | 338 // Update the shared function info with the compiled code. |
328 shared->set_code(*code); | 339 shared->set_code(*code); |
329 | 340 |
330 // Set the expected number of properties for instances. | 341 // Set the expected number of properties for instances. |
331 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 342 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
332 | 343 |
333 // Check the function has compiled code. | 344 // Check the function has compiled code. |
334 ASSERT(shared->is_compiled()); | 345 ASSERT(shared->is_compiled()); |
335 return true; | 346 return true; |
336 } | 347 } |
337 | 348 |
338 | 349 |
339 } } // namespace v8::internal | 350 } } // namespace v8::internal |
OLD | NEW |