55 class ScopedLoggerInitializer {
57 ScopedLoggerInitializer()
58 : saved_log_(i::FLAG_log),
59 saved_prof_(i::FLAG_prof),
62 trick_to_run_init_flags_(init_flags_()),
64 env_(v8::Context::New(
CcTest::isolate())),
65 logger_(
CcTest::i_isolate()->logger()) {
69 ~ScopedLoggerInitializer() {
72 if (temp_file_ !=
NULL) fclose(temp_file_);
73 i::FLAG_prof = saved_prof_;
74 i::FLAG_log = saved_log_;
79 Logger* logger() {
return logger_; }
81 FILE* StopLoggingGetTempFile() {
90 static bool init_flags_() {
94 i::FLAG_logfile_per_isolate =
false;
98 const bool saved_log_;
99 const bool saved_prof_;
101 const bool trick_to_run_init_flags_;
112 static const char* StrNStr(
const char*
s1,
const char*
s2,
int n) {
113 if (s1[n] ==
'\0')
return strstr(s1, s2);
117 char* found = strstr(str.start(),
s2);
118 return found !=
NULL ? s1 + (found - str.start()) :
NULL;
130 : v8::internal::Thread(isolate),
131 semaphore_(new v8::internal::Semaphore(0)),
135 virtual ~LoopingThread() {
delete semaphore_; }
138 self_ = pthread_self();
142 void SendSigProf() { pthread_kill(self_, SIGPROF); }
144 void Stop() { run_ =
false; }
146 bool WaitForRunning() {
return semaphore_->Wait(1000000); }
149 bool IsRunning() {
return run_; }
151 virtual void RunLoop() = 0;
153 void SetV8ThreadId() {
154 v8_thread_id_ = v8::V8::GetCurrentThreadId();
157 void SignalRunning() { semaphore_->Signal(); }
160 v8::internal::Semaphore* semaphore_;
167 class LoopingJsThread :
public LoopingThread {
170 : LoopingThread(isolate) { }
176 while (IsRunning()) {
184 "var j; for (var i=0; i<10000; ++i) { j = Math.sin(i); }");
193 class LoopingNonJsThread :
public LoopingThread {
196 : LoopingThread(isolate) { }
205 while (IsRunning()) {
217 semaphore_(new v8::internal::Semaphore(0)),
218 was_sample_stack_called_(
false) {
221 ~TestSampler() {
delete semaphore_; }
224 was_sample_stack_called_ =
true;
229 bool WaitForTick() {
return semaphore_->Wait(1000000); }
231 void Reset() { was_sample_stack_called_ =
false; }
233 bool WasSampleStackCalled() {
return was_sample_stack_called_; }
236 v8::internal::Semaphore* semaphore_;
237 bool was_sample_stack_called_;
243 TEST(ProfMultipleThreads) {
244 TestSampler* sampler =
NULL;
249 CHECK(sampler->IsActive());
257 CHECK(!sampler->WasSampleStackCalled());
258 jsThread.WaitForRunning();
259 jsThread.SendSigProf();
260 CHECK(sampler->WaitForTick());
261 CHECK(sampler->WasSampleStackCalled());
263 CHECK(!sampler->WasSampleStackCalled());
264 nonJsThread.WaitForRunning();
265 nonJsThread.SendSigProf();
266 CHECK(!sampler->WaitForTick());
267 CHECK(!sampler->WasSampleStackCalled());
288 explicit SimpleExternalString(
const char* source)
290 for (
int i = 0; i < utf_source_.length(); ++i)
291 utf_source_[i] = source[i];
293 virtual ~SimpleExternalString() {}
294 virtual size_t length()
const {
return utf_source_.length(); }
295 virtual const uint16_t*
data()
const {
return utf_source_.start(); }
307 SimpleExternalString source_ext_str(
"(function ext() {})();");
315 CHECK(!evil_script->
Run().IsEmpty());
320 i_source->set_resource(
NULL);
333 ScopedLoggerInitializer initialize_logger;
334 Logger* logger = initialize_logger.logger();
343 proto->
Set(v8_str(
"method1"),
350 initialize_logger.env()->Global()->Set(v8_str(
"Obj"), obj->
GetFunction());
351 CompileRun(
"Obj.prototype.method1.toString();");
357 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists,
true));
362 "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"method1\"\0",
386 ScopedLoggerInitializer initialize_logger;
387 Logger* logger = initialize_logger.logger();
394 inst->
SetAccessor(v8_str(
"prop1"), Prop1Getter, Prop1Setter);
401 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists,
true));
406 "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"get prop1\"",
413 "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"set prop1\"",
420 "code-creation,Callback,-2,0x%" V8PRIxPTR ",1,\"get prop2\"",
433 TEST(EquivalenceOfLoggingAndTraversal) {
441 ScopedLoggerInitializer initialize_logger;
442 Logger* logger = initialize_logger.logger();
446 "(function f(obj) {\n"
448 " (function a(j) { return function b() { return j; } })(100);\n"
460 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists,
true));
464 initialize_logger.env()->Global()->Set(v8_str(
"_log"), log_str);
474 printf(
"compile: %s\n", *exception);
480 printf(
"run: %s\n", *exception);
488 s->WriteUtf8(data.start());
489 printf(
"%s\n", data.start());
void SetAccessor(Handle< String > name, AccessorGetterCallback getter, AccessorSetterCallback setter=0, Handle< Value > data=Handle< Value >(), AccessControl settings=DEFAULT, PropertyAttribute attribute=None, Handle< AccessorSignature > signature=Handle< AccessorSignature >())
static Local< Signature > New(Isolate *isolate, Handle< FunctionTemplate > receiver=Handle< FunctionTemplate >(), int argc=0, Handle< FunctionTemplate > argv[]=0)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
static V8_INLINE Local< T > New(Isolate *isolate, Handle< T > that)
void CollectAllGarbage(int flags, const char *gc_reason=NULL, const GCCallbackFlags gc_callback_flags=kNoGCCallbackFlags)
static const char *const kLogToTemporaryFile
static ExternalTwoByteString * cast(Object *obj)
Local< ObjectTemplate > InstanceTemplate()
void LogCompiledFunctions()
static Vector< const byte > GetScriptsSource()
i::NativesCollection< i::TEST > TestSources
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in only print modified registers Don t break for ASM_UNIMPLEMENTED_BREAK macros print stack trace when an illegal exception is thrown randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot testing_bool_flag testing_int_flag string flag tmp file in which to serialize heap Print the time it takes to lazily compile hydrogen code stubs concurrent_recompilation concurrent_sweeping Print usage including on console Map counters to a file Enable debugger compile events enable GDBJIT enable GDBJIT interface for all code objects dump only objects containing this substring stress the GC compactor to flush out pretty print source code print source AST function name where to insert a breakpoint print scopes for builtins trace contexts operations print stuff during garbage collection report code statistics after GC report handles after GC trace cache state transitions print interface inference details prints when objects are turned into dictionaries report heap spill statistics along with trace isolate state changes trace regexp bytecode execution Minimal Log all events to the log file Log API events to the log file Log heap samples on garbage collection for the hp2ps tool log positions Log suspect operations Used with turns on browser compatible mode for profiling v8 log
Local< String > ToString() const
void Set(Handle< String > name, Handle< Data > value, PropertyAttribute attributes=None)
virtual const uint16_t * data() const =0
void SetClassName(Handle< String > name)
virtual size_t length() const =0
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths true
Vector< const char > ReadFile(const char *filename, bool *exists, bool verbose)
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >(), int length=0)
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
static i::Isolate * i_isolate()
static const int kMakeHeapIterableMask
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
#define CHECK_NE(unexpected, value)
static void Sleep(const int milliseconds)
int StrLength(const char *string)
void SampleStack(const RegisterState ®s)
static Local< Context > New(Isolate *isolate, ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())
static int SNPrintF(Vector< char > str, const char *format,...)
V8_INLINE bool IsEmpty() const
Local< Function > GetFunction()
V8_INLINE bool IsEmpty() const
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function info
static Local< String > NewExternal(Isolate *isolate, ExternalStringResource *resource)
Local< ObjectTemplate > PrototypeTemplate()
static void StrNCpy(Vector< char > dest, const char *src, size_t n)
void LogAccessorCallbacks()
virtual void Tick(TickSample *sample)=0
void StringEvent(const char *name, const char *value)
static v8::Isolate * isolate()
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)