@@ -31,153 +31,15 @@ namespace node {
3131using v8::Context;
3232using v8::Function;
3333using v8::FunctionCallbackInfo;
34- using v8::GCCallbackFlags;
35- using v8::GCType;
3634using v8::Handle;
37- using v8::HandleScope;
3835using v8::HeapStatistics;
3936using v8::Isolate;
4037using v8::Local;
41- using v8::Null;
42- using v8::Number;
4338using v8::Object;
4439using v8::String;
4540using v8::Uint32;
4641using v8::V8;
4742using v8::Value;
48- using v8::kGCTypeAll ;
49- using v8::kGCTypeMarkSweepCompact ;
50- using v8::kGCTypeScavenge ;
51-
52-
53- void Environment::IsolateData::BeforeGarbageCollection (Isolate* isolate,
54- GCType type,
55- GCCallbackFlags flags) {
56- Get (isolate)->BeforeGarbageCollection (type, flags);
57- }
58-
59-
60- void Environment::IsolateData::AfterGarbageCollection (Isolate* isolate,
61- GCType type,
62- GCCallbackFlags flags) {
63- Get (isolate)->AfterGarbageCollection (type, flags);
64- }
65-
66-
67- void Environment::IsolateData::BeforeGarbageCollection (GCType type,
68- GCCallbackFlags flags) {
69- gc_info_before_ = GCInfo (isolate (), type, flags, uv_hrtime ());
70- }
71-
72-
73- void Environment::IsolateData::AfterGarbageCollection (GCType type,
74- GCCallbackFlags flags) {
75- gc_info_after_ = GCInfo (isolate (), type, flags, uv_hrtime ());
76-
77- // The copy upfront and the remove-then-insert is to avoid corrupting the
78- // list when the callback removes itself from it. QUEUE_FOREACH() is unsafe
79- // when the list is mutated while being walked.
80- ASSERT (QUEUE_EMPTY (&gc_tracker_queue_) == false );
81- QUEUE queue;
82- QUEUE* q = QUEUE_HEAD (&gc_tracker_queue_);
83- QUEUE_SPLIT (&gc_tracker_queue_, q, &queue);
84- while (QUEUE_EMPTY (&queue) == false ) {
85- q = QUEUE_HEAD (&queue);
86- QUEUE_REMOVE (q);
87- QUEUE_INSERT_TAIL (&gc_tracker_queue_, q);
88- Environment* env = ContainerOf (&Environment::gc_tracker_queue_, q);
89- env->AfterGarbageCollectionCallback (&gc_info_before_, &gc_info_after_);
90- }
91- }
92-
93-
94- void Environment::IsolateData::StartGarbageCollectionTracking (
95- Environment* env) {
96- if (QUEUE_EMPTY (&gc_tracker_queue_)) {
97- isolate ()->AddGCPrologueCallback (BeforeGarbageCollection, v8::kGCTypeAll );
98- isolate ()->AddGCEpilogueCallback (AfterGarbageCollection, v8::kGCTypeAll );
99- }
100- ASSERT (QUEUE_EMPTY (&env->gc_tracker_queue_ ) == true );
101- QUEUE_INSERT_TAIL (&gc_tracker_queue_, &env->gc_tracker_queue_ );
102- }
103-
104-
105- void Environment::IsolateData::StopGarbageCollectionTracking (Environment* env) {
106- ASSERT (QUEUE_EMPTY (&env->gc_tracker_queue_ ) == false );
107- QUEUE_REMOVE (&env->gc_tracker_queue_ );
108- QUEUE_INIT (&env->gc_tracker_queue_ );
109- if (QUEUE_EMPTY (&gc_tracker_queue_)) {
110- isolate ()->RemoveGCPrologueCallback (BeforeGarbageCollection);
111- isolate ()->RemoveGCEpilogueCallback (AfterGarbageCollection);
112- }
113- }
114-
115-
116- // Considering a memory constrained environment, creating more objects is less
117- // than ideal
118- void Environment::AfterGarbageCollectionCallback (const GCInfo* before,
119- const GCInfo* after) {
120- HandleScope handle_scope (isolate ());
121- Context::Scope context_scope (context ());
122- Local<Value> argv[] = { Object::New (isolate ()), Object::New (isolate ()) };
123- const GCInfo* infov[] = { before, after };
124- for (unsigned i = 0 ; i < ARRAY_SIZE (argv); i += 1 ) {
125- Local<Object> obj = argv[i].As <Object>();
126- const GCInfo* info = infov[i];
127- switch (info->type ()) {
128- case kGCTypeScavenge :
129- obj->Set (type_string (), scavenge_string ());
130- break ;
131- case kGCTypeMarkSweepCompact :
132- obj->Set (type_string (), mark_sweep_compact_string ());
133- break ;
134- default :
135- UNREACHABLE ();
136- }
137- obj->Set (flags_string (), Uint32::NewFromUnsigned (isolate (), info->flags ()));
138- obj->Set (timestamp_string (), Number::New (isolate (), info->timestamp ()));
139- // TODO(trevnorris): Setting many object properties in C++ is a significant
140- // performance hit. Redo this to pass the results to JS and create/set the
141- // properties there.
142- #define V (name ) \
143- do { \
144- obj->Set (name ## _string (), \
145- Uint32::NewFromUnsigned (isolate (), info->stats ()->name ())); \
146- } while (0 )
147- V (total_heap_size);
148- V (total_heap_size_executable);
149- V (total_physical_size);
150- V (used_heap_size);
151- V (heap_size_limit);
152- #undef V
153- }
154- MakeCallback (this ,
155- Null (isolate ()),
156- gc_info_callback_function (),
157- ARRAY_SIZE (argv),
158- argv);
159- }
160-
161-
162- void Environment::StartGarbageCollectionTracking (Local<Function> callback) {
163- ASSERT (gc_info_callback_function ().IsEmpty () == true );
164- set_gc_info_callback_function (callback);
165- isolate_data ()->StartGarbageCollectionTracking (this );
166- }
167-
168-
169- void Environment::StopGarbageCollectionTracking () {
170- ASSERT (gc_info_callback_function ().IsEmpty () == false );
171- isolate_data ()->StopGarbageCollectionTracking (this );
172- set_gc_info_callback_function (Local<Function>());
173- }
174-
175-
176- void StartGarbageCollectionTracking (const FunctionCallbackInfo<Value>& args) {
177- CHECK (args[0 ]->IsFunction () == true );
178- Environment* env = Environment::GetCurrent (args);
179- env->StartGarbageCollectionTracking (args[0 ].As <Function>());
180- }
18143
18244
18345void GetHeapStatistics (const FunctionCallbackInfo<Value>& args) {
@@ -201,11 +63,6 @@ void GetHeapStatistics(const FunctionCallbackInfo<Value>& args) {
20163}
20264
20365
204- void StopGarbageCollectionTracking (const FunctionCallbackInfo<Value>& args) {
205- Environment::GetCurrent (args)->StopGarbageCollectionTracking ();
206- }
207-
208-
20966void SetFlagsFromString (const FunctionCallbackInfo<Value>& args) {
21067 String::Utf8Value flags (args[0 ]);
21168 V8::SetFlagsFromString (*flags, flags.length ());
@@ -216,12 +73,6 @@ void InitializeV8Bindings(Handle<Object> target,
21673 Handle<Value> unused,
21774 Handle<Context> context) {
21875 Environment* env = Environment::GetCurrent (context);
219- env->SetMethod (target,
220- " startGarbageCollectionTracking" ,
221- StartGarbageCollectionTracking);
222- env->SetMethod (target,
223- " stopGarbageCollectionTracking" ,
224- StopGarbageCollectionTracking);
22576 env->SetMethod (target, " getHeapStatistics" , GetHeapStatistics);
22677 env->SetMethod (target, " setFlagsFromString" , SetFlagsFromString);
22778}
0 commit comments