| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 208 } |
| 204 | 209 |
| 205 // Compile the function and add it to the cache. | 210 // Compile the function and add it to the cache. |
| 206 result = MakeFunction(true, | 211 result = MakeFunction(true, |
| 207 false, | 212 false, |
| 208 script, | 213 script, |
| 209 Handle<Context>::null(), | 214 Handle<Context>::null(), |
| 210 extension, | 215 extension, |
| 211 pre_data); | 216 pre_data); |
| 212 if (extension == NULL && !result.is_null()) { | 217 if (extension == NULL && !result.is_null()) { |
| 213 CompilationCache::PutFunction(source, CompilationCache::SCRIPT, result); | 218 CompilationCache::PutScript(source, CompilationCache::SCRIPT, result); |
| 214 } | 219 } |
| 215 | 220 |
| 216 // Get rid of the pre-parsing data (if necessary). | 221 // Get rid of the pre-parsing data (if necessary). |
| 217 if (input_pre_data == NULL && pre_data != NULL) { | 222 if (input_pre_data == NULL && pre_data != NULL) { |
| 218 delete pre_data; | 223 delete pre_data; |
| 219 } | 224 } |
| 220 } | 225 } |
| 221 | 226 |
| 222 if (result.is_null()) Top::ReportPendingMessages(); | 227 if (result.is_null()) Top::ReportPendingMessages(); |
| 223 | |
| 224 return result; | 228 return result; |
| 225 } | 229 } |
| 226 | 230 |
| 227 | 231 |
| 228 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, | 232 Handle<JSFunction> Compiler::CompileEval(Handle<String> source, |
| 229 Handle<Context> context, | 233 Handle<Context> context, |
| 230 int line_offset, | 234 int line_offset, |
| 231 bool is_global) { | 235 bool is_global) { |
| 232 int source_length = source->length(); | 236 int source_length = source->length(); |
| 233 Counters::total_eval_size.Increment(source_length); | 237 Counters::total_eval_size.Increment(source_length); |
| 234 Counters::total_compile_size.Increment(source_length); | 238 Counters::total_compile_size.Increment(source_length); |
| 235 | 239 |
| 236 // The VM is in the COMPILER state until exiting this function. | 240 // The VM is in the COMPILER state until exiting this function. |
| 237 VMState state(COMPILER); | 241 VMState state(COMPILER); |
| 238 CompilationCache::Entry entry = is_global | 242 CompilationCache::Entry entry = is_global |
| 239 ? CompilationCache::EVAL_GLOBAL | 243 ? CompilationCache::EVAL_GLOBAL |
| 240 : CompilationCache::EVAL_CONTEXTUAL; | 244 : CompilationCache::EVAL_CONTEXTUAL; |
| 241 | 245 |
| 242 // Do a lookup in the compilation cache; if the entry is not there, | 246 // Do a lookup in the compilation cache; if the entry is not there, |
| 243 // invoke the compiler and add the result to the cache. | 247 // invoke the compiler and add the result to the cache. |
| 244 Handle<JSFunction> result = | 248 Handle<JSFunction> result = |
| 245 CompilationCache::LookupEval(source, context, entry); | 249 CompilationCache::LookupEval(source, context, entry); |
| 246 if (result.is_null()) { | 250 if (result.is_null()) { |
| 247 // Create a script object describing the script to be compiled. | 251 // Create a script object describing the script to be compiled. |
| 248 Handle<Script> script = Factory::NewScript(source); | 252 Handle<Script> script = Factory::NewScript(source); |
| 249 script->set_line_offset(Smi::FromInt(line_offset)); | 253 script->set_line_offset(Smi::FromInt(line_offset)); |
| 250 result = MakeFunction(is_global, true, script, context, NULL, NULL); | 254 result = MakeFunction(is_global, true, script, context, NULL, NULL); |
| 251 if (!result.is_null()) { | 255 if (!result.is_null()) { |
| 252 CompilationCache::PutEvalFunction(source, context, entry, result); | 256 CompilationCache::PutEval(source, context, entry, result); |
| 253 } | 257 } |
| 254 } | 258 } |
| 255 | 259 |
| 256 return result; | 260 return result; |
| 257 } | 261 } |
| 258 | 262 |
| 259 | 263 |
| 260 bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared, | 264 bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared, |
| 261 int loop_nesting) { | 265 int loop_nesting) { |
| 262 ZoneScope zone_scope(DELETE_ON_EXIT); | 266 ZoneScope zone_scope(DELETE_ON_EXIT); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 304 |
| 301 // Compile the code. | 305 // Compile the code. |
| 302 Handle<Code> code = MakeCode(lit, script, Handle<Context>::null(), false); | 306 Handle<Code> code = MakeCode(lit, script, Handle<Context>::null(), false); |
| 303 | 307 |
| 304 // Check for stack-overflow exception. | 308 // Check for stack-overflow exception. |
| 305 if (code.is_null()) { | 309 if (code.is_null()) { |
| 306 Top::StackOverflow(); | 310 Top::StackOverflow(); |
| 307 return false; | 311 return false; |
| 308 } | 312 } |
| 309 | 313 |
| 310 #ifdef ENABLE_LOGGING_AND_PROFILING | 314 #if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT |
| 311 // Log the code generation. If source information is available include script | 315 // Log the code generation. If source information is available include script |
| 312 // 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 |
| 313 // the line number is not for free. | 317 // the line number is not for free. |
| 314 if (Logger::is_enabled()) { | 318 if (Logger::is_enabled() || OProfileAgent::is_enabled()) { |
| 315 if (script->name()->IsString()) { | 319 if (script->name()->IsString()) { |
| 316 int line_num = script->GetLineNumber(start_position); | 320 int line_num = script->GetLineNumber(start_position); |
| 317 if (line_num > 0) { | 321 if (line_num > 0) { |
| 318 line_num += script->line_offset()->value() + 1; | 322 line_num += script->line_offset()->value() + 1; |
| 319 } | 323 } |
| 320 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name(), | 324 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name(), |
| 321 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()); |
| 322 } else { | 330 } else { |
| 323 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name())); | 331 LOG(CodeCreateEvent("LazyCompile", *code, *lit->name())); |
| 332 OProfileAgent::CreateNativeCodeRegion(*lit->name(), code->address(), |
| 333 code->ExecutableSize()); |
| 324 } | 334 } |
| 325 } | 335 } |
| 326 #endif | 336 #endif |
| 327 | 337 |
| 328 // Update the shared function info with the compiled code. | 338 // Update the shared function info with the compiled code. |
| 329 shared->set_code(*code); | 339 shared->set_code(*code); |
| 330 | 340 |
| 331 // Set the expected number of properties for instances. | 341 // Set the expected number of properties for instances. |
| 332 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); | 342 SetExpectedNofPropertiesFromEstimate(shared, lit->expected_property_count()); |
| 333 | 343 |
| 334 // Check the function has compiled code. | 344 // Check the function has compiled code. |
| 335 ASSERT(shared->is_compiled()); | 345 ASSERT(shared->is_compiled()); |
| 336 return true; | 346 return true; |
| 337 } | 347 } |
| 338 | 348 |
| 339 | 349 |
| 340 } } // namespace v8::internal | 350 } } // namespace v8::internal |
| OLD | NEW |