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

Side by Side Diff: src/debug.h

Issue 115462: Add a script cache to the debugger... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « include/v8-debug.h ('k') | src/debug.cc » ('j') | src/debug.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_DEBUG_H_ 28 #ifndef V8_DEBUG_H_
29 #define V8_DEBUG_H_ 29 #define V8_DEBUG_H_
30 30
31 #include "assembler.h" 31 #include "assembler.h"
32 #include "code-stubs.h" 32 #include "code-stubs.h"
33 #include "debug-agent.h" 33 #include "debug-agent.h"
34 #include "execution.h" 34 #include "execution.h"
35 #include "factory.h" 35 #include "factory.h"
36 #include "hashmap.h"
36 #include "platform.h" 37 #include "platform.h"
37 #include "string-stream.h" 38 #include "string-stream.h"
38 #include "v8threads.h" 39 #include "v8threads.h"
39 40
40 #ifdef ENABLE_DEBUGGER_SUPPORT 41 #ifdef ENABLE_DEBUGGER_SUPPORT
41 #include "../include/v8-debug.h" 42 #include "../include/v8-debug.h"
42 43
43 namespace v8 { namespace internal { 44 namespace v8 { namespace internal {
44 45
45 46
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 void ClearDebugBreakAtIC(); 138 void ClearDebugBreakAtIC();
138 139
139 bool IsDebugBreakAtReturn(); 140 bool IsDebugBreakAtReturn();
140 void SetDebugBreakAtReturn(); 141 void SetDebugBreakAtReturn();
141 void ClearDebugBreakAtReturn(); 142 void ClearDebugBreakAtReturn();
142 143
143 DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator); 144 DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator);
144 }; 145 };
145 146
146 147
148 // Cache of all script objects in the heap. When a script is added a weak handle
149 // to it is created and that weak handle is stored in the cache. The weak handle
150 // callback takes care of removing the script from the cache. The key used in
151 // the hash map holding the cache is the script id.
Mads Ager (chromium) 2009/05/18 12:57:00 I would just write "The key used in the cache is t
Søren Thygesen Gjesse 2009/05/18 13:13:17 Done.
152 class ScriptCache : private HashMap {
153 public:
154 ScriptCache() : HashMap(ScriptMatch), collected_scripts_(10) {}
155 virtual ~ScriptCache() { Clear(); }
156
157 // Add script to the cache.
158 void Add(Handle<Script> script);
159
160 // Return the scripts in the cache.
161 Handle<FixedArray> GetScripts();
162
163 // Generate debugger events for collected scripts.
164 void ProcessCollectedScripts();
165
166 private:
167 // Calculate the hash value from the key (script id).
168 static uint32_t Hash(int key) { return ComputeIntegerHash(key); }
169
170 // Scripts match if their keys (script id) match.
171 static bool ScriptMatch(void* key1, void* key2) { return key1 == key2; }
172
173 // Clear the cache releasing all the weak handles.
174 void Clear();
175
176 // Weak handle callback for scripts in the cache.
177 static void HandleWeakScript(v8::Persistent<v8::Value> obj, void* data);
178
179 // List used during GC to temporarily store id's of collected scripts.
180 List<int> collected_scripts_;
181 };
182
183
147 // Linked list holding debug info objects. The debug info objects are kept as 184 // Linked list holding debug info objects. The debug info objects are kept as
148 // weak handles to avoid a debug info object to keep a function alive. 185 // weak handles to avoid a debug info object to keep a function alive.
149 class DebugInfoListNode { 186 class DebugInfoListNode {
150 public: 187 public:
151 explicit DebugInfoListNode(DebugInfo* debug_info); 188 explicit DebugInfoListNode(DebugInfo* debug_info);
152 virtual ~DebugInfoListNode(); 189 virtual ~DebugInfoListNode();
153 190
154 DebugInfoListNode* next() { return next_; } 191 DebugInfoListNode* next() { return next_; }
155 void set_next(DebugInfoListNode* next) { next_ = next; } 192 void set_next(DebugInfoListNode* next) { next_ = next; }
156 Handle<DebugInfo> debug_info() { return debug_info_; } 193 Handle<DebugInfo> debug_info() { return debug_info_; }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // Fast check to see if any break points are active. 260 // Fast check to see if any break points are active.
224 inline static bool has_break_points() { return has_break_points_; } 261 inline static bool has_break_points() { return has_break_points_; }
225 262
226 static void NewBreak(StackFrame::Id break_frame_id); 263 static void NewBreak(StackFrame::Id break_frame_id);
227 static void SetBreak(StackFrame::Id break_frame_id, int break_id); 264 static void SetBreak(StackFrame::Id break_frame_id, int break_id);
228 static StackFrame::Id break_frame_id() { 265 static StackFrame::Id break_frame_id() {
229 return thread_local_.break_frame_id_; 266 return thread_local_.break_frame_id_;
230 } 267 }
231 static int break_id() { return thread_local_.break_id_; } 268 static int break_id() { return thread_local_.break_id_; }
232 269
233
234
235
236 static bool StepInActive() { return thread_local_.step_into_fp_ != 0; } 270 static bool StepInActive() { return thread_local_.step_into_fp_ != 0; }
237 static void HandleStepIn(Handle<JSFunction> function, 271 static void HandleStepIn(Handle<JSFunction> function,
238 Address fp, 272 Address fp,
239 bool is_constructor); 273 bool is_constructor);
240 static Address step_in_fp() { return thread_local_.step_into_fp_; } 274 static Address step_in_fp() { return thread_local_.step_into_fp_; }
241 static Address* step_in_fp_addr() { return &thread_local_.step_into_fp_; } 275 static Address* step_in_fp_addr() { return &thread_local_.step_into_fp_; }
242 276
243 static EnterDebugger* debugger_entry() { 277 static EnterDebugger* debugger_entry() {
244 return thread_local_.debugger_entry_; 278 return thread_local_.debugger_entry_;
245 } 279 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc 334 friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc
301 335
302 // Threading support. 336 // Threading support.
303 static char* ArchiveDebug(char* to); 337 static char* ArchiveDebug(char* to);
304 static char* RestoreDebug(char* from); 338 static char* RestoreDebug(char* from);
305 static int ArchiveSpacePerThread(); 339 static int ArchiveSpacePerThread();
306 340
307 // Mirror cache handling. 341 // Mirror cache handling.
308 static void ClearMirrorCache(); 342 static void ClearMirrorCache();
309 343
344 // Script cache handling.
345 static void CreateScriptCache();
346 static void DestroyScriptCache();
347 static void AddScriptToScriptCache(Handle<Script> script);
348 static Handle<FixedArray> GetLoadedScripts();
349
350 // Garbage collection notifications.
351 static void AfterGarbageCollection();
352
310 // Code generation assumptions. 353 // Code generation assumptions.
311 static const int kIa32CallInstructionLength = 5; 354 static const int kIa32CallInstructionLength = 5;
312 static const int kIa32JSReturnSequenceLength = 6; 355 static const int kIa32JSReturnSequenceLength = 6;
313 356
314 // Code generator routines. 357 // Code generator routines.
315 static void GenerateLoadICDebugBreak(MacroAssembler* masm); 358 static void GenerateLoadICDebugBreak(MacroAssembler* masm);
316 static void GenerateStoreICDebugBreak(MacroAssembler* masm); 359 static void GenerateStoreICDebugBreak(MacroAssembler* masm);
317 static void GenerateKeyedLoadICDebugBreak(MacroAssembler* masm); 360 static void GenerateKeyedLoadICDebugBreak(MacroAssembler* masm);
318 static void GenerateKeyedStoreICDebugBreak(MacroAssembler* masm); 361 static void GenerateKeyedStoreICDebugBreak(MacroAssembler* masm);
319 static void GenerateConstructCallDebugBreak(MacroAssembler* masm); 362 static void GenerateConstructCallDebugBreak(MacroAssembler* masm);
(...skipping 16 matching lines...) Expand all
336 static void SetAfterBreakTarget(JavaScriptFrame* frame); 379 static void SetAfterBreakTarget(JavaScriptFrame* frame);
337 static Handle<Object> CheckBreakPoints(Handle<Object> break_point); 380 static Handle<Object> CheckBreakPoints(Handle<Object> break_point);
338 static bool CheckBreakPoint(Handle<Object> break_point_object); 381 static bool CheckBreakPoint(Handle<Object> break_point_object);
339 382
340 // Global handle to debug context where all the debugger JavaScript code is 383 // Global handle to debug context where all the debugger JavaScript code is
341 // loaded. 384 // loaded.
342 static Handle<Context> debug_context_; 385 static Handle<Context> debug_context_;
343 386
344 // Boolean state indicating whether any break points are set. 387 // Boolean state indicating whether any break points are set.
345 static bool has_break_points_; 388 static bool has_break_points_;
389
390 // Cache of all scripts in the heap.
391 static ScriptCache* script_cache_;
392
393 // List of active debug info objects.
346 static DebugInfoListNode* debug_info_list_; 394 static DebugInfoListNode* debug_info_list_;
347 395
348 static bool disable_break_; 396 static bool disable_break_;
349 static bool break_on_exception_; 397 static bool break_on_exception_;
350 static bool break_on_uncaught_exception_; 398 static bool break_on_uncaught_exception_;
351 399
352 // Per-thread data. 400 // Per-thread data.
353 class ThreadLocal { 401 class ThreadLocal {
354 public: 402 public:
355 // Counter for generating next break id. 403 // Counter for generating next break id.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 bool* caught_exception); 573 bool* caught_exception);
526 static Handle<Object> MakeExceptionEvent(Handle<Object> exec_state, 574 static Handle<Object> MakeExceptionEvent(Handle<Object> exec_state,
527 Handle<Object> exception, 575 Handle<Object> exception,
528 bool uncaught, 576 bool uncaught,
529 bool* caught_exception); 577 bool* caught_exception);
530 static Handle<Object> MakeNewFunctionEvent(Handle<Object> func, 578 static Handle<Object> MakeNewFunctionEvent(Handle<Object> func,
531 bool* caught_exception); 579 bool* caught_exception);
532 static Handle<Object> MakeCompileEvent(Handle<Script> script, 580 static Handle<Object> MakeCompileEvent(Handle<Script> script,
533 bool before, 581 bool before,
534 bool* caught_exception); 582 bool* caught_exception);
583 static Handle<Object> MakeScriptCollectedEvent(int id,
584 bool* caught_exception);
535 static void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue); 585 static void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue);
536 static void OnException(Handle<Object> exception, bool uncaught); 586 static void OnException(Handle<Object> exception, bool uncaught);
537 static void OnBeforeCompile(Handle<Script> script); 587 static void OnBeforeCompile(Handle<Script> script);
538 static void OnAfterCompile(Handle<Script> script, 588 static void OnAfterCompile(Handle<Script> script,
539 Handle<JSFunction> fun); 589 Handle<JSFunction> fun);
540 static void OnNewFunction(Handle<JSFunction> fun); 590 static void OnNewFunction(Handle<JSFunction> fun);
591 static void OnScriptCollected(int id);
541 static void ProcessDebugEvent(v8::DebugEvent event, 592 static void ProcessDebugEvent(v8::DebugEvent event,
542 Handle<JSObject> event_data, 593 Handle<JSObject> event_data,
543 bool auto_continue); 594 bool auto_continue);
544 static void NotifyMessageHandler(v8::DebugEvent event, 595 static void NotifyMessageHandler(v8::DebugEvent event,
545 Handle<JSObject> exec_state, 596 Handle<JSObject> exec_state,
546 Handle<JSObject> event_data, 597 Handle<JSObject> event_data,
547 bool auto_continue); 598 bool auto_continue);
548 static void SetEventListener(Handle<Object> callback, Handle<Object> data); 599 static void SetEventListener(Handle<Object> callback, Handle<Object> data);
549 static void SetMessageHandler(v8::Debug::MessageHandler2 handler); 600 static void SetMessageHandler(v8::Debug::MessageHandler2 handler);
550 static void SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, 601 static void SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 StackGuard::Preempt(); 714 StackGuard::Preempt();
664 Debug::set_preemption_pending(false); 715 Debug::set_preemption_pending(false);
665 } 716 }
666 717
667 // If there are commands in the queue when leaving the debugger request that 718 // If there are commands in the queue when leaving the debugger request that
668 // these commands are processed. 719 // these commands are processed.
669 if (prev_ == NULL && Debugger::HasCommands()) { 720 if (prev_ == NULL && Debugger::HasCommands()) {
670 StackGuard::DebugCommand(); 721 StackGuard::DebugCommand();
671 } 722 }
672 723
673 // If leaving the debugger with the debugger no longer active unload it.
674 if (prev_ == NULL) { 724 if (prev_ == NULL) {
725 // Clear mirror cache when leaving the debugger. Skip this if there is a
726 // pending exception as clearing the mirror cache calls back into
727 // JavaScript. This can happen if the v8::Debug::Call is used in which
728 // case the exception should end up in the calling code.
729 if (!Top::has_pending_exception()) {
730 Debug::ClearMirrorCache();
731 }
732 // If leaving the debugger with the debugger no longer active unload it.
675 if (!Debugger::IsDebuggerActive()) { 733 if (!Debugger::IsDebuggerActive()) {
676 Debugger::UnloadDebugger(); 734 Debugger::UnloadDebugger();
677 } 735 }
678 } 736 }
679 737
680 // Leaving this debugger entry. 738 // Leaving this debugger entry.
681 Debug::set_debugger_entry(prev_); 739 Debug::set_debugger_entry(prev_);
682 } 740 }
683 741
684 // Check whether the debugger could be entered. 742 // Check whether the debugger could be entered.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 Debug::AddressId id_; 817 Debug::AddressId id_;
760 int reg_; 818 int reg_;
761 }; 819 };
762 820
763 821
764 } } // namespace v8::internal 822 } } // namespace v8::internal
765 823
766 #endif // ENABLE_DEBUGGER_SUPPORT 824 #endif // ENABLE_DEBUGGER_SUPPORT
767 825
768 #endif // V8_DEBUG_H_ 826 #endif // V8_DEBUG_H_
OLDNEW
« no previous file with comments | « include/v8-debug.h ('k') | src/debug.cc » ('j') | src/debug.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698