From d22dbb5c51d51813fdea77a6bf1d6a9867372cfa Mon Sep 17 00:00:00 2001
From: Parsa Nasirimehr
Date: Tue, 7 Jan 2025 00:49:59 -0800
Subject: [PATCH] chore(Android): Migrate Hermes Instruments to Kotlin (#48378)
Summary:
Time to migrate some of Hermes's instruments. I see that HermesMemoryDumper(`react/hermes/instrumentation/HermesMemoryDumper.h`) implements the interface on C++, ~but not sure if i need to update the `getId` call to just `id` (same with `getInternalStorage`) or if the interop between Kotlin and Java applies to these things as well. cortinico Any thoughts on your side would be appreciated.
HermesSamplingProfiler just became an object, since it was a singleton and a static anyway.
Here is what HermesMemoryDumper.h looks like:
~
*Updated*: I ended up making them match the function signature on Cxx, because even if it does have that implicit behavior, doesn't feel right to tap into it like this.
## Changelog:
[INTERNAL] [FIXED] - Migrate HermesMemoryDumper and HermesSamplingProfiler to Kotlin
Pull Request resolved: https://github.com/facebook/react-native/pull/48378
Test Plan:
`/gradlew test`:
Reviewed By: cortinico
Differential Revision: D67657481
Pulled By: philIip
fbshipit-source-id: 4fb5e003789d51d464d0cca5800704ea51324b69
---
...MemoryDumper.java => HermesMemoryDumper.kt} | 10 +++++-----
...Profiler.java => HermesSamplingProfiler.kt} | 18 ++++++++----------
2 files changed, 13 insertions(+), 15 deletions(-)
rename packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/{HermesMemoryDumper.java => HermesMemoryDumper.kt} (54%)
rename packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/{HermesSamplingProfiler.java => HermesSamplingProfiler.kt} (54%)
diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.kt
similarity index 54%
rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.java
rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.kt
index 518d2aa6f084ec..ddce11e5ceebaa 100644
--- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.java
+++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.kt
@@ -5,14 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/
-package com.facebook.hermes.instrumentation;
+package com.facebook.hermes.instrumentation
public interface HermesMemoryDumper {
- boolean shouldSaveSnapshot();
+ public fun shouldSaveSnapshot(): Boolean
- String getInternalStorage();
+ public fun getInternalStorage(): String
- String getId();
+ public fun getId(): String
- void setMetaData(String crashId);
+ public fun setMetaData(crashId: String)
}
diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesSamplingProfiler.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesSamplingProfiler.kt
similarity index 54%
rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesSamplingProfiler.java
rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesSamplingProfiler.kt
index c02700a6bcb723..9fef00ed214a12 100644
--- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesSamplingProfiler.java
+++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesSamplingProfiler.kt
@@ -5,28 +5,26 @@
* LICENSE file in the root directory of this source tree.
*/
-package com.facebook.hermes.instrumentation;
+package com.facebook.hermes.instrumentation
-import com.facebook.soloader.SoLoader;
+import com.facebook.soloader.SoLoader
/** Hermes sampling profiler static JSI API. */
-public class HermesSamplingProfiler {
- static {
- SoLoader.loadLibrary("jsijniprofiler");
+public object HermesSamplingProfiler {
+ init {
+ SoLoader.loadLibrary("jsijniprofiler")
}
/** Start sample profiling. */
- public static native void enable();
+ @JvmStatic public external fun enable()
/** Stop sample profiling. */
- public static native void disable();
+ @JvmStatic public external fun disable()
/**
* Dump sampled stack traces to file.
*
* @param filename the file to dump sampling trace to.
*/
- public static native void dumpSampledTraceToFile(String filename);
-
- private HermesSamplingProfiler() {}
+ @JvmStatic public external fun dumpSampledTraceToFile(filename: String)
}