4242public final class JavaProfiler {
4343 private static final String NATIVE_LIBS = "/META-INF/native-libs" ;
4444 private static final String LIBRARY_NAME = "libjavaProfiler." + (OperatingSystem .current () == OperatingSystem .macos ? "dylib" : "so" );
45-
45+
4646 private static final Unsafe UNSAFE ;
4747 static {
4848 Unsafe unsafe = null ;
@@ -122,6 +122,16 @@ public static synchronized JavaProfiler getInstance(String libLocation, String s
122122 System .load (libLocation );
123123 profiler .initializeContextStorage ();
124124 instance = profiler ;
125+
126+ String maxArenaValue = System .getProperty ("ddprof.debug.malloc_arena_max" );
127+ if (maxArenaValue != null ) {
128+ try {
129+ mallocArenaMax0 (Integer .parseInt (maxArenaValue ));
130+ } catch (NumberFormatException e ) {
131+ System .out .println ("[WARN] Invalid value for ddprof.debug.malloc_arena_max: " + maxArenaValue + ". Expecting an integer." );
132+ }
133+ }
134+
125135 return profiler ;
126136 }
127137
@@ -139,7 +149,7 @@ public static synchronized JavaProfiler getInstance(String libLocation, String s
139149 */
140150 private static Path libraryFromClasspath (OperatingSystem os , Arch arch , String qualifier , Path tempDir ) throws IOException {
141151 String resourcePath = NATIVE_LIBS + "/" + os .name ().toLowerCase () + "-" + arch .name ().toLowerCase () + ((qualifier != null && !qualifier .isEmpty ()) ? "-" + qualifier : "" ) + "/" + LIBRARY_NAME ;
142-
152+
143153 InputStream libraryData = JavaProfiler .class .getResourceAsStream (resourcePath );
144154
145155 if (libraryData != null ) {
@@ -433,7 +443,7 @@ public boolean isThresholdExceeded(long thresholdMillis, long startTicks, long e
433443 * @param origin the thread the task was submitted on
434444 */
435445 public void recordQueueTime (long startTicks , long endTicks , Class <?> task , Class <?> scheduler ,
436- Thread origin ) {
446+ Thread origin ) {
437447 recordQueueEnd0 (startTicks , endTicks , task .getName (), scheduler .getName (), origin );
438448 }
439449
@@ -499,7 +509,7 @@ static boolean isMuslProcSelfMaps() throws IOException {
499509 * However, if such string is missing should indicate that the system is not a musl one.
500510 */
501511 static boolean isMuslJavaExecutable () throws IOException {
502-
512+
503513 byte [] magic = new byte []{(byte )0x7f , (byte )'E' , (byte )'L' , (byte )'F' };
504514 byte [] prefix = new byte []{(byte )'/' , (byte )'l' , (byte )'d' , (byte )'-' }; // '/ld-*'
505515 byte [] musl = new byte []{(byte )'m' , (byte )'u' , (byte )'s' , (byte )'l' }; // 'musl'
@@ -573,4 +583,6 @@ private static boolean containsArray(byte[] container, int offset, byte[] contai
573583 private static native long currentTicks0 ();
574584
575585 private static native long tscFrequency0 ();
586+
587+ private static native void mallocArenaMax0 (int max );
576588}
0 commit comments