mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8245756: Reduce bootstrap cost of StringConcatFactory prependers
Reviewed-by: forax, psandoz
This commit is contained in:
parent
6e1403480a
commit
5200d162bc
4 changed files with 40 additions and 19 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -188,12 +188,12 @@ final class StringConcatHelper {
|
||||||
* @param indexCoder final char index in the buffer, along with coder packed
|
* @param indexCoder final char index in the buffer, along with coder packed
|
||||||
* into higher bits.
|
* into higher bits.
|
||||||
* @param buf buffer to append to
|
* @param buf buffer to append to
|
||||||
* @param prefix a constant to prepend before value
|
|
||||||
* @param value boolean value to encode
|
* @param value boolean value to encode
|
||||||
|
* @param prefix a constant to prepend before value
|
||||||
* @param suffix a constant to prepend after value
|
* @param suffix a constant to prepend after value
|
||||||
* @return updated index (coder value retained)
|
* @return updated index (coder value retained)
|
||||||
*/
|
*/
|
||||||
static long prepend(long indexCoder, byte[] buf, String prefix, boolean value, String suffix) {
|
static long prepend(long indexCoder, byte[] buf, boolean value, String prefix, String suffix) {
|
||||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||||
indexCoder = prepend(indexCoder, buf, value);
|
indexCoder = prepend(indexCoder, buf, value);
|
||||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||||
|
@ -207,12 +207,12 @@ final class StringConcatHelper {
|
||||||
* @param indexCoder final char index in the buffer, along with coder packed
|
* @param indexCoder final char index in the buffer, along with coder packed
|
||||||
* into higher bits.
|
* into higher bits.
|
||||||
* @param buf buffer to append to
|
* @param buf buffer to append to
|
||||||
* @param prefix a constant to prepend before value
|
|
||||||
* @param value boolean value to encode
|
* @param value boolean value to encode
|
||||||
|
* @param prefix a constant to prepend before value
|
||||||
* @param suffix a constant to prepend after value
|
* @param suffix a constant to prepend after value
|
||||||
* @return updated index (coder value retained)
|
* @return updated index (coder value retained)
|
||||||
*/
|
*/
|
||||||
static long prepend(long indexCoder, byte[] buf, String prefix, byte value, String suffix) {
|
static long prepend(long indexCoder, byte[] buf, byte value, String prefix, String suffix) {
|
||||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||||
indexCoder = prepend(indexCoder, buf, (int)value);
|
indexCoder = prepend(indexCoder, buf, (int)value);
|
||||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||||
|
@ -245,12 +245,12 @@ final class StringConcatHelper {
|
||||||
* @param indexCoder final char index in the buffer, along with coder packed
|
* @param indexCoder final char index in the buffer, along with coder packed
|
||||||
* into higher bits.
|
* into higher bits.
|
||||||
* @param buf buffer to append to
|
* @param buf buffer to append to
|
||||||
* @param prefix a constant to prepend before value
|
|
||||||
* @param value boolean value to encode
|
* @param value boolean value to encode
|
||||||
|
* @param prefix a constant to prepend before value
|
||||||
* @param suffix a constant to prepend after value
|
* @param suffix a constant to prepend after value
|
||||||
* @return updated index (coder value retained)
|
* @return updated index (coder value retained)
|
||||||
*/
|
*/
|
||||||
static long prepend(long indexCoder, byte[] buf, String prefix, char value, String suffix) {
|
static long prepend(long indexCoder, byte[] buf, char value, String prefix, String suffix) {
|
||||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||||
indexCoder = prepend(indexCoder, buf, value);
|
indexCoder = prepend(indexCoder, buf, value);
|
||||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||||
|
@ -264,12 +264,12 @@ final class StringConcatHelper {
|
||||||
* @param indexCoder final char index in the buffer, along with coder packed
|
* @param indexCoder final char index in the buffer, along with coder packed
|
||||||
* into higher bits.
|
* into higher bits.
|
||||||
* @param buf buffer to append to
|
* @param buf buffer to append to
|
||||||
* @param prefix a constant to prepend before value
|
|
||||||
* @param value boolean value to encode
|
* @param value boolean value to encode
|
||||||
|
* @param prefix a constant to prepend before value
|
||||||
* @param suffix a constant to prepend after value
|
* @param suffix a constant to prepend after value
|
||||||
* @return updated index (coder value retained)
|
* @return updated index (coder value retained)
|
||||||
*/
|
*/
|
||||||
static long prepend(long indexCoder, byte[] buf, String prefix, short value, String suffix) {
|
static long prepend(long indexCoder, byte[] buf, short value, String prefix, String suffix) {
|
||||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||||
indexCoder = prepend(indexCoder, buf, (int)value);
|
indexCoder = prepend(indexCoder, buf, (int)value);
|
||||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||||
|
@ -301,12 +301,12 @@ final class StringConcatHelper {
|
||||||
* @param indexCoder final char index in the buffer, along with coder packed
|
* @param indexCoder final char index in the buffer, along with coder packed
|
||||||
* into higher bits.
|
* into higher bits.
|
||||||
* @param buf buffer to append to
|
* @param buf buffer to append to
|
||||||
* @param prefix a constant to prepend before value
|
|
||||||
* @param value boolean value to encode
|
* @param value boolean value to encode
|
||||||
|
* @param prefix a constant to prepend before value
|
||||||
* @param suffix a constant to prepend after value
|
* @param suffix a constant to prepend after value
|
||||||
* @return updated index (coder value retained)
|
* @return updated index (coder value retained)
|
||||||
*/
|
*/
|
||||||
static long prepend(long indexCoder, byte[] buf, String prefix, int value, String suffix) {
|
static long prepend(long indexCoder, byte[] buf, int value, String prefix, String suffix) {
|
||||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||||
indexCoder = prepend(indexCoder, buf, value);
|
indexCoder = prepend(indexCoder, buf, value);
|
||||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||||
|
@ -338,12 +338,12 @@ final class StringConcatHelper {
|
||||||
* @param indexCoder final char index in the buffer, along with coder packed
|
* @param indexCoder final char index in the buffer, along with coder packed
|
||||||
* into higher bits.
|
* into higher bits.
|
||||||
* @param buf buffer to append to
|
* @param buf buffer to append to
|
||||||
* @param prefix a constant to prepend before value
|
|
||||||
* @param value boolean value to encode
|
* @param value boolean value to encode
|
||||||
|
* @param prefix a constant to prepend before value
|
||||||
* @param suffix a constant to prepend after value
|
* @param suffix a constant to prepend after value
|
||||||
* @return updated index (coder value retained)
|
* @return updated index (coder value retained)
|
||||||
*/
|
*/
|
||||||
static long prepend(long indexCoder, byte[] buf, String prefix, long value, String suffix) {
|
static long prepend(long indexCoder, byte[] buf, long value, String prefix, String suffix) {
|
||||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||||
indexCoder = prepend(indexCoder, buf, value);
|
indexCoder = prepend(indexCoder, buf, value);
|
||||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||||
|
@ -377,12 +377,12 @@ final class StringConcatHelper {
|
||||||
* @param indexCoder final char index in the buffer, along with coder packed
|
* @param indexCoder final char index in the buffer, along with coder packed
|
||||||
* into higher bits.
|
* into higher bits.
|
||||||
* @param buf buffer to append to
|
* @param buf buffer to append to
|
||||||
* @param prefix a constant to prepend before value
|
|
||||||
* @param value boolean value to encode
|
* @param value boolean value to encode
|
||||||
|
* @param prefix a constant to prepend before value
|
||||||
* @param suffix a constant to prepend after value
|
* @param suffix a constant to prepend after value
|
||||||
* @return updated index (coder value retained)
|
* @return updated index (coder value retained)
|
||||||
*/
|
*/
|
||||||
static long prepend(long indexCoder, byte[] buf, String prefix, String value, String suffix) {
|
static long prepend(long indexCoder, byte[] buf, String value, String prefix, String suffix) {
|
||||||
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
if (suffix != null) indexCoder = prepend(indexCoder, buf, suffix);
|
||||||
indexCoder = prepend(indexCoder, buf, value);
|
indexCoder = prepend(indexCoder, buf, value);
|
||||||
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
if (prefix != null) indexCoder = prepend(indexCoder, buf, prefix);
|
||||||
|
|
|
@ -2287,6 +2287,10 @@ public final class System {
|
||||||
return StringConcatHelper.initialCoder();
|
return StringConcatHelper.initialCoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long stringConcatMix(long lengthCoder, String constant) {
|
||||||
|
return StringConcatHelper.mix(lengthCoder, constant);
|
||||||
|
}
|
||||||
|
|
||||||
public Object classData(Class<?> c) {
|
public Object classData(Class<?> c) {
|
||||||
return c.getClassData();
|
return c.getClassData();
|
||||||
}
|
}
|
||||||
|
|
|
@ -624,7 +624,7 @@ public final class StringConcatFactory {
|
||||||
String constantValue = el.getValue();
|
String constantValue = el.getValue();
|
||||||
|
|
||||||
// Eagerly update the initialLengthCoder value
|
// Eagerly update the initialLengthCoder value
|
||||||
initialLengthCoder = (long)mixer(String.class).invoke(initialLengthCoder, constantValue);
|
initialLengthCoder = JLA.stringConcatMix(initialLengthCoder, constantValue);
|
||||||
|
|
||||||
if (pos < 0) {
|
if (pos < 0) {
|
||||||
// Collecting into prefixConstant
|
// Collecting into prefixConstant
|
||||||
|
@ -747,9 +747,11 @@ public final class StringConcatFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodHandle prepender(String prefix, Class<?> cl, String suffix) {
|
private static MethodHandle prepender(String prefix, Class<?> cl, String suffix) {
|
||||||
|
if (prefix == null && suffix == null) {
|
||||||
|
return NULL_PREPENDERS.computeIfAbsent(cl, NULL_PREPEND);
|
||||||
|
}
|
||||||
return MethodHandles.insertArguments(
|
return MethodHandles.insertArguments(
|
||||||
MethodHandles.insertArguments(
|
PREPENDERS.computeIfAbsent(cl, PREPEND), 3, prefix, suffix);
|
||||||
PREPENDERS.computeIfAbsent(cl, PREPEND), 2, prefix), 3, suffix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodHandle mixer(Class<?> cl) {
|
private static MethodHandle mixer(Class<?> cl) {
|
||||||
|
@ -762,7 +764,15 @@ public final class StringConcatFactory {
|
||||||
public MethodHandle apply(Class<?> c) {
|
public MethodHandle apply(Class<?> c) {
|
||||||
return JLA.stringConcatHelper("prepend",
|
return JLA.stringConcatHelper("prepend",
|
||||||
methodType(long.class, long.class, byte[].class,
|
methodType(long.class, long.class, byte[].class,
|
||||||
String.class, Wrapper.asPrimitiveType(c), String.class));
|
Wrapper.asPrimitiveType(c), String.class, String.class));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final Function<Class<?>, MethodHandle> NULL_PREPEND = new Function<>() {
|
||||||
|
@Override
|
||||||
|
public MethodHandle apply(Class<?> c) {
|
||||||
|
return MethodHandles.insertArguments(
|
||||||
|
PREPENDERS.computeIfAbsent(c, PREPEND), 3, (String)null, (String)null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -835,12 +845,14 @@ public final class StringConcatFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ConcurrentMap<Class<?>, MethodHandle> PREPENDERS;
|
private static final ConcurrentMap<Class<?>, MethodHandle> PREPENDERS;
|
||||||
|
private static final ConcurrentMap<Class<?>, MethodHandle> NULL_PREPENDERS;
|
||||||
private static final ConcurrentMap<Class<?>, MethodHandle> MIXERS;
|
private static final ConcurrentMap<Class<?>, MethodHandle> MIXERS;
|
||||||
private static final long INITIAL_CODER;
|
private static final long INITIAL_CODER;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
INITIAL_CODER = JLA.stringConcatInitialCoder();
|
INITIAL_CODER = JLA.stringConcatInitialCoder();
|
||||||
PREPENDERS = new ConcurrentHashMap<>();
|
PREPENDERS = new ConcurrentHashMap<>();
|
||||||
|
NULL_PREPENDERS = new ConcurrentHashMap<>();
|
||||||
MIXERS = new ConcurrentHashMap<>();
|
MIXERS = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -338,6 +338,11 @@ public interface JavaLangAccess {
|
||||||
*/
|
*/
|
||||||
long stringConcatInitialCoder();
|
long stringConcatInitialCoder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update lengthCoder for constant
|
||||||
|
*/
|
||||||
|
long stringConcatMix(long lengthCoder, String constant);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the class data associated with the given class.
|
* Get the class data associated with the given class.
|
||||||
* @param c the class
|
* @param c the class
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue