From 5b1b35623616964741bbb3fa2e5f02779e8378b2 Mon Sep 17 00:00:00 2001 From: ryota0624 Date: Wed, 7 Oct 2020 14:27:19 +0900 Subject: [PATCH] :hammer: replace printStackTrace() to using java.util.logging --- .../corretto/benchmark/extremem/Arraylet.java | 9 +++--- .../benchmark/extremem/ArrayletOflong.java | 10 +++---- .../corretto/benchmark/extremem/Util.java | 30 ++++++++++++------- .../benchmark/hyperalloc/ObjectStore.java | 6 +++- .../benchmark/hyperalloc/SimpleRunner.java | 8 +++-- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/Arraylet.java b/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/Arraylet.java index 3d7112a..10aba32 100644 --- a/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/Arraylet.java +++ b/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/Arraylet.java @@ -133,7 +133,7 @@ final BaseType get(int at) { BaseType[] elements = (BaseType []) fan_out_node[at / max_length]; return elements[at % max_length]; } - + final void set(int at, BaseType value) { if ((at < 0) || (at >= length)) { Exception x = new ArrayIndexOutOfBoundsException(at); @@ -189,7 +189,6 @@ public static void main(String args[]) { } } catch (Exception x) { Trace.debug("caught exception during first batch"); - x.printStackTrace(); } try { @@ -204,7 +203,7 @@ public static void main(String args[]) { } } catch (Exception x) { Trace.debug("caught exception during second batch"); - x.printStackTrace(); + Util.printException(x); } try { @@ -219,7 +218,7 @@ public static void main(String args[]) { } } catch (Exception x) { Trace.debug("caught exception during third batch"); - x.printStackTrace(); + Util.printException(x); } } -} \ No newline at end of file +} diff --git a/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/ArrayletOflong.java b/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/ArrayletOflong.java index 36d0508..390d62e 100644 --- a/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/ArrayletOflong.java +++ b/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/ArrayletOflong.java @@ -137,7 +137,7 @@ final long get(int at) { long[] elements = (long []) fan_out_node[at / max_length]; return elements[at % max_length]; } - + final void set(int at, long value) { if ((at < 0) || (at >= length)) { Exception x = new ArrayIndexOutOfBoundsException(at); @@ -195,7 +195,7 @@ public static void main(String args[]) { } } catch (Exception x) { Trace.debug("caught exception during first batch"); - x.printStackTrace(); + Util.printException(x); } try { @@ -210,7 +210,7 @@ public static void main(String args[]) { } } catch (Exception x) { Trace.debug("caught exception during second batch"); - x.printStackTrace(); + Util.printException(x); } try { @@ -225,7 +225,7 @@ public static void main(String args[]) { } } catch (Exception x) { Trace.debug("caught exception during third batch"); - x.printStackTrace(); + Util.printException(x); } } -} \ No newline at end of file +} diff --git a/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/Util.java b/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/Util.java index fc9dd06..0240589 100644 --- a/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/Util.java +++ b/Extremem/src/main/java/com/amazon/corretto/benchmark/extremem/Util.java @@ -4,6 +4,8 @@ package com.amazon.corretto.benchmark.extremem; import java.util.Collection; +import java.util.logging.Logger; +import java.util.logging.Level; class Util { @@ -31,6 +33,8 @@ class Util { static final int InitialHashMapArraySize = 16; + static Logger logger = Logger.getGlobal(); + /* * Generic utilities */ @@ -44,14 +48,18 @@ static void internalError(String msg) { static void fatalException(String msg, Throwable t) { System.err.print("Intecepted fatal exception: "); System.err.println(msg); - t.printStackTrace(); + printException(t); System.exit(-1); } + static void printException(Throwable t) { + logger.log(Level.INFO, t.getMessage(), t); + } + // Use this service, without a message, when there is a strong // likelihood that we are out of memory and any attempt to print // a message will result in exceptions, thereby circumventing the exit - // attempt. + // attempt. static void severeInternalError() { System.exit(-1); } @@ -174,7 +182,7 @@ static void ephemeralRSBArray(ExtrememThread t, int len, int element_size) { log.accumulate(LifeSpan.Ephemeral, MemoryFlavor.ArrayRSB, Grow, len * element_size); } - + static void abandonEphemeralRSBArray(ExtrememThread t, int len, int element_size) { MemoryLog garbage = t.garbageLog(); @@ -242,7 +250,7 @@ static void tallyTreeMap(long tree_entries, log.accumulate (ls, MemoryFlavor.ObjectReference, p, tree_entries * 5); log.accumulate (ls, MemoryFlavor.ObjectRSB, p, tree_entries * Util.SizeOfBoolean); - } + } static void createTreeNode(ExtrememThread t, LifeSpan ls) { Polarity Grow = Polarity.Expand; @@ -315,7 +323,7 @@ static void abandonHashMap(ExtrememThread t, LifeSpan ls, // Account for referenced array garbage.accumulate(ls, MemoryFlavor.ArrayObject, Grow, 1); garbage.accumulate(ls, MemoryFlavor.ArrayReference, Grow, capacity); - + tallyHashNodes(garbage, ls, Grow, size); } @@ -345,7 +353,7 @@ static void tallyHashNodes(MemoryLog l, LifeSpan ls, Polarity p, int n) { l.accumulate(ls, MemoryFlavor.PlainObject, p, n); l.accumulate (ls, MemoryFlavor.ObjectReference, p, n * 3); l.accumulate (ls, MemoryFlavor.ObjectRSB, p, n * Util.SizeOfInt); - + } // Usie addHashEntry and abandonHashEntry to adjust the number of @@ -356,7 +364,7 @@ static void addHashEntry(ExtrememThread t, LifeSpan ls) { Polarity Grow = Polarity.Expand; // Identify that one node of HashMap representation has become garbage. // Each node consists of a key, content, and next reference fields - // and an int hash_code field. + // and an int hash_code field. log.accumulate (ls, MemoryFlavor.PlainObject, Grow, 1); log.accumulate (ls, MemoryFlavor.ObjectReference, Grow, 3); log.accumulate (ls, MemoryFlavor.ObjectRSB, Grow, Util.SizeOfInt); @@ -367,7 +375,7 @@ static void abandonHashEntry(ExtrememThread t, LifeSpan ls) { Polarity Grow = Polarity.Expand; // Identify that one node of HashMap representation has become garbage. // Each node consists of a key, content, and next reference fields - // and an int hash_code field. + // and an int hash_code field. garbage.accumulate (ls, MemoryFlavor.PlainObject, Grow, 1); garbage.accumulate (ls, MemoryFlavor.ObjectReference, Grow, 3); garbage.accumulate (ls, MemoryFlavor.ObjectRSB, Grow, Util.SizeOfInt); @@ -420,7 +428,7 @@ static void tallyHashMap(MemoryLog log, LifeSpan ls, Polarity p, /* * Memory accounting utilities for HashSet */ - + /* Account for the HashSet representations associated with name and * descriptor indexes used for Product lookups. This accounting * does not include memory to represent the individual Long @@ -500,7 +508,7 @@ static int ephemeralStringBuilderAppend(ExtrememThread t, } // Discard the StringBuilder and its backing store. Allocate string - // and its backing store. + // and its backing store. static void ephemeralStringBuilderToString(ExtrememThread t, int count, int capacity) { MemoryLog garbage = t.garbageLog(); @@ -746,4 +754,4 @@ static void tallyStrings(MemoryLog log, LifeSpan ls, Polarity p, log.accumulate(ls, MemoryFlavor.ArrayObject, p, string_count); log.accumulate(ls, MemoryFlavor.StringData, p, cumulative_len); } -} \ No newline at end of file +} diff --git a/HyperAlloc/src/main/java/com/amazon/corretto/benchmark/hyperalloc/ObjectStore.java b/HyperAlloc/src/main/java/com/amazon/corretto/benchmark/hyperalloc/ObjectStore.java index d532655..ea0d9b0 100644 --- a/HyperAlloc/src/main/java/com/amazon/corretto/benchmark/hyperalloc/ObjectStore.java +++ b/HyperAlloc/src/main/java/com/amazon/corretto/benchmark/hyperalloc/ObjectStore.java @@ -9,6 +9,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Supplier; +import java.util.logging.Level; +import java.util.logging.Logger; /** * The object store for long lived object. The objects are stored in a list of object lists. Objects from one list may @@ -40,6 +42,8 @@ public class ObjectStore implements Runnable { private AtomicLong currentSize; private boolean running; + static Logger logger = Logger.getGlobal(); + public ObjectStore(final int sizeLimitInMb) { this(sizeLimitInMb, DEFAULT_PRUNE_RATIO, DEFAULT_RESHUFFLE_RATIO); } @@ -127,7 +131,7 @@ public void run() { Thread.sleep(INTERVAL_IN_MS); } catch (InterruptedException e) { - e.printStackTrace(); + logger.log(Level.SEVERE, e.getMessage(), e); System.exit(1); } } diff --git a/HyperAlloc/src/main/java/com/amazon/corretto/benchmark/hyperalloc/SimpleRunner.java b/HyperAlloc/src/main/java/com/amazon/corretto/benchmark/hyperalloc/SimpleRunner.java index 1b65b4b..44e9b10 100644 --- a/HyperAlloc/src/main/java/com/amazon/corretto/benchmark/hyperalloc/SimpleRunner.java +++ b/HyperAlloc/src/main/java/com/amazon/corretto/benchmark/hyperalloc/SimpleRunner.java @@ -13,6 +13,8 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -29,6 +31,8 @@ public SimpleRunner(SimpleRunConfig config) { this.config = config; } + static Logger logger = Logger.getGlobal(); + @Override public void start() { try { @@ -58,7 +62,7 @@ public void start() { r.get(); } } catch (ExecutionException ex) { - ex.printStackTrace(); + logger.log(Level.SEVERE, ex.getMessage(), ex); printResult(-1); System.exit(1); } @@ -181,7 +185,7 @@ public void run() { } } catch (IOException ioe) { System.err.println("Cannot write to allocation log: " + allocationLogFile); - ioe.printStackTrace(System.err); + logger.log(Level.SEVERE, ioe.getMessage(), ioe); } catch (InterruptedException iee) { Thread.currentThread().interrupt(); }