--- /dev/null 2016-10-25 08:46:44.038854975 +0200
+++ new/src/share/classes/sun/evtracing/processing/MetadataStore.java 2016-10-25 10:40:44.066800620 +0200
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014, 2015, Dynatrace and/or its affiliates. All rights reserved.
+ *
+ * This file is part of the Lock Contention Tracing Subsystem for the HotSpot
+ * Virtual Machine, which is developed at Christian Doppler Laboratory on
+ * Monitoring and Evolution of Very-Large-Scale Software Systems. Please
+ * contact us at if you need additional information
+ * or have any questions.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work. If not, see .
+ *
+ */
+package sun.evtracing.processing;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import sun.evtracing.parser.metadata.JavaClass;
+import sun.evtracing.parser.metadata.JavaMethod;
+import sun.evtracing.parser.metadata.JavaStack;
+
+public class MetadataStore {
+
+ private static final long UNKNOWN_STACK_ID = 0;
+
+ private Map classes = new HashMap<>();
+ private Map methods = new HashMap<>();
+ private Map stacks = new HashMap<>();
+
+ public JavaClass getOrAddClass(long classId) {
+ if (classId == JavaClass.SPECIAL_ID) {
+ return JavaClass.UNKNOWN;
+ }
+ return classes.computeIfAbsent(classId, k -> new JavaClass(k));
+ }
+
+ public JavaMethod getOrAddMethod(long methodId) {
+ if (methodId == JavaMethod.SPECIAL_ID) {
+ return JavaMethod.UNKNOWN;
+ }
+ return methods.computeIfAbsent(methodId, m -> new JavaMethod(m));
+ }
+
+ public JavaStack getOrAddStack(long stackId) {
+ if (stackId == UNKNOWN_STACK_ID) {
+ return JavaStack.UNKNOWN;
+ }
+ return stacks.computeIfAbsent(stackId, s -> new JavaStack());
+ }
+
+ public void purgeUnloadedClassesFrom(long classLoader) {
+ classes.values().removeIf(c -> c.classLoader() == classLoader);
+ methods.values().removeIf(m -> m.clazz().classLoader() == classLoader);
+
+ // Some stacks are not resolved immediately and thus remain unset for
+ // considerable time. One example is when a monitor is exited temporarily
+ // for Object.wait(), but the event refers to the actual lock site which can
+ // only be determined later when the monitor is actually exited. Obviously,
+ // such stacks can never be affected by class unloads.
+ // If a stack was resolved immediately, but we missed it because of a broken
+ // event order, this is a bug and we can't detect it.
+ stacks.values().removeIf(st -> st.isSet() && st.hasMethodFromClassLoader(classLoader));
+ }
+}