Mercurial > hg > truffle
changeset 16680:c53c0c153d73
gracefully handle ConcurrentModificationException while iterating over system properties during initialization of the Debug class
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 04 Aug 2014 14:28:05 +0200 |
parents | 58622d6b1097 |
children | 74123ce7599b |
files | graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java |
diffstat | 1 files changed, 21 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Mon Aug 04 14:26:29 2014 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Mon Aug 04 14:28:05 2014 +0200 @@ -1082,19 +1082,31 @@ static { Set<String> metrics = new HashSet<>(); Set<String> timers = new HashSet<>(); - for (Map.Entry<Object, Object> e : System.getProperties().entrySet()) { - String name = e.getKey().toString(); - if (name.startsWith(ENABLE_METRIC_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { - metrics.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length())); - } - if (name.startsWith(ENABLE_TIMER_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { - timers.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length())); - } - } + parseMetricAndTimerSystemProperties(metrics, timers); enabledMetrics = metrics.isEmpty() ? null : metrics; enabledTimers = timers.isEmpty() ? null : timers; } + protected static void parseMetricAndTimerSystemProperties(Set<String> metrics, Set<String> timers) { + do { + try { + for (Map.Entry<Object, Object> e : System.getProperties().entrySet()) { + String name = e.getKey().toString(); + if (name.startsWith(ENABLE_METRIC_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { + metrics.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length())); + } + if (name.startsWith(ENABLE_TIMER_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { + timers.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length())); + } + } + return; + } catch (ConcurrentModificationException e) { + // Iterating over the system properties may race with another thread that is + // updating the system properties. Simply try again in this case. + } + } while (true); + } + /** * Creates a {@linkplain DebugTimer timer} that is enabled iff debugging is * {@linkplain #isEnabled() enabled} or the system property whose name is formed by adding to