@@ -85,8 +85,8 @@ void ObjectManager::Init(Isolate *isolate) {
85
85
m_poJsWrapperFunc = new Persistent<Function>(isolate, jsWrapperFunc);
86
86
87
87
if (m_markingMode != JavaScriptMarkingMode::None) {
88
- isolate->AddGCPrologueCallback (ObjectManager::OnGcStartedStatic, kGCTypeAll );
89
- isolate->AddGCEpilogueCallback (ObjectManager::OnGcFinishedStatic, kGCTypeAll );
88
+ isolate->AddGCPrologueCallback (ObjectManager::OnGcStartedStatic, kGCTypeMarkSweepCompact );
89
+ isolate->AddGCEpilogueCallback (ObjectManager::OnGcFinishedStatic, kGCTypeMarkSweepCompact );
90
90
}
91
91
}
92
92
@@ -380,9 +380,18 @@ void ObjectManager::JSObjectWeakCallback(Isolate *isolate, ObjectWeakCallbackSta
380
380
jsInstanceInfo->IsJavaObjectWeak = true ;
381
381
}
382
382
} else {
383
- assert (!m_markedForGC.empty ());
384
- auto &topGCInfo = m_markedForGC.top ();
385
- topGCInfo.markedForGC .push_back (po);
383
+ if (m_markedForGC.empty ()){
384
+ // Emulates the behavior in the OnGcStarted callback. Тhis is necessary as the hooking
385
+ // to the V8 GC is done only on the markSweepCompact phase. The JSObjectWeakCallback
386
+ // however is still triggered in other V8 GC phases (scavenger for example). This
387
+ // creates a problem that there is no 'top' on the m_markedForGC stack.
388
+ GarbageCollectionInfo gcInfo (++m_numberOfGC);
389
+ gcInfo.markedForGC .push_back (po);
390
+ m_markedForGC.push (gcInfo);
391
+ } else {
392
+ auto &topGCInfo = m_markedForGC.top ();
393
+ topGCInfo.markedForGC .push_back (po);
394
+ }
386
395
}
387
396
}
388
397
}
@@ -634,9 +643,15 @@ void ObjectManager::MarkReachableArrayElements(Local<Object> &o, stack<Local<Val
634
643
635
644
void ObjectManager::OnGcStartedStatic (Isolate *isolate, GCType type, GCCallbackFlags flags) {
636
645
try {
646
+ tns::instrumentation::Frame frame;
647
+
637
648
auto runtime = Runtime::GetRuntime (isolate);
638
649
auto objectManager = runtime->GetObjectManager ();
639
650
objectManager->OnGcStarted (type, flags);
651
+
652
+ if (frame.check ()){
653
+ frame.log (" OnGcStartedStatic" );
654
+ }
640
655
} catch (NativeScriptException &e) {
641
656
e.ReThrowToV8 ();
642
657
} catch (std::exception e) {
@@ -652,9 +667,15 @@ void ObjectManager::OnGcStartedStatic(Isolate *isolate, GCType type, GCCallbackF
652
667
653
668
void ObjectManager::OnGcFinishedStatic (Isolate *isolate, GCType type, GCCallbackFlags flags) {
654
669
try {
670
+ tns::instrumentation::Frame frame;
671
+
655
672
auto runtime = Runtime::GetRuntime (isolate);
656
673
auto objectManager = runtime->GetObjectManager ();
657
674
objectManager->OnGcFinished (type, flags);
675
+
676
+ if (frame.check ()){
677
+ frame.log (" OnGcFinishedStatic" );
678
+ }
658
679
} catch (NativeScriptException &e) {
659
680
e.ReThrowToV8 ();
660
681
} catch (std::exception e) {
0 commit comments