* When JS GC happens change state of the java counterpart to mirror state of JS * object and REVIVE the JS object unconditionally "Regular" js objects are * pushed into the "regular objects" array "Callback" js objects (ones that have * implementation object) are pushed into two "special objects" array: -ones * called for the first time which are originally strong in java -ones called * for t
| 402 | * performance optimizations during GC |
| 403 | * */ |
| 404 | void ObjectManager::JSObjectWeakCallback( |
| 405 | Isolate* isolate, ObjectWeakCallbackState* callbackState) { |
| 406 | HandleScope handleScope(isolate); |
| 407 | |
| 408 | Persistent<Object>* po = callbackState->target; |
| 409 | |
| 410 | auto itFound = m_visitedPOs.find(po); |
| 411 | |
| 412 | if (itFound == m_visitedPOs.end()) { |
| 413 | m_visitedPOs.insert(po); |
| 414 | |
| 415 | auto obj = Local<Object>::New(isolate, *po); |
| 416 | JSInstanceInfo* jsInstanceInfo = GetJSInstanceInfo(obj); |
| 417 | |
| 418 | if (jsInstanceInfo != nullptr) { |
| 419 | int javaObjectID = jsInstanceInfo->JavaObjectID; |
| 420 | |
| 421 | bool hasImplObj = HasImplObject(isolate, obj); |
| 422 | |
| 423 | DEBUG_WRITE("JSObjectWeakCallback objectId: %d, hasImplObj=%d", |
| 424 | javaObjectID, hasImplObj); |
| 425 | |
| 426 | if (hasImplObj) { |
| 427 | if (jsInstanceInfo->IsJavaObjectWeak) { |
| 428 | m_implObjWeak.emplace_back(po, javaObjectID); |
| 429 | } else { |
| 430 | m_implObjStrong.emplace(javaObjectID, po); |
| 431 | jsInstanceInfo->IsJavaObjectWeak = true; |
| 432 | } |
| 433 | } else { |
| 434 | if (m_markedForGC.empty()) { |
| 435 | // Emulates the behavior in the OnGcStarted callback. Тhis is |
| 436 | // necessary as the hooking to the V8 GC is done only on the |
| 437 | // markSweepCompact phase. The JSObjectWeakCallback however is still |
| 438 | // triggered in other V8 GC phases (scavenger for example). This |
| 439 | // creates a problem that there is no 'top' on the m_markedForGC |
| 440 | // stack. |
| 441 | GarbageCollectionInfo gcInfo(++m_numberOfGC); |
| 442 | gcInfo.markedForGC.push_back(po); |
| 443 | m_markedForGC.push(gcInfo); |
| 444 | } else { |
| 445 | auto& topGCInfo = m_markedForGC.top(); |
| 446 | topGCInfo.markedForGC.push_back(po); |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | po->SetWeak(callbackState, JSObjectWeakCallbackStatic, |
| 453 | WeakCallbackType::kFinalizer); |
| 454 | } |
| 455 | |
| 456 | int ObjectManager::GenerateNewObjectID() { |
| 457 | const int one = 1; |
no test coverage detected