diff --git a/bridge/core/api/api.cc b/bridge/core/api/api.cc index eb8b31fe4e..976fed70cc 100644 --- a/bridge/core/api/api.cc +++ b/bridge/core/api/api.cc @@ -72,18 +72,23 @@ void evaluateQuickjsByteCodeInternal(void* page_, void evaluateWbcInternal(void* page_, uint8_t* bytes, - int32_t byteLen, + int32_t byte_len, + int64_t profile_id, Dart_PersistentHandle persistent_handle, EvaluateQuickjsByteCodeCallback result_callback) { auto page = reinterpret_cast(page_); assert(std::this_thread::get_id() == page->currentThread()); + page->dartIsolateContext()->profiler()->StartTrackEvaluation(profile_id); + size_t dataBlockSize; bool is_success; webf::Wbc wbc = webf::Wbc(); - uint8_t* dataBlockBytes = wbc.prepareWbc(bytes, byteLen, &dataBlockSize); + uint8_t* dataBlockBytes = wbc.prepareWbc(bytes, byte_len, &dataBlockSize); if (dataBlockBytes == nullptr) { +#if ENABLE_LOG WEBF_LOG(ERROR) << "prepareWbc error" << std::endl; +#endif is_success = false; } else { std::vector decompressedBytes; @@ -95,14 +100,21 @@ void evaluateWbcInternal(void* page_, dataBlockBytes = NULL; if (decompressedSize < 0) { +#if ENABLE_LOG WEBF_LOG(ERROR) << "LZ4 decompression failed with error code: " << decompressedSize << std::endl; +#endif is_success = false; } else { +#if ENABLE_LOG WEBF_LOG(VERBOSE) << "LZ4 decompression success! " << decompressedSize << std::endl; +#endif is_success = page->evaluateByteCode(reinterpret_cast(decompressedBytes.data()), decompressedSize); + WEBF_LOG(VERBOSE) << " SUCCESS: " << is_success; } } + page->dartIsolateContext()->profiler()->FinishTrackEvaluation(profile_id); + page->dartIsolateContext()->dispatcher()->PostToDart(page->isDedicated(), ReturnEvaluateQuickjsByteCodeResultToDart, persistent_handle, result_callback, is_success); } diff --git a/bridge/core/api/api.h b/bridge/core/api/api.h index 97a28c627f..e73d8e6f75 100644 --- a/bridge/core/api/api.h +++ b/bridge/core/api/api.h @@ -30,7 +30,8 @@ void evaluateQuickjsByteCodeInternal(void* page_, void evaluateWbcInternal(void* page_, uint8_t* bytes, - int32_t byteLen, + int32_t byte_len, + int64_t profile_id, Dart_PersistentHandle persistent_handle, EvaluateQuickjsByteCodeCallback result_callback); void parseHTMLInternal(void* page_, diff --git a/bridge/include/webf_bridge.h b/bridge/include/webf_bridge.h index 535c9d15b3..d01b7d900c 100644 --- a/bridge/include/webf_bridge.h +++ b/bridge/include/webf_bridge.h @@ -100,6 +100,14 @@ void dumpQuickjsByteCode(void* page, DumpQuickjsByteCodeCallback result_callback); WEBF_EXPORT_C +void evaluateWbc(void* page_, + uint8_t* bytes, + int32_t byte_len, + int64_t profile_id, + Dart_Handle dart_handle, + EvaluateQuickjsByteCodeCallback result_callback); + + WEBF_EXPORT_C void parseHTML(void* page, char* code, int32_t length, diff --git a/bridge/webf_bridge.cc b/bridge/webf_bridge.cc index fc716d78c1..90a1dc3775 100644 --- a/bridge/webf_bridge.cc +++ b/bridge/webf_bridge.cc @@ -205,7 +205,8 @@ void parseHTML(void* page_, void evaluateWbc(void* page_, uint8_t* bytes, - int32_t byteLen, + int32_t byte_len, + int64_t profile_id, Dart_Handle dart_handle, EvaluateQuickjsByteCodeCallback result_callback) { #if ENABLE_LOG @@ -214,7 +215,7 @@ void evaluateWbc(void* page_, auto page = reinterpret_cast(page_); Dart_PersistentHandle persistent_handle = Dart_NewPersistentHandle_DL(dart_handle); page->dartIsolateContext()->dispatcher()->PostToJs(page->isDedicated(), page->contextId(), - webf::evaluateWbcInternal, page_, bytes, byteLen, + webf::evaluateWbcInternal, page_, bytes, byte_len, profile_id, persistent_handle, result_callback); } diff --git a/webf/example/assets/bundle.html b/webf/example/assets/bundle.html index 431559ebb8..1be47ec9f3 100644 --- a/webf/example/assets/bundle.html +++ b/webf/example/assets/bundle.html @@ -46,6 +46,6 @@ - + diff --git a/webf/example/assets/bundle.wbc1 b/webf/example/assets/bundle.wbc1 new file mode 100644 index 0000000000..a69e018f83 Binary files /dev/null and b/webf/example/assets/bundle.wbc1 differ diff --git a/webf/lib/src/bridge/to_native.dart b/webf/lib/src/bridge/to_native.dart index b69ffa0dba..ea2a6d36ec 100644 --- a/webf/lib/src/bridge/to_native.dart +++ b/webf/lib/src/bridge/to_native.dart @@ -389,7 +389,7 @@ Future evaluateQuickjsByteCode(double contextId, Uint8List bytes, { Evalua return completer.future; } -Future evaluateWbc(double contextId, Uint8List bytes) async { +Future evaluateWbc(double contextId, Uint8List bytes, { EvaluateOpItem? profileOp }) async { if (WebFController.getControllerOfJSContextId(contextId) == null) { return false; } @@ -403,7 +403,7 @@ Future evaluateWbc(double contextId, Uint8List bytes) async { Pointer> nativeCallback = Pointer.fromFunction(handleEvaluateQuickjsByteCodeResult); - _evaluateWbc(_allocatedPages[contextId]!, byteData, bytes.length, context, nativeCallback); + _evaluateWbc(_allocatedPages[contextId]!, byteData, bytes.length, profileOp?.hashCode ?? 0, context, nativeCallback); return completer.future; } diff --git a/webf/lib/src/html/script.dart b/webf/lib/src/html/script.dart index 36c2af91f4..5376960bd2 100644 --- a/webf/lib/src/html/script.dart +++ b/webf/lib/src/html/script.dart @@ -49,11 +49,12 @@ class ScriptRunner { } } else if (bundle.isBytecode) { bool result = false; - if (bundle.url.contains('.kbc1')) { - result = await evaluateQuickjsByteCode(contextId, bundle.data!, profileOp: profileOp); - } else if (bundle.url.contains('.wbc1')) { + if (bundle.url.contains('.wbc1')) { result = await evaluateWbc(contextId, bundle.data!, profileOp: profileOp); + } else { + result = await evaluateQuickjsByteCode(contextId, bundle.data!, profileOp: profileOp); } + print('result: $result'); if (!result) { throw FlutterError('Bytecode are not valid to execute.');