diff -r 2c3cc4b01880 -r c16ac7a2eba4 src/jdk.jfr/share/classes/jdk/jfr/internal/EventControl.java --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventControl.java Wed Oct 30 16:14:56 2019 +0100 +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventControl.java Wed Oct 30 19:43:52 2019 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2019, 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 @@ -32,11 +32,7 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; import jdk.internal.module.Modules; import jdk.jfr.AnnotationElement; @@ -59,7 +55,14 @@ // holds SettingControl instances that need to be released // when a class is unloaded (to avoid memory leaks). public final class EventControl { - + final static class NamedControl { + public final String name; + public final Control control; + NamedControl(String name, Control control) { + this.name = name; + this.control = control; + } + } static final String FIELD_SETTING_PREFIX = "setting"; private static final Type TYPE_ENABLED = TypeLibrary.createType(EnabledSetting.class); private static final Type TYPE_THRESHOLD = TypeLibrary.createType(ThresholdSetting.class); @@ -67,24 +70,24 @@ private static final Type TYPE_PERIOD = TypeLibrary.createType(PeriodSetting.class); private static final Type TYPE_CUTOFF = TypeLibrary.createType(CutoffSetting.class); - private final List settingInfos = new ArrayList<>(); - private final Map eventControls = new HashMap<>(5); + private final ArrayList settingInfos = new ArrayList<>(); + private final ArrayList namedControls = new ArrayList<>(5); private final PlatformEventType type; private final String idName; EventControl(PlatformEventType eventType) { - eventControls.put(Enabled.NAME, defineEnabled(eventType)); + addControl(Enabled.NAME, defineEnabled(eventType)); if (eventType.hasDuration()) { - eventControls.put(Threshold.NAME, defineThreshold(eventType)); + addControl(Threshold.NAME, defineThreshold(eventType)); } if (eventType.hasStackTrace()) { - eventControls.put(StackTrace.NAME, defineStackTrace(eventType)); + addControl(StackTrace.NAME, defineStackTrace(eventType)); } if (eventType.hasPeriod()) { - eventControls.put(Period.NAME, definePeriod(eventType)); + addControl(Period.NAME, definePeriod(eventType)); } if (eventType.hasCutoff()) { - eventControls.put(Cutoff.NAME, defineCutoff(eventType)); + addControl(Cutoff.NAME, defineCutoff(eventType)); } ArrayList aes = new ArrayList<>(eventType.getAnnotationElements()); @@ -99,6 +102,19 @@ this.idName = String.valueOf(eventType.getId()); } + private boolean hasControl(String name) { + for (NamedControl nc : namedControls) { + if (name.equals(nc.name)) { + return true; + } + } + return false; + } + + private void addControl(String name, Control control) { + namedControls.add(new NamedControl(name, control)); + } + static void remove(PlatformEventType type, List aes, Class clazz) { long id = Type.getTypeId(clazz); for (AnnotationElement a : type.getAnnotationElements()) { @@ -131,7 +147,8 @@ if (n != null) { name = n.value(); } - if (!eventControls.containsKey(name)) { + + if (!hasControl(name)) { defineSetting((Class) settingClass, m, type, name); } } @@ -163,7 +180,7 @@ } } aes.trimToSize(); - eventControls.put(settingName, si.settingControl); + addControl(settingName, si.settingControl); eventType.add(PrivateAccess.getInstance().newSettingDescriptor(settingType, settingName, defaultValue, aes)); settingInfos.add(si); } @@ -247,9 +264,9 @@ } void disable() { - for (Control c : eventControls.values()) { - if (c instanceof EnabledSetting) { - c.setValueSafe("false"); + for (NamedControl nc : namedControls) { + if (nc.control instanceof EnabledSetting) { + nc.control.setValueSafe("false"); return; } } @@ -259,24 +276,23 @@ if (!type.isRegistered()) { return; } - for (Map.Entry entry : eventControls.entrySet()) { - Control c = entry.getValue(); - if (Utils.isSettingVisible(c, type.hasEventHook())) { - String value = c.getLastValue(); + ActiveSettingEvent event = ActiveSettingEvent.EVENT.get(); + for (NamedControl nc : namedControls) { + if (Utils.isSettingVisible(nc.control, type.hasEventHook())) { + String value = nc.control.getLastValue(); if (value == null) { - value = c.getDefaultValue(); + value = nc.control.getDefaultValue(); } - ActiveSettingEvent ase = new ActiveSettingEvent(); - ase.id = type.getId(); - ase.name = entry.getKey(); - ase.value = value; - ase.commit(); + event.id = type.getId(); + event.name = nc.name; + event.value = value; + event.commit(); } } } - public Set> getEntries() { - return eventControls.entrySet(); + public ArrayList getNamedControls() { + return namedControls; } public PlatformEventType getEventType() {