# HG changeset patch # User Doug Simon # Date 1407155285 -7200 # Node ID c53c0c153d73f8491fd35ed8ea6547c98b804b10 # Parent 58622d6b109711642782ccd4f8ab503659f67ad5 gracefully handle ConcurrentModificationException while iterating over system properties during initialization of the Debug class diff -r 58622d6b1097 -r c53c0c153d73 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java --- 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 metrics = new HashSet<>(); Set timers = new HashSet<>(); - for (Map.Entry 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 metrics, Set timers) { + do { + try { + for (Map.Entry 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