diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java index 51fb1cfdb3a..5f42cefb7a8 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java @@ -54,6 +54,7 @@ import java.util.List; import java.util.Set; import java.util.StringJoiner; +import com.oracle.svm.core.jdk.jfr.JfrTraceId; import org.graalvm.compiler.core.common.SuppressFBWarnings; import org.graalvm.compiler.core.common.calc.UnsignedMath; import org.graalvm.compiler.serviceprovider.JavaVersionUtil; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrFeature.java index d239fd01ad9..75ee2cb7d26 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrFeature.java @@ -43,7 +43,7 @@ public class JfrFeature implements Feature { @Override public void afterRegistration(AfterRegistrationAccess access) { - ImageSingletons.add(JfrRuntimeAccess.class, new JfrRuntimeAccessImpl()); + ImageSingletons.add(JfrRuntimeAccess.class, new JfrRuntimeAccessImpl(JfrTraceId.getTraceIdMap())); } @Override diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrRuntimeAccessImpl.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrRuntimeAccessImpl.java index 5c95de4965d..ecebc21afa1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrRuntimeAccessImpl.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrRuntimeAccessImpl.java @@ -34,6 +34,11 @@ import java.util.List; class JfrRuntimeAccessImpl implements JfrRuntimeAccess { private List> eventClasses = new ArrayList<>(); + private JfrTraceIdMap traceIdMap; + + public JfrRuntimeAccessImpl(JfrTraceIdMap traceIdMap) { + this.traceIdMap = traceIdMap; + } @Override public List> getEventClasses() { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrTraceId.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrTraceId.java new file mode 100644 index 00000000000..7d1b01921c2 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrTraceId.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.jfr; + +import com.oracle.svm.core.jdk.UninterruptibleUtils; +import org.graalvm.nativeimage.ImageSingletons; + +import java.util.concurrent.atomic.AtomicLong; + +public class JfrTraceId { + + private static AtomicLong classCounter = new AtomicLong(); + private static JfrTraceIdMap map = new JfrTraceIdMap(); + + public static JfrTraceIdMap getTraceIdMap() { + return map; + } + + private static void setUsedThisEpoch(Class clazz) { + throw new RuntimeException("Not yet implemented"); + } + + private static long traceId(Class clazz) { + return getTraceIdMap().getId(clazz); + } + + private static long setUsedAndGet(Class clazz) { + setUsedThisEpoch(clazz); + return traceId(clazz); + } + + public static long use(Class clazz) { + assert clazz != null; + return setUsedAndGet(clazz); + } + + public static void initId(Class clazz) { + if (clazz == null) { + return; + } + assert getTraceIdMap().getId(clazz) >= 0; + long nextId = classCounter.incrementAndGet(); + //System.out.println("New classId for: " + clazz.getName() + ": " + nextId); + getTraceIdMap().setId(clazz, nextId); + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrTraceIdMap.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrTraceIdMap.java new file mode 100644 index 00000000000..7773bc66647 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/jfr/JfrTraceIdMap.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.jfr; + +import java.util.HashMap; + +public class JfrTraceIdMap { + private HashMap map = new HashMap<>(); + + long getId(Object key) { + Long id = map.get(key); + if (id != null) { + return id.longValue(); + } else { + return -1; + } + } + + void setId(Object key, long id) { + map.put(key, id); + } +} diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ConfigurableClassInitialization.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ConfigurableClassInitialization.java index 91c313ff5f0..373d289f89f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ConfigurableClassInitialization.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ConfigurableClassInitialization.java @@ -40,6 +40,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import com.oracle.svm.core.jdk.jfr.JavaJfrUtils; +import com.oracle.svm.core.jdk.jfr.JfrTraceId; import org.graalvm.compiler.options.OptionKey; import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess; @@ -166,6 +167,7 @@ public class ConfigurableClassInitialization implements ClassInitializationSuppo * class initialization fails. */ private InitKind ensureClassInitialized(Class clazz, boolean allowErrors) { + JfrTraceId.initId(clazz); try { UNSAFE.ensureClassInitialized(clazz); return InitKind.BUILD_TIME;