diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/naming/QualifiedName.java b/org.eclipse.xtext/src/org/eclipse/xtext/naming/QualifiedName.java index 65cac8be6..de8ae22fd 100644 --- a/org.eclipse.xtext/src/org/eclipse/xtext/naming/QualifiedName.java +++ b/org.eclipse.xtext/src/org/eclipse/xtext/naming/QualifiedName.java @@ -36,7 +36,7 @@ public class QualifiedName implements Comparable { private QualifiedName lowerCase; - private static boolean USE_INTERNING = Boolean.getBoolean("xtext.qn.interning"); + static boolean USE_INTERNING = Boolean.getBoolean("xtext.qn.interning"); /** * The single existing empty QualifiedName. @@ -128,18 +128,15 @@ public class QualifiedName implements Comparable { } /** - * Returns string internal instance from string pool, if a system property {@code xtext.qn.interning} is set to {@code true}, or the - * same object otherwise. + * Returns string internal instance from string pool, if {@link #USE_INTERNING} is true, or the same object + * otherwise. *

- * Implementation notes: - *

    - *
  1. Interning {@link String} objects may affect performance, see bug 484215. - *
  2. Interning {@link String} objects is not recommended for older JVM's, because of possible perm gen memory explosion, see - * http://java-performance.info/string-intern-in-java-6-7-8/. - *
+ * {@link #USE_INTERNING} can be set by using the system property {@code xtext.qn.interning} or by calling + * {@link QualifiedNameInterning#enable()} / {@link QualifiedNameInterning#disable()}.
+ * The default value is false. */ private static String intern(String string) { - return USE_INTERNING? CommonUtil.intern(string) : string; + return USE_INTERNING ? CommonUtil.intern(string) : string; } /** diff --git a/org.eclipse.xtext/src/org/eclipse/xtext/naming/QualifiedNameInterning.java b/org.eclipse.xtext/src/org/eclipse/xtext/naming/QualifiedNameInterning.java new file mode 100644 index 000000000..8affdd61b --- /dev/null +++ b/org.eclipse.xtext/src/org/eclipse/xtext/naming/QualifiedNameInterning.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2022 itemis AG (http://www.itemis.eu) and others. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.xtext.naming; + +/** + * Provides methods for enabling and disabling the interning of strings used in {@link QualifiedName}. + *

+ * String interning is disabled by default. It can be enabled by setting the system property {@code xtext.qn.interning} + * to true or by calling {@link #enable()}. + *

+ * Caution: Setting the system property at runtime does not have an effect. Use {@link #enable()} to enable String + * interning at runtime. + * + * @since 2.26.0 + * + * @author Oliver Libutzki - Initial contribution and API + * + * @see QualifiedName#USE_INTERNING + * + */ +public final class QualifiedNameInterning { + + /** + * Private constructor to ensure that this class cannot be instantiated. + */ + private QualifiedNameInterning() { + } + + /** + * Enables the usage of a String pool for {@link QualifiedName QualifiedName's} segments. + *

+ * Note: {@link QualifiedName QualifiedNames} which are created before enabling are not affected. + *

+ * Caution: Interning {@link String} objects may affect performance, see bug 484215. + */ + public static void enable() { + QualifiedName.USE_INTERNING = true; + } + + /** + * Disables the usage of a String pool for {@link QualifiedName QualifiedName's} segments. + *

+ * Note: {@link QualifiedName QualifiedNames} which are created before disabling are not affected. + */ + public static void disable() { + QualifiedName.USE_INTERNING = false; + } + +}