mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
Merge
This commit is contained in:
commit
88d610826b
177 changed files with 4477 additions and 1750 deletions
|
@ -25,25 +25,21 @@
|
|||
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.loader.BootLoader;
|
||||
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||
import jdk.internal.org.objectweb.asm.FieldVisitor;
|
||||
import jdk.internal.org.objectweb.asm.MethodVisitor;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
import sun.invoke.util.ValueConversions;
|
||||
import sun.invoke.util.Wrapper;
|
||||
|
||||
import java.lang.invoke.LambdaForm.NamedFunction;
|
||||
import java.lang.invoke.MethodHandles.Lookup;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.invoke.LambdaForm.BasicType;
|
||||
import static java.lang.invoke.LambdaForm.BasicType.*;
|
||||
import static java.lang.invoke.MethodHandleStatics.*;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||
import static java.lang.invoke.LambdaForm.BasicType.V_TYPE_NUM;
|
||||
import static java.lang.invoke.LambdaForm.BasicType.V_TYPE_NUM;
|
||||
import static java.lang.invoke.LambdaForm.BasicType.V_TYPE_NUM;
|
||||
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
||||
import static java.lang.invoke.MethodHandleNatives.Constants.*;
|
||||
import static java.lang.invoke.MethodHandleStatics.newInternalError;
|
||||
import static java.lang.invoke.MethodHandleStatics.uncaughtException;
|
||||
|
||||
/**
|
||||
* The flavor of method handle which emulates an invoke instruction
|
||||
|
@ -56,7 +52,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
|
||||
/*non-public*/ BoundMethodHandle(MethodType type, LambdaForm form) {
|
||||
super(type, form);
|
||||
assert(speciesData() == speciesData(form));
|
||||
assert(speciesData() == speciesDataFor(form));
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -70,13 +66,13 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
case L_TYPE:
|
||||
return bindSingle(type, form, x); // Use known fast path.
|
||||
case I_TYPE:
|
||||
return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(I_TYPE).constructor().invokeBasic(type, form, ValueConversions.widenSubword(x));
|
||||
return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(I_TYPE_NUM).factory().invokeBasic(type, form, ValueConversions.widenSubword(x));
|
||||
case J_TYPE:
|
||||
return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(J_TYPE).constructor().invokeBasic(type, form, (long) x);
|
||||
return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(J_TYPE_NUM).factory().invokeBasic(type, form, (long) x);
|
||||
case F_TYPE:
|
||||
return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(F_TYPE).constructor().invokeBasic(type, form, (float) x);
|
||||
return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(F_TYPE_NUM).factory().invokeBasic(type, form, (float) x);
|
||||
case D_TYPE:
|
||||
return (BoundMethodHandle) SpeciesData.EMPTY.extendWith(D_TYPE).constructor().invokeBasic(type, form, (double) x);
|
||||
return (BoundMethodHandle) SPECIALIZER.topSpecies().extendWith(D_TYPE_NUM).factory().invokeBasic(type, form, (double) x);
|
||||
default : throw newInternalError("unexpected xtype: " + xtype);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
|
@ -98,6 +94,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
BoundMethodHandle bindArgumentL(int pos, Object value) {
|
||||
return editor().bindArgumentL(this, pos, value);
|
||||
}
|
||||
|
||||
/*non-public*/
|
||||
BoundMethodHandle bindArgumentI(int pos, int value) {
|
||||
return editor().bindArgumentI(this, pos, value);
|
||||
|
@ -114,7 +111,6 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
BoundMethodHandle bindArgumentD(int pos, double value) {
|
||||
return editor().bindArgumentD(this, pos, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
BoundMethodHandle rebind() {
|
||||
if (!tooComplex()) {
|
||||
|
@ -137,28 +133,29 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
static BoundMethodHandle makeReinvoker(MethodHandle target) {
|
||||
LambdaForm form = DelegatingMethodHandle.makeReinvokerForm(
|
||||
target, MethodTypeForm.LF_REBIND,
|
||||
Species_L.SPECIES_DATA, Species_L.SPECIES_DATA.getterFunction(0));
|
||||
Species_L.BMH_SPECIES, Species_L.BMH_SPECIES.getterFunction(0));
|
||||
return Species_L.make(target.type(), form, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link SpeciesData} instance representing this BMH species. All subclasses must provide a
|
||||
* Return the {@link BoundMethodHandle.SpeciesData} instance representing this BMH species. All subclasses must provide a
|
||||
* static field containing this value, and they must accordingly implement this method.
|
||||
*/
|
||||
/*non-public*/ abstract SpeciesData speciesData();
|
||||
/*non-public*/ abstract BoundMethodHandle.SpeciesData speciesData();
|
||||
|
||||
/*non-public*/ static SpeciesData speciesData(LambdaForm form) {
|
||||
/*non-public*/ static BoundMethodHandle.SpeciesData speciesDataFor(LambdaForm form) {
|
||||
Object c = form.names[0].constraint;
|
||||
if (c instanceof SpeciesData)
|
||||
if (c instanceof SpeciesData) {
|
||||
return (SpeciesData) c;
|
||||
}
|
||||
// if there is no BMH constraint, then use the null constraint
|
||||
return SpeciesData.EMPTY;
|
||||
return SPECIALIZER.topSpecies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of fields in this BMH. Equivalent to speciesData().fieldCount().
|
||||
*/
|
||||
/*non-public*/ abstract int fieldCount();
|
||||
/*non-public*/ final int fieldCount() { return speciesData().fieldCount(); }
|
||||
|
||||
@Override
|
||||
Object internalProperties() {
|
||||
|
@ -167,7 +164,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
|
||||
@Override
|
||||
final String internalValues() {
|
||||
int count = speciesData().fieldCount();
|
||||
int count = fieldCount();
|
||||
if (count == 1) {
|
||||
return "[" + arg(0) + "]";
|
||||
}
|
||||
|
@ -180,17 +177,18 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
|
||||
/*non-public*/ final Object arg(int i) {
|
||||
try {
|
||||
switch (speciesData().fieldType(i)) {
|
||||
case L_TYPE: return speciesData().getters[i].invokeBasic(this);
|
||||
case I_TYPE: return (int) speciesData().getters[i].invokeBasic(this);
|
||||
case J_TYPE: return (long) speciesData().getters[i].invokeBasic(this);
|
||||
case F_TYPE: return (float) speciesData().getters[i].invokeBasic(this);
|
||||
case D_TYPE: return (double) speciesData().getters[i].invokeBasic(this);
|
||||
Class<?> fieldType = speciesData().fieldTypes().get(i);
|
||||
switch (BasicType.basicType(fieldType)) {
|
||||
case L_TYPE: return speciesData().getter(i).invokeBasic(this);
|
||||
case I_TYPE: return (int) speciesData().getter(i).invokeBasic(this);
|
||||
case J_TYPE: return (long) speciesData().getter(i).invokeBasic(this);
|
||||
case F_TYPE: return (float) speciesData().getter(i).invokeBasic(this);
|
||||
case D_TYPE: return (double) speciesData().getter(i).invokeBasic(this);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
}
|
||||
throw new InternalError("unexpected type: " + speciesData().typeChars+"."+i);
|
||||
throw new InternalError("unexpected type: " + speciesData().key()+"."+i);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -210,20 +208,21 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
|
||||
private // make it private to force users to access the enclosing class first
|
||||
static final class Species_L extends BoundMethodHandle {
|
||||
|
||||
final Object argL0;
|
||||
|
||||
private Species_L(MethodType mt, LambdaForm lf, Object argL0) {
|
||||
super(mt, lf);
|
||||
this.argL0 = argL0;
|
||||
}
|
||||
|
||||
@Override
|
||||
/*non-public*/ SpeciesData speciesData() {
|
||||
return SPECIES_DATA;
|
||||
return BMH_SPECIES;
|
||||
}
|
||||
@Override
|
||||
/*non-public*/ int fieldCount() {
|
||||
return 1;
|
||||
}
|
||||
/*non-public*/ static final SpeciesData SPECIES_DATA = new SpeciesData("L", Species_L.class);
|
||||
|
||||
/*non-public*/ static @Stable SpeciesData BMH_SPECIES;
|
||||
|
||||
/*non-public*/ static BoundMethodHandle make(MethodType mt, LambdaForm lf, Object argL0) {
|
||||
return new Species_L(mt, lf, argL0);
|
||||
}
|
||||
|
@ -234,7 +233,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
@Override
|
||||
/*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
|
||||
try {
|
||||
return (BoundMethodHandle) SPECIES_DATA.extendWith(L_TYPE).constructor().invokeBasic(mt, lf, argL0, narg);
|
||||
return (BoundMethodHandle) BMH_SPECIES.extendWith(L_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
}
|
||||
|
@ -242,7 +241,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
@Override
|
||||
/*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
|
||||
try {
|
||||
return (BoundMethodHandle) SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, argL0, narg);
|
||||
return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
}
|
||||
|
@ -250,7 +249,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
@Override
|
||||
/*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
|
||||
try {
|
||||
return (BoundMethodHandle) SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, argL0, narg);
|
||||
return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
}
|
||||
|
@ -258,7 +257,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
@Override
|
||||
/*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
|
||||
try {
|
||||
return (BoundMethodHandle) SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, argL0, narg);
|
||||
return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
}
|
||||
|
@ -266,7 +265,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
@Override
|
||||
/*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
|
||||
try {
|
||||
return (BoundMethodHandle) SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, argL0, narg);
|
||||
return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, argL0, narg);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
}
|
||||
|
@ -277,601 +276,177 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
// BMH species meta-data
|
||||
//
|
||||
|
||||
/**
|
||||
* Meta-data wrapper for concrete BMH types.
|
||||
* Each BMH type corresponds to a given sequence of basic field types (LIJFD).
|
||||
* The fields are immutable; their values are fully specified at object construction.
|
||||
* Each BMH type supplies an array of getter functions which may be used in lambda forms.
|
||||
* A BMH is constructed by cloning a shorter BMH and adding one or more new field values.
|
||||
* The shortest possible BMH has zero fields; its class is SimpleMethodHandle.
|
||||
* BMH species are not interrelated by subtyping, even though it would appear that
|
||||
* a shorter BMH could serve as a supertype of a longer one which extends it.
|
||||
*/
|
||||
static class SpeciesData {
|
||||
private final String typeChars;
|
||||
private final BasicType[] typeCodes;
|
||||
private final Class<? extends BoundMethodHandle> clazz;
|
||||
// Bootstrapping requires circular relations MH -> BMH -> SpeciesData -> MH
|
||||
// Therefore, we need a non-final link in the chain. Use array elements.
|
||||
@Stable private final MethodHandle[] constructor;
|
||||
@Stable private final MethodHandle[] getters;
|
||||
@Stable private final NamedFunction[] nominalGetters;
|
||||
@Stable private final SpeciesData[] extensions;
|
||||
/*non-public*/
|
||||
static final class SpeciesData extends ClassSpecializer<BoundMethodHandle, String, SpeciesData>.SpeciesData {
|
||||
// This array is filled in lazily, as new species come into being over time.
|
||||
@Stable final private SpeciesData[] extensions = new SpeciesData[ARG_TYPE_LIMIT];
|
||||
|
||||
/*non-public*/ int fieldCount() {
|
||||
return typeCodes.length;
|
||||
}
|
||||
/*non-public*/ BasicType fieldType(int i) {
|
||||
return typeCodes[i];
|
||||
}
|
||||
/*non-public*/ char fieldTypeChar(int i) {
|
||||
return typeChars.charAt(i);
|
||||
}
|
||||
String fieldSignature() {
|
||||
return typeChars;
|
||||
}
|
||||
public Class<? extends BoundMethodHandle> fieldHolder() {
|
||||
return clazz;
|
||||
}
|
||||
public String toString() {
|
||||
return "SpeciesData<"+fieldSignature()+">";
|
||||
public SpeciesData(Specializer outer, String key) {
|
||||
outer.super(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link LambdaForm.Name} containing a {@link LambdaForm.NamedFunction} that
|
||||
* represents a MH bound to a generic invoker, which in turn forwards to the corresponding
|
||||
* getter.
|
||||
*/
|
||||
NamedFunction getterFunction(int i) {
|
||||
NamedFunction nf = nominalGetters[i];
|
||||
assert(nf.memberDeclaringClassOrNull() == fieldHolder());
|
||||
assert(nf.returnType() == fieldType(i));
|
||||
return nf;
|
||||
@Override
|
||||
protected String deriveClassName() {
|
||||
String typeString = deriveTypeString();
|
||||
if (typeString.isEmpty()) {
|
||||
return SimpleMethodHandle.class.getName();
|
||||
}
|
||||
return BoundMethodHandle.class.getName() + "$Species_" + typeString;
|
||||
}
|
||||
|
||||
NamedFunction[] getterFunctions() {
|
||||
return nominalGetters;
|
||||
@Override
|
||||
protected List<Class<?>> deriveFieldTypes(String key) {
|
||||
ArrayList<Class<?>> types = new ArrayList<>(key.length());
|
||||
for (int i = 0; i < key.length(); i++) {
|
||||
types.add(basicType(key.charAt(i)).basicTypeClass());
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
MethodHandle[] getterHandles() { return getters; }
|
||||
|
||||
MethodHandle constructor() {
|
||||
return constructor[0];
|
||||
@Override
|
||||
protected String deriveTypeString() {
|
||||
// (If/when we have to add nominal types, just inherit the more complex default.)
|
||||
return key();
|
||||
}
|
||||
|
||||
static final SpeciesData EMPTY = new SpeciesData("", BoundMethodHandle.class);
|
||||
|
||||
SpeciesData(String types, Class<? extends BoundMethodHandle> clazz) {
|
||||
this.typeChars = types;
|
||||
this.typeCodes = basicTypes(types);
|
||||
this.clazz = clazz;
|
||||
if (!INIT_DONE) {
|
||||
this.constructor = new MethodHandle[1]; // only one ctor
|
||||
this.getters = new MethodHandle[types.length()];
|
||||
this.nominalGetters = new NamedFunction[types.length()];
|
||||
@Override
|
||||
protected MethodHandle deriveTransformHelper(MemberName transform, int whichtm) {
|
||||
if (whichtm == Specializer.TN_COPY_NO_EXTEND) {
|
||||
return factory();
|
||||
} else if (whichtm < ARG_TYPE_LIMIT) {
|
||||
return extendWith((byte) whichtm).factory();
|
||||
} else {
|
||||
this.constructor = Factory.makeCtors(clazz, types, null);
|
||||
this.getters = Factory.makeGetters(clazz, types, null);
|
||||
this.nominalGetters = Factory.makeNominalGetters(types, null, this.getters);
|
||||
}
|
||||
this.extensions = new SpeciesData[ARG_TYPE_LIMIT];
|
||||
}
|
||||
|
||||
private void initForBootstrap() {
|
||||
assert(!INIT_DONE);
|
||||
if (constructor() == null) {
|
||||
String types = typeChars;
|
||||
CACHE.put(types, this);
|
||||
Factory.makeCtors(clazz, types, this.constructor);
|
||||
Factory.makeGetters(clazz, types, this.getters);
|
||||
Factory.makeNominalGetters(types, this.nominalGetters, this.getters);
|
||||
throw newInternalError("bad transform");
|
||||
}
|
||||
}
|
||||
|
||||
private static final ConcurrentMap<String, SpeciesData> CACHE = new ConcurrentHashMap<>();
|
||||
private static final boolean INIT_DONE; // set after <clinit> finishes...
|
||||
|
||||
SpeciesData extendWith(byte type) {
|
||||
return extendWith(BasicType.basicType(type));
|
||||
@Override
|
||||
protected <X> List<X> deriveTransformHelperArguments(MemberName transform, int whichtm, List<X> args, List<X> fields) {
|
||||
assert(verifyTHAargs(transform, whichtm, args, fields));
|
||||
// The rule is really simple: Keep the first two arguments
|
||||
// the same, then put in the fields, then put any other argument.
|
||||
args.addAll(2, fields);
|
||||
return args;
|
||||
}
|
||||
|
||||
SpeciesData extendWith(BasicType type) {
|
||||
int ord = type.ordinal();
|
||||
SpeciesData d = extensions[ord];
|
||||
if (d != null) return d;
|
||||
extensions[ord] = d = get(typeChars+type.basicTypeChar());
|
||||
return d;
|
||||
}
|
||||
|
||||
private static SpeciesData get(String types) {
|
||||
return CACHE.computeIfAbsent(types, new Function<String, SpeciesData>() {
|
||||
@Override
|
||||
public SpeciesData apply(String types) {
|
||||
Class<? extends BoundMethodHandle> bmhcl = Factory.getConcreteBMHClass(types);
|
||||
// SpeciesData instantiation may throw VirtualMachineError because of
|
||||
// code cache overflow...
|
||||
SpeciesData speciesData = new SpeciesData(types, bmhcl);
|
||||
// CHM.computeIfAbsent ensures only one SpeciesData will be set
|
||||
// successfully on the concrete BMH class if ever
|
||||
Factory.setSpeciesDataToConcreteBMHClass(bmhcl, speciesData);
|
||||
// the concrete BMH class is published via SpeciesData instance
|
||||
// returned here only after it's SPECIES_DATA field is set
|
||||
return speciesData;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This is to be called when assertions are enabled. It checks whether SpeciesData for all of the statically
|
||||
* defined species subclasses of BoundMethodHandle has been added to the SpeciesData cache. See below in the
|
||||
* static initializer for
|
||||
*/
|
||||
static boolean speciesDataCachePopulated() {
|
||||
Class<BoundMethodHandle> rootCls = BoundMethodHandle.class;
|
||||
for (Class<?> c : rootCls.getDeclaredClasses()) {
|
||||
if (rootCls.isAssignableFrom(c)) {
|
||||
final Class<? extends BoundMethodHandle> cbmh = c.asSubclass(BoundMethodHandle.class);
|
||||
SpeciesData d = Factory.getSpeciesDataFromConcreteBMHClass(cbmh);
|
||||
assert(d != null) : cbmh.getName();
|
||||
assert(d.clazz == cbmh);
|
||||
assert(CACHE.get(d.typeChars) == d);
|
||||
}
|
||||
private boolean verifyTHAargs(MemberName transform, int whichtm, List<?> args, List<?> fields) {
|
||||
assert(transform == Specializer.BMH_TRANSFORMS.get(whichtm));
|
||||
assert(args.size() == transform.getMethodType().parameterCount());
|
||||
assert(fields.size() == this.fieldCount());
|
||||
final int MH_AND_LF = 2;
|
||||
if (whichtm == Specializer.TN_COPY_NO_EXTEND) {
|
||||
assert(transform.getMethodType().parameterCount() == MH_AND_LF);
|
||||
} else if (whichtm < ARG_TYPE_LIMIT) {
|
||||
assert(transform.getMethodType().parameterCount() == MH_AND_LF+1);
|
||||
final BasicType type = basicType((byte) whichtm);
|
||||
assert(transform.getParameterTypes()[MH_AND_LF] == type.basicTypeClass());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*non-public*/ SpeciesData extendWith(byte typeNum) {
|
||||
SpeciesData sd = extensions[typeNum];
|
||||
if (sd != null) return sd;
|
||||
sd = SPECIALIZER.findSpecies(key() + BasicType.basicType(typeNum).basicTypeChar());
|
||||
extensions[typeNum] = sd;
|
||||
return sd;
|
||||
}
|
||||
}
|
||||
|
||||
/*non-public*/
|
||||
static final Specializer SPECIALIZER = new Specializer();
|
||||
static {
|
||||
SimpleMethodHandle.BMH_SPECIES = BoundMethodHandle.SPECIALIZER.findSpecies("");
|
||||
Species_L.BMH_SPECIES = BoundMethodHandle.SPECIALIZER.findSpecies("L");
|
||||
}
|
||||
|
||||
/*non-public*/
|
||||
static final class Specializer extends ClassSpecializer<BoundMethodHandle, String, SpeciesData> {
|
||||
|
||||
private static final MemberName SPECIES_DATA_ACCESSOR;
|
||||
|
||||
static {
|
||||
// Pre-fill the BMH species-data cache with EMPTY and all BMH's inner subclasses.
|
||||
EMPTY.initForBootstrap();
|
||||
Species_L.SPECIES_DATA.initForBootstrap();
|
||||
// check that all static SpeciesData instances have been initialized
|
||||
assert speciesDataCachePopulated();
|
||||
// Note: Do not simplify this, because INIT_DONE must not be
|
||||
// a compile-time constant during bootstrapping.
|
||||
INIT_DONE = Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static SpeciesData getSpeciesData(String types) {
|
||||
return SpeciesData.get(types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generation of concrete BMH classes.
|
||||
*
|
||||
* A concrete BMH species is fit for binding a number of values adhering to a
|
||||
* given type pattern. Reference types are erased.
|
||||
*
|
||||
* BMH species are cached by type pattern.
|
||||
*
|
||||
* A BMH species has a number of fields with the concrete (possibly erased) types of
|
||||
* bound values. Setters are provided as an API in BMH. Getters are exposed as MHs,
|
||||
* which can be included as names in lambda forms.
|
||||
*/
|
||||
static class Factory {
|
||||
|
||||
private static final String JLO_SIG = "Ljava/lang/Object;";
|
||||
private static final String MH = "java/lang/invoke/MethodHandle";
|
||||
private static final String MH_SIG = "L"+MH+";";
|
||||
private static final String BMH = "java/lang/invoke/BoundMethodHandle";
|
||||
private static final String BMH_NAME = "java.lang.invoke.BoundMethodHandle";
|
||||
private static final String BMH_SIG = "L"+BMH+";";
|
||||
private static final String SPECIES_DATA = "java/lang/invoke/BoundMethodHandle$SpeciesData";
|
||||
private static final String SPECIES_DATA_SIG = "L"+SPECIES_DATA+";";
|
||||
private static final String STABLE_SIG = "Ljdk/internal/vm/annotation/Stable;";
|
||||
|
||||
private static final String SPECIES_PREFIX_NAME = "Species_";
|
||||
private static final String SPECIES_PREFIX_PATH = BMH + "$" + SPECIES_PREFIX_NAME;
|
||||
private static final String SPECIES_CLASS_PREFIX = BMH_NAME + "$" + SPECIES_PREFIX_NAME;
|
||||
|
||||
private static final String BMHSPECIES_DATA_EWI_SIG = "(B)" + SPECIES_DATA_SIG;
|
||||
private static final String MYSPECIES_DATA_SIG = "()" + SPECIES_DATA_SIG;
|
||||
private static final String INT_SIG = "()I";
|
||||
|
||||
private static final String SIG_INCIPIT = "(Ljava/lang/invoke/MethodType;Ljava/lang/invoke/LambdaForm;";
|
||||
|
||||
private static final String[] E_THROWABLE = new String[] { "java/lang/Throwable" };
|
||||
|
||||
private static final ConcurrentMap<String, Class<? extends BoundMethodHandle>> CLASS_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Get a concrete subclass of BMH for a given combination of bound types.
|
||||
*
|
||||
* @param types the type signature, wherein reference types are erased to 'L'
|
||||
* @return the concrete BMH class
|
||||
*/
|
||||
static Class<? extends BoundMethodHandle> getConcreteBMHClass(String types) {
|
||||
// CHM.computeIfAbsent ensures generateConcreteBMHClass is called
|
||||
// only once per key.
|
||||
return CLASS_CACHE.computeIfAbsent(
|
||||
types, new Function<String, Class<? extends BoundMethodHandle>>() {
|
||||
@Override
|
||||
public Class<? extends BoundMethodHandle> apply(String types) {
|
||||
String shortTypes = LambdaForm.shortenSignature(types);
|
||||
String className = SPECIES_CLASS_PREFIX + shortTypes;
|
||||
Class<?> c = BootLoader.loadClassOrNull(className);
|
||||
if (TRACE_RESOLVE) {
|
||||
System.out.println("[BMH_RESOLVE] " + shortTypes +
|
||||
(c != null ? " (success)" : " (fail)") );
|
||||
}
|
||||
if (c != null) {
|
||||
return c.asSubclass(BoundMethodHandle.class);
|
||||
} else {
|
||||
// Not pregenerated, generate the class
|
||||
return generateConcreteBMHClass(shortTypes, types);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a concrete subclass of BMH for a given combination of bound types.
|
||||
*
|
||||
* A concrete BMH species adheres to the following schema:
|
||||
*
|
||||
* <pre>
|
||||
* class Species_[[types]] extends BoundMethodHandle {
|
||||
* [[fields]]
|
||||
* final SpeciesData speciesData() { return SpeciesData.get("[[types]]"); }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* The {@code [[types]]} signature is precisely the string that is passed to this
|
||||
* method.
|
||||
*
|
||||
* The {@code [[fields]]} section consists of one field definition per character in
|
||||
* the type signature, adhering to the naming schema described in the definition of
|
||||
* {@link #makeFieldName}.
|
||||
*
|
||||
* For example, a concrete BMH species for two reference and one integral bound values
|
||||
* would have the following shape:
|
||||
*
|
||||
* <pre>
|
||||
* class BoundMethodHandle { ... private static
|
||||
* final class Species_LLI extends BoundMethodHandle {
|
||||
* final Object argL0;
|
||||
* final Object argL1;
|
||||
* final int argI2;
|
||||
* private Species_LLI(MethodType mt, LambdaForm lf, Object argL0, Object argL1, int argI2) {
|
||||
* super(mt, lf);
|
||||
* this.argL0 = argL0;
|
||||
* this.argL1 = argL1;
|
||||
* this.argI2 = argI2;
|
||||
* }
|
||||
* final SpeciesData speciesData() { return SPECIES_DATA; }
|
||||
* final int fieldCount() { return 3; }
|
||||
* @Stable static SpeciesData SPECIES_DATA; // injected afterwards
|
||||
* static BoundMethodHandle make(MethodType mt, LambdaForm lf, Object argL0, Object argL1, int argI2) {
|
||||
* return new Species_LLI(mt, lf, argL0, argL1, argI2);
|
||||
* }
|
||||
* final BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) {
|
||||
* return new Species_LLI(mt, lf, argL0, argL1, argI2);
|
||||
* }
|
||||
* final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
|
||||
* return SPECIES_DATA.extendWith(L_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg);
|
||||
* }
|
||||
* final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
|
||||
* return SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg);
|
||||
* }
|
||||
* final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
|
||||
* return SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg);
|
||||
* }
|
||||
* final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
|
||||
* return SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg);
|
||||
* }
|
||||
* public final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
|
||||
* return SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, argL0, argL1, argI2, narg);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @param types the type signature, wherein reference types are erased to 'L'
|
||||
* @return the generated concrete BMH class
|
||||
*/
|
||||
static Class<? extends BoundMethodHandle> generateConcreteBMHClass(String shortTypes,
|
||||
String types) {
|
||||
final String className = speciesInternalClassName(shortTypes);
|
||||
byte[] classFile = generateConcreteBMHClassBytes(shortTypes, types, className);
|
||||
|
||||
// load class
|
||||
InvokerBytecodeGenerator.maybeDump(className, classFile);
|
||||
Class<? extends BoundMethodHandle> bmhClass =
|
||||
UNSAFE.defineClass(className, classFile, 0, classFile.length,
|
||||
BoundMethodHandle.class.getClassLoader(), null)
|
||||
.asSubclass(BoundMethodHandle.class);
|
||||
|
||||
return bmhClass;
|
||||
}
|
||||
|
||||
static String speciesInternalClassName(String shortTypes) {
|
||||
return SPECIES_PREFIX_PATH + shortTypes;
|
||||
}
|
||||
|
||||
static byte[] generateConcreteBMHClassBytes(final String shortTypes,
|
||||
final String types, final String className) {
|
||||
final String sourceFile = SPECIES_PREFIX_NAME + shortTypes;
|
||||
|
||||
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
|
||||
final int NOT_ACC_PUBLIC = 0; // not ACC_PUBLIC
|
||||
cw.visit(V1_6, NOT_ACC_PUBLIC + ACC_FINAL + ACC_SUPER, className, null, BMH, null);
|
||||
cw.visitSource(sourceFile, null);
|
||||
|
||||
// emit static types and SPECIES_DATA fields
|
||||
FieldVisitor fw = cw.visitField(NOT_ACC_PUBLIC + ACC_STATIC, "SPECIES_DATA", SPECIES_DATA_SIG, null, null);
|
||||
fw.visitAnnotation(STABLE_SIG, true);
|
||||
fw.visitEnd();
|
||||
|
||||
// emit bound argument fields
|
||||
for (int i = 0; i < types.length(); ++i) {
|
||||
final char t = types.charAt(i);
|
||||
final String fieldName = makeFieldName(types, i);
|
||||
final String fieldDesc = t == 'L' ? JLO_SIG : String.valueOf(t);
|
||||
cw.visitField(ACC_FINAL, fieldName, fieldDesc, null, null).visitEnd();
|
||||
}
|
||||
|
||||
MethodVisitor mv;
|
||||
|
||||
// emit constructor
|
||||
mv = cw.visitMethod(ACC_PRIVATE, "<init>", makeSignature(types, true), null, null);
|
||||
mv.visitCode();
|
||||
mv.visitVarInsn(ALOAD, 0); // this
|
||||
mv.visitVarInsn(ALOAD, 1); // type
|
||||
mv.visitVarInsn(ALOAD, 2); // form
|
||||
|
||||
mv.visitMethodInsn(INVOKESPECIAL, BMH, "<init>", makeSignature("", true), false);
|
||||
|
||||
for (int i = 0, j = 0; i < types.length(); ++i, ++j) {
|
||||
// i counts the arguments, j counts corresponding argument slots
|
||||
char t = types.charAt(i);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(typeLoadOp(t), j + 3); // parameters start at 3
|
||||
mv.visitFieldInsn(PUTFIELD, className, makeFieldName(types, i), typeSig(t));
|
||||
if (t == 'J' || t == 'D') {
|
||||
++j; // adjust argument register access
|
||||
}
|
||||
}
|
||||
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
|
||||
// emit implementation of speciesData()
|
||||
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "speciesData", MYSPECIES_DATA_SIG, null, null);
|
||||
mv.visitCode();
|
||||
mv.visitFieldInsn(GETSTATIC, className, "SPECIES_DATA", SPECIES_DATA_SIG);
|
||||
mv.visitInsn(ARETURN);
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
|
||||
// emit implementation of fieldCount()
|
||||
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "fieldCount", INT_SIG, null, null);
|
||||
mv.visitCode();
|
||||
int fc = types.length();
|
||||
if (fc <= (ICONST_5 - ICONST_0)) {
|
||||
mv.visitInsn(ICONST_0 + fc);
|
||||
} else {
|
||||
mv.visitIntInsn(SIPUSH, fc);
|
||||
}
|
||||
mv.visitInsn(IRETURN);
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
// emit make() ...factory method wrapping constructor
|
||||
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_STATIC, "make", makeSignature(types, false), null, null);
|
||||
mv.visitCode();
|
||||
// make instance
|
||||
mv.visitTypeInsn(NEW, className);
|
||||
mv.visitInsn(DUP);
|
||||
// load mt, lf
|
||||
mv.visitVarInsn(ALOAD, 0); // type
|
||||
mv.visitVarInsn(ALOAD, 1); // form
|
||||
// load factory method arguments
|
||||
for (int i = 0, j = 0; i < types.length(); ++i, ++j) {
|
||||
// i counts the arguments, j counts corresponding argument slots
|
||||
char t = types.charAt(i);
|
||||
mv.visitVarInsn(typeLoadOp(t), j + 2); // parameters start at 3
|
||||
if (t == 'J' || t == 'D') {
|
||||
++j; // adjust argument register access
|
||||
}
|
||||
}
|
||||
|
||||
// finally, invoke the constructor and return
|
||||
mv.visitMethodInsn(INVOKESPECIAL, className, "<init>", makeSignature(types, true), false);
|
||||
mv.visitInsn(ARETURN);
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
|
||||
// emit copyWith()
|
||||
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "copyWith", makeSignature("", false), null, null);
|
||||
mv.visitCode();
|
||||
// make instance
|
||||
mv.visitTypeInsn(NEW, className);
|
||||
mv.visitInsn(DUP);
|
||||
// load mt, lf
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
// put fields on the stack
|
||||
emitPushFields(types, className, mv);
|
||||
// finally, invoke the constructor and return
|
||||
mv.visitMethodInsn(INVOKESPECIAL, className, "<init>", makeSignature(types, true), false);
|
||||
mv.visitInsn(ARETURN);
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
|
||||
// for each type, emit copyWithExtendT()
|
||||
for (BasicType type : BasicType.ARG_TYPES) {
|
||||
int ord = type.ordinal();
|
||||
char btChar = type.basicTypeChar();
|
||||
mv = cw.visitMethod(NOT_ACC_PUBLIC + ACC_FINAL, "copyWithExtend" + btChar, makeSignature(String.valueOf(btChar), false), null, E_THROWABLE);
|
||||
mv.visitCode();
|
||||
// return SPECIES_DATA.extendWith(t).constructor().invokeBasic(mt, lf, argL0, ..., narg)
|
||||
// obtain constructor
|
||||
mv.visitFieldInsn(GETSTATIC, className, "SPECIES_DATA", SPECIES_DATA_SIG);
|
||||
int iconstInsn = ICONST_0 + ord;
|
||||
assert(iconstInsn <= ICONST_5);
|
||||
mv.visitInsn(iconstInsn);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, SPECIES_DATA, "extendWith", BMHSPECIES_DATA_EWI_SIG, false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, SPECIES_DATA, "constructor", "()" + MH_SIG, false);
|
||||
// load mt, lf
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
// put fields on the stack
|
||||
emitPushFields(types, className, mv);
|
||||
// put narg on stack
|
||||
mv.visitVarInsn(typeLoadOp(btChar), 3);
|
||||
// finally, invoke the constructor and return
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, MH, "invokeBasic", makeSignature(types + btChar, false), false);
|
||||
mv.visitInsn(ARETURN);
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
||||
cw.visitEnd();
|
||||
|
||||
return cw.toByteArray();
|
||||
}
|
||||
|
||||
private static int typeLoadOp(char t) {
|
||||
switch (t) {
|
||||
case 'L': return ALOAD;
|
||||
case 'I': return ILOAD;
|
||||
case 'J': return LLOAD;
|
||||
case 'F': return FLOAD;
|
||||
case 'D': return DLOAD;
|
||||
default : throw newInternalError("unrecognized type " + t);
|
||||
}
|
||||
}
|
||||
|
||||
private static void emitPushFields(String types, String className, MethodVisitor mv) {
|
||||
for (int i = 0; i < types.length(); ++i) {
|
||||
char tc = types.charAt(i);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, className, makeFieldName(types, i), typeSig(tc));
|
||||
}
|
||||
}
|
||||
|
||||
static String typeSig(char t) {
|
||||
return t == 'L' ? JLO_SIG : String.valueOf(t);
|
||||
}
|
||||
|
||||
//
|
||||
// Getter MH generation.
|
||||
//
|
||||
|
||||
private static MethodHandle makeGetter(Class<?> cbmhClass, String types, int index) {
|
||||
String fieldName = makeFieldName(types, index);
|
||||
Class<?> fieldType = Wrapper.forBasicType(types.charAt(index)).primitiveType();
|
||||
try {
|
||||
return LOOKUP.findGetter(cbmhClass, fieldName, fieldType);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw newInternalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
static MethodHandle[] makeGetters(Class<?> cbmhClass, String types, MethodHandle[] mhs) {
|
||||
if (mhs == null) mhs = new MethodHandle[types.length()];
|
||||
for (int i = 0; i < mhs.length; ++i) {
|
||||
mhs[i] = makeGetter(cbmhClass, types, i);
|
||||
assert(mhs[i].internalMemberName().getDeclaringClass() == cbmhClass);
|
||||
}
|
||||
return mhs;
|
||||
}
|
||||
|
||||
static MethodHandle[] makeCtors(Class<? extends BoundMethodHandle> cbmh, String types, MethodHandle mhs[]) {
|
||||
if (mhs == null) mhs = new MethodHandle[1];
|
||||
if (types.equals("")) return mhs; // hack for empty BMH species
|
||||
mhs[0] = makeCbmhCtor(cbmh, types);
|
||||
return mhs;
|
||||
}
|
||||
|
||||
static NamedFunction[] makeNominalGetters(String types, NamedFunction[] nfs, MethodHandle[] getters) {
|
||||
if (nfs == null) nfs = new NamedFunction[types.length()];
|
||||
for (int i = 0; i < nfs.length; ++i) {
|
||||
nfs[i] = new NamedFunction(getters[i]);
|
||||
}
|
||||
return nfs;
|
||||
}
|
||||
|
||||
//
|
||||
// Auxiliary methods.
|
||||
//
|
||||
|
||||
static SpeciesData getSpeciesDataFromConcreteBMHClass(Class<? extends BoundMethodHandle> cbmh) {
|
||||
try {
|
||||
Field F_SPECIES_DATA = cbmh.getDeclaredField("SPECIES_DATA");
|
||||
return (SpeciesData) F_SPECIES_DATA.get(null);
|
||||
SPECIES_DATA_ACCESSOR = IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BoundMethodHandle.class,
|
||||
"speciesData", MethodType.methodType(BoundMethodHandle.SpeciesData.class));
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw newInternalError(ex);
|
||||
throw newInternalError("Bootstrap link error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void setSpeciesDataToConcreteBMHClass(Class<? extends BoundMethodHandle> cbmh, SpeciesData speciesData) {
|
||||
private Specializer() {
|
||||
super( // Reified type parameters:
|
||||
BoundMethodHandle.class, String.class, BoundMethodHandle.SpeciesData.class,
|
||||
// Principal constructor type:
|
||||
MethodType.methodType(void.class, MethodType.class, LambdaForm.class),
|
||||
// Required linkage between class and species:
|
||||
SPECIES_DATA_ACCESSOR,
|
||||
"BMH_SPECIES",
|
||||
BMH_TRANSFORMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String topSpeciesKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BoundMethodHandle.SpeciesData newSpeciesData(String key) {
|
||||
return new BoundMethodHandle.SpeciesData(this, key);
|
||||
}
|
||||
|
||||
static final List<MemberName> BMH_TRANSFORMS;
|
||||
static final int TN_COPY_NO_EXTEND = V_TYPE_NUM;
|
||||
static {
|
||||
final Class<BoundMethodHandle> BMH = BoundMethodHandle.class;
|
||||
// copyWithExtendLIJFD + copyWith
|
||||
try {
|
||||
Field F_SPECIES_DATA = cbmh.getDeclaredField("SPECIES_DATA");
|
||||
// ## FIXME: annotation parser can't create proxy classes until module system is fully initialzed
|
||||
// assert F_SPECIES_DATA.getDeclaredAnnotation(Stable.class) != null;
|
||||
F_SPECIES_DATA.set(null, speciesData);
|
||||
BMH_TRANSFORMS = List.of(
|
||||
IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendL", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, Object.class)),
|
||||
IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendI", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, int.class)),
|
||||
IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendJ", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, long.class)),
|
||||
IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendF", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, float.class)),
|
||||
IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWithExtendD", MethodType.methodType(BMH, MethodType.class, LambdaForm.class, double.class)),
|
||||
IMPL_LOOKUP.resolveOrFail(REF_invokeVirtual, BMH, "copyWith", MethodType.methodType(BMH, MethodType.class, LambdaForm.class))
|
||||
);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw newInternalError(ex);
|
||||
throw newInternalError("Failed resolving copyWith methods", ex);
|
||||
}
|
||||
|
||||
// as it happens, there is one transform per BasicType including V_TYPE
|
||||
assert(BMH_TRANSFORMS.size() == TYPE_LIMIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Field names in concrete BMHs adhere to this pattern:
|
||||
* arg + type + index
|
||||
* where type is a single character (L, I, J, F, D).
|
||||
* Generation of concrete BMH classes.
|
||||
*
|
||||
* A concrete BMH species is fit for binding a number of values adhering to a
|
||||
* given type pattern. Reference types are erased.
|
||||
*
|
||||
* BMH species are cached by type pattern.
|
||||
*
|
||||
* A BMH species has a number of fields with the concrete (possibly erased) types of
|
||||
* bound values. Setters are provided as an API in BMH. Getters are exposed as MHs,
|
||||
* which can be included as names in lambda forms.
|
||||
*/
|
||||
private static String makeFieldName(String types, int index) {
|
||||
assert index >= 0 && index < types.length();
|
||||
return "arg" + types.charAt(index) + index;
|
||||
}
|
||||
|
||||
private static String makeSignature(String types, boolean ctor) {
|
||||
StringBuilder buf = new StringBuilder(SIG_INCIPIT);
|
||||
int len = types.length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
buf.append(typeSig(types.charAt(i)));
|
||||
}
|
||||
return buf.append(')').append(ctor ? "V" : BMH_SIG).toString();
|
||||
}
|
||||
|
||||
private static MethodType makeConstructorType(String types) {
|
||||
int length = types.length();
|
||||
Class<?> ptypes[] = new Class<?>[length + 2];
|
||||
ptypes[0] = MethodType.class;
|
||||
ptypes[1] = LambdaForm.class;
|
||||
for (int i = 0; i < length; i++) {
|
||||
ptypes[i + 2] = BasicType.basicType(types.charAt(i)).basicTypeClass();
|
||||
}
|
||||
return MethodType.makeImpl(BoundMethodHandle.class, ptypes, true);
|
||||
}
|
||||
|
||||
static MethodHandle makeCbmhCtor(Class<? extends BoundMethodHandle> cbmh, String types) {
|
||||
try {
|
||||
return LOOKUP.findStatic(cbmh, "make", makeConstructorType(types));
|
||||
} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | TypeNotPresentException e) {
|
||||
throw newInternalError(e);
|
||||
class Factory extends ClassSpecializer<BoundMethodHandle, String, BoundMethodHandle.SpeciesData>.Factory {
|
||||
@Override
|
||||
protected String chooseFieldName(Class<?> type, int index) {
|
||||
return "arg" + super.chooseFieldName(type, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final Lookup LOOKUP = Lookup.IMPL_LOOKUP;
|
||||
@Override
|
||||
protected Factory makeFactory() {
|
||||
return new Factory();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All subclasses must provide such a value describing their type signature.
|
||||
*/
|
||||
static final SpeciesData SPECIES_DATA = SpeciesData.EMPTY;
|
||||
|
||||
private static final SpeciesData[] SPECIES_DATA_CACHE = new SpeciesData[6];
|
||||
private static SpeciesData checkCache(int size, String types) {
|
||||
int idx = size - 1;
|
||||
SpeciesData data = SPECIES_DATA_CACHE[idx];
|
||||
if (data != null) return data;
|
||||
SPECIES_DATA_CACHE[idx] = data = getSpeciesData(types);
|
||||
return data;
|
||||
}
|
||||
static SpeciesData speciesData_L() { return checkCache(1, "L"); }
|
||||
static SpeciesData speciesData_LL() { return checkCache(2, "LL"); }
|
||||
static SpeciesData speciesData_LLL() { return checkCache(3, "LLL"); }
|
||||
static SpeciesData speciesData_LLLL() { return checkCache(4, "LLLL"); }
|
||||
static SpeciesData speciesData_LLLLL() { return checkCache(5, "LLLLL"); }
|
||||
static SpeciesData speciesData_L() { return Species_L.BMH_SPECIES; }
|
||||
static SpeciesData speciesData_LL() { return SPECIALIZER.findSpecies("LL"); }
|
||||
static SpeciesData speciesData_LLL() { return SPECIALIZER.findSpecies("LLL"); }
|
||||
static SpeciesData speciesData_LLLL() { return SPECIALIZER.findSpecies("LLLL"); }
|
||||
static SpeciesData speciesData_LLLLL() { return SPECIALIZER.findSpecies("LLLLL"); }
|
||||
}
|
||||
|
|
1030
src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java
Normal file
1030
src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java
Normal file
File diff suppressed because it is too large
Load diff
|
@ -25,14 +25,14 @@
|
|||
|
||||
package java.lang.invoke;
|
||||
|
||||
import java.util.Map;
|
||||
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||
import jdk.internal.org.objectweb.asm.Opcodes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import sun.invoke.util.Wrapper;
|
||||
|
||||
import static java.lang.invoke.MethodHandleNatives.Constants.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Helper class to assist the GenerateJLIClassesPlugin to get access to
|
||||
|
@ -118,8 +118,7 @@ class GenerateJLIClassesHelper {
|
|||
// require an even more complex naming scheme
|
||||
LambdaForm reinvoker = makeReinvokerFor(methodTypes[i]);
|
||||
forms.add(reinvoker);
|
||||
String speciesSig = BoundMethodHandle
|
||||
.speciesData(reinvoker).fieldSignature();
|
||||
String speciesSig = BoundMethodHandle.speciesDataFor(reinvoker).key();
|
||||
assert(speciesSig.equals("L"));
|
||||
names.add(reinvoker.kind.defaultLambdaName + "_" + speciesSig);
|
||||
|
||||
|
@ -205,20 +204,19 @@ class GenerateJLIClassesHelper {
|
|||
DelegatingMethodHandle.NF_getTarget);
|
||||
}
|
||||
|
||||
static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(
|
||||
final String types) {
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(final String types) {
|
||||
for (char c : types.toCharArray()) {
|
||||
if ("LIJFD".indexOf(c) < 0) {
|
||||
throw new IllegalArgumentException("All characters must "
|
||||
+ "correspond to a basic field type: LIJFD");
|
||||
}
|
||||
}
|
||||
String shortTypes = LambdaForm.shortenSignature(types);
|
||||
final String className =
|
||||
BoundMethodHandle.Factory.speciesInternalClassName(shortTypes);
|
||||
return Map.entry(className,
|
||||
BoundMethodHandle.Factory.generateConcreteBMHClassBytes(
|
||||
shortTypes, types, className));
|
||||
final BoundMethodHandle.SpeciesData species = BoundMethodHandle.SPECIALIZER.findSpecies(types);
|
||||
final String className = species.speciesCode().getName();
|
||||
final ClassSpecializer.Factory factory = BoundMethodHandle.SPECIALIZER.factory();
|
||||
final byte[] code = factory.generateConcreteSpeciesCodeFile(className, species);
|
||||
return Map.entry(className.replace('.', '/'), code);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -183,8 +183,7 @@ class InvokerBytecodeGenerator {
|
|||
new java.security.PrivilegedAction<>() {
|
||||
public Void run() {
|
||||
try {
|
||||
String dumpName = className;
|
||||
//dumpName = dumpName.replace('/', '-');
|
||||
String dumpName = className.replace('.','/');
|
||||
File dumpFile = new File(DUMP_CLASS_FILES_DIR, dumpName+".class");
|
||||
System.out.println("dump: " + dumpFile);
|
||||
dumpFile.getParentFile().mkdirs();
|
||||
|
@ -630,7 +629,7 @@ class InvokerBytecodeGenerator {
|
|||
String name = form.kind.methodName;
|
||||
switch (form.kind) {
|
||||
case BOUND_REINVOKER: {
|
||||
name = name + "_" + BoundMethodHandle.speciesData(form).fieldSignature();
|
||||
name = name + "_" + BoundMethodHandle.speciesDataFor(form).key();
|
||||
return resolveFrom(name, invokerType, DelegatingMethodHandle.Holder.class);
|
||||
}
|
||||
case DELEGATE: return resolveFrom(name, invokerType, DelegatingMethodHandle.Holder.class);
|
||||
|
|
|
@ -143,12 +143,22 @@ class LambdaForm {
|
|||
D_TYPE('D', double.class, Wrapper.DOUBLE), // all primitive types
|
||||
V_TYPE('V', void.class, Wrapper.VOID); // not valid in all contexts
|
||||
|
||||
static final BasicType[] ALL_TYPES = BasicType.values();
|
||||
static final BasicType[] ARG_TYPES = Arrays.copyOf(ALL_TYPES, ALL_TYPES.length-1);
|
||||
static final @Stable BasicType[] ALL_TYPES = BasicType.values();
|
||||
static final @Stable BasicType[] ARG_TYPES = Arrays.copyOf(ALL_TYPES, ALL_TYPES.length-1);
|
||||
|
||||
static final int ARG_TYPE_LIMIT = ARG_TYPES.length;
|
||||
static final int TYPE_LIMIT = ALL_TYPES.length;
|
||||
|
||||
// Derived int constants, which (unlike the enums) can be constant folded.
|
||||
// We can remove them when JDK-8161245 is fixed.
|
||||
static final byte
|
||||
L_TYPE_NUM = (byte) L_TYPE.ordinal(),
|
||||
I_TYPE_NUM = (byte) I_TYPE.ordinal(),
|
||||
J_TYPE_NUM = (byte) J_TYPE.ordinal(),
|
||||
F_TYPE_NUM = (byte) F_TYPE.ordinal(),
|
||||
D_TYPE_NUM = (byte) D_TYPE.ordinal(),
|
||||
V_TYPE_NUM = (byte) V_TYPE.ordinal();
|
||||
|
||||
final char btChar;
|
||||
final Class<?> btClass;
|
||||
final Wrapper btWrapper;
|
||||
|
@ -679,6 +689,9 @@ class LambdaForm {
|
|||
Class<?> rtype = signatureReturn(sig).btClass;
|
||||
return MethodType.makeImpl(rtype, ptypes, true);
|
||||
}
|
||||
static MethodType basicMethodType(MethodType mt) {
|
||||
return signatureType(basicTypeSignature(mt));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if i-th name is a call to MethodHandleImpl.selectAlternative.
|
||||
|
@ -1291,14 +1304,28 @@ class LambdaForm {
|
|||
assert(sigp == sig.length);
|
||||
return String.valueOf(sig);
|
||||
}
|
||||
|
||||
/** Hack to make signatures more readable when they show up in method names.
|
||||
* Signature should start with a sequence of uppercase ASCII letters.
|
||||
* Runs of three or more are replaced by a single letter plus a decimal repeat count.
|
||||
* A tail of anything other than uppercase ASCII is passed through unchanged.
|
||||
* @param signature sequence of uppercase ASCII letters with possible repetitions
|
||||
* @return same sequence, with repetitions counted by decimal numerals
|
||||
*/
|
||||
public static String shortenSignature(String signature) {
|
||||
// Hack to make signatures more readable when they show up in method names.
|
||||
final int NO_CHAR = -1, MIN_RUN = 3;
|
||||
int c0, c1 = NO_CHAR, c1reps = 0;
|
||||
StringBuilder buf = null;
|
||||
int len = signature.length();
|
||||
if (len < MIN_RUN) return signature;
|
||||
for (int i = 0; i <= len; i++) {
|
||||
if (c1 != NO_CHAR && !('A' <= c1 && c1 <= 'Z')) {
|
||||
// wrong kind of char; bail out here
|
||||
if (buf != null) {
|
||||
buf.append(signature.substring(i - c1reps, len));
|
||||
}
|
||||
break;
|
||||
}
|
||||
// shift in the next char:
|
||||
c0 = c1; c1 = (i == len ? NO_CHAR : signature.charAt(i));
|
||||
if (c1 == c0) { ++c1reps; continue; }
|
||||
|
@ -1342,7 +1369,7 @@ class LambdaForm {
|
|||
this.arguments = that.arguments;
|
||||
this.constraint = constraint;
|
||||
assert(constraint == null || isParam()); // only params have constraints
|
||||
assert(constraint == null || constraint instanceof BoundMethodHandle.SpeciesData || constraint instanceof Class);
|
||||
assert(constraint == null || constraint instanceof ClassSpecializer.SpeciesData || constraint instanceof Class);
|
||||
}
|
||||
Name(MethodHandle function, Object... arguments) {
|
||||
this(new NamedFunction(function), arguments);
|
||||
|
|
|
@ -27,6 +27,8 @@ package java.lang.invoke;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.invoke.LambdaForm.*;
|
||||
import static java.lang.invoke.LambdaForm.BasicType.*;
|
||||
|
||||
|
@ -325,15 +327,15 @@ final class LambdaFormBuffer {
|
|||
* whose function is in the corresponding position in newFns.
|
||||
* Only do this if the arguments are exactly equal to the given.
|
||||
*/
|
||||
LambdaFormBuffer replaceFunctions(NamedFunction[] oldFns, NamedFunction[] newFns,
|
||||
LambdaFormBuffer replaceFunctions(List<NamedFunction> oldFns, List<NamedFunction> newFns,
|
||||
Object... forArguments) {
|
||||
assert(inTrans());
|
||||
if (oldFns.length == 0) return this;
|
||||
if (oldFns.isEmpty()) return this;
|
||||
for (int i = arity; i < length; i++) {
|
||||
Name n = names[i];
|
||||
int nfi = indexOf(n.function, oldFns);
|
||||
int nfi = oldFns.indexOf(n.function);
|
||||
if (nfi >= 0 && Arrays.equals(n.arguments, forArguments)) {
|
||||
changeName(i, new Name(newFns[nfi], n.arguments));
|
||||
changeName(i, new Name(newFns.get(nfi), n.arguments));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -381,10 +381,11 @@ class LambdaFormEditor {
|
|||
/// Editing methods for method handles. These need to have fast paths.
|
||||
|
||||
private BoundMethodHandle.SpeciesData oldSpeciesData() {
|
||||
return BoundMethodHandle.speciesData(lambdaForm);
|
||||
return BoundMethodHandle.speciesDataFor(lambdaForm);
|
||||
}
|
||||
|
||||
private BoundMethodHandle.SpeciesData newSpeciesData(BasicType type) {
|
||||
return oldSpeciesData().extendWith(type);
|
||||
return oldSpeciesData().extendWith((byte) type.ordinal());
|
||||
}
|
||||
|
||||
BoundMethodHandle bindArgumentL(BoundMethodHandle mh, int pos, Object value) {
|
||||
|
@ -461,7 +462,7 @@ class LambdaFormEditor {
|
|||
buf.replaceParameterByNewExpression(pos, new Name(getter, newBaseAddress));
|
||||
} else {
|
||||
// cannot bind the MH arg itself, unless oldData is empty
|
||||
assert(oldData == BoundMethodHandle.SpeciesData.EMPTY);
|
||||
assert(oldData == BoundMethodHandle.SPECIALIZER.topSpecies());
|
||||
newBaseAddress = new Name(L_TYPE).withConstraint(newData);
|
||||
buf.replaceParameterByNewExpression(0, new Name(getter, newBaseAddress));
|
||||
buf.insertParameter(0, newBaseAddress);
|
||||
|
|
|
@ -776,11 +776,11 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
if (PROFILE_GWT) {
|
||||
int[] counts = new int[2];
|
||||
mh = (BoundMethodHandle)
|
||||
BoundMethodHandle.speciesData_LLLL().constructor().invokeBasic(type, form,
|
||||
BoundMethodHandle.speciesData_LLLL().factory().invokeBasic(type, form,
|
||||
(Object) test, (Object) profile(target), (Object) profile(fallback), counts);
|
||||
} else {
|
||||
mh = (BoundMethodHandle)
|
||||
BoundMethodHandle.speciesData_LLL().constructor().invokeBasic(type, form,
|
||||
BoundMethodHandle.speciesData_LLL().factory().invokeBasic(type, form,
|
||||
(Object) test, (Object) profile(target), (Object) profile(fallback));
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
|
@ -1089,7 +1089,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLLL();
|
||||
BoundMethodHandle mh;
|
||||
try {
|
||||
mh = (BoundMethodHandle) data.constructor().invokeBasic(type, form, (Object) target, (Object) exType,
|
||||
mh = (BoundMethodHandle) data.factory().invokeBasic(type, form, (Object) target, (Object) exType,
|
||||
(Object) catcher, (Object) collectArgs, (Object) unboxResult);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
|
@ -1890,7 +1890,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLL();
|
||||
BoundMethodHandle mh;
|
||||
try {
|
||||
mh = (BoundMethodHandle) data.constructor().invokeBasic(type, form, (Object) clauseData,
|
||||
mh = (BoundMethodHandle) data.factory().invokeBasic(type, form, (Object) clauseData,
|
||||
(Object) collectArgs, (Object) unboxResult);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
|
@ -2133,7 +2133,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
BoundMethodHandle.SpeciesData data = BoundMethodHandle.speciesData_LLLL();
|
||||
BoundMethodHandle mh;
|
||||
try {
|
||||
mh = (BoundMethodHandle) data.constructor().invokeBasic(type, form, (Object) target, (Object) cleanup,
|
||||
mh = (BoundMethodHandle) data.factory().invokeBasic(type, form, (Object) target, (Object) cleanup,
|
||||
(Object) collectArgs, (Object) unboxResult);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import static java.lang.invoke.LambdaForm.BasicType.*;
|
||||
import static java.lang.invoke.MethodHandleStatics.*;
|
||||
|
||||
|
@ -33,6 +35,7 @@ import static java.lang.invoke.MethodHandleStatics.*;
|
|||
* @author jrose
|
||||
*/
|
||||
final class SimpleMethodHandle extends BoundMethodHandle {
|
||||
|
||||
private SimpleMethodHandle(MethodType type, LambdaForm form) {
|
||||
super(type, form);
|
||||
}
|
||||
|
@ -41,10 +44,11 @@ final class SimpleMethodHandle extends BoundMethodHandle {
|
|||
return new SimpleMethodHandle(type, form);
|
||||
}
|
||||
|
||||
/*non-public*/ static final SpeciesData SPECIES_DATA = SpeciesData.EMPTY;
|
||||
/*non-public*/ static @Stable BoundMethodHandle.SpeciesData BMH_SPECIES;
|
||||
|
||||
/*non-public*/ public SpeciesData speciesData() {
|
||||
return SPECIES_DATA;
|
||||
@Override
|
||||
/*non-public*/ BoundMethodHandle.SpeciesData speciesData() {
|
||||
return BMH_SPECIES;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,11 +61,6 @@ final class SimpleMethodHandle extends BoundMethodHandle {
|
|||
return "\n& Class="+getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
/*non-public*/ public int fieldCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
/*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
|
||||
return BoundMethodHandle.bindSingle(mt, lf, narg); // Use known fast path.
|
||||
|
@ -69,7 +68,7 @@ final class SimpleMethodHandle extends BoundMethodHandle {
|
|||
@Override
|
||||
/*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
|
||||
try {
|
||||
return (BoundMethodHandle) SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, narg);
|
||||
return (BoundMethodHandle) BMH_SPECIES.extendWith(I_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
}
|
||||
|
@ -77,7 +76,7 @@ final class SimpleMethodHandle extends BoundMethodHandle {
|
|||
@Override
|
||||
/*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
|
||||
try {
|
||||
return (BoundMethodHandle) SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, narg);
|
||||
return (BoundMethodHandle) BMH_SPECIES.extendWith(J_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
}
|
||||
|
@ -85,7 +84,7 @@ final class SimpleMethodHandle extends BoundMethodHandle {
|
|||
@Override
|
||||
/*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
|
||||
try {
|
||||
return (BoundMethodHandle) SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, narg);
|
||||
return (BoundMethodHandle) BMH_SPECIES.extendWith(F_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
}
|
||||
|
@ -93,7 +92,7 @@ final class SimpleMethodHandle extends BoundMethodHandle {
|
|||
@Override
|
||||
/*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
|
||||
try {
|
||||
return (BoundMethodHandle) SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, narg);
|
||||
return (BoundMethodHandle) BMH_SPECIES.extendWith(D_TYPE_NUM).factory().invokeBasic(mt, lf, narg);
|
||||
} catch (Throwable ex) {
|
||||
throw uncaughtException(ex);
|
||||
}
|
||||
|
|
|
@ -1133,7 +1133,7 @@ class InetAddress implements java.io.Serializable {
|
|||
|
||||
/**
|
||||
* Create an instance of the NameService interface based on
|
||||
* the setting of the {@codejdk.net.hosts.file} system property.
|
||||
* the setting of the {@code jdk.net.hosts.file} system property.
|
||||
*
|
||||
* <p>The default NameService is the PlatformNameService, which typically
|
||||
* delegates name and address resolution calls to the underlying
|
||||
|
|
|
@ -57,13 +57,12 @@ import java.util.Date;
|
|||
*
|
||||
* @author Benjamin Renaud
|
||||
* @since 1.1
|
||||
* @deprecated A new certificate handling package is created in the Java platform.
|
||||
* This Certificate interface is entirely deprecated and
|
||||
* is here to allow for a smooth transition to the new
|
||||
* package.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by
|
||||
* {@code java.security.cert.Certificate} and related classes.
|
||||
* @see java.security.cert.Certificate
|
||||
*/
|
||||
@Deprecated(since="1.2")
|
||||
@Deprecated(since="1.2", forRemoval=true)
|
||||
public interface Certificate {
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,12 +52,13 @@ import java.util.*;
|
|||
*
|
||||
* @author Benjamin Renaud
|
||||
* @since 1.1
|
||||
* @deprecated This class is no longer used. Its functionality has been
|
||||
* replaced by {@code java.security.KeyStore}, the
|
||||
* {@code java.security.cert} package, and
|
||||
* {@code java.security.Principal}.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by
|
||||
* {@code java.security.KeyStore}, the {@code java.security.cert} package,
|
||||
* and {@code java.security.Principal}.
|
||||
*/
|
||||
@Deprecated(since="1.2")
|
||||
@Deprecated(since="1.2", forRemoval=true)
|
||||
@SuppressWarnings("removal")
|
||||
public abstract class Identity implements Principal, Serializable {
|
||||
|
||||
/** use serialVersionUID from JDK 1.1.x for interoperability */
|
||||
|
|
|
@ -57,12 +57,13 @@ import java.util.Properties;
|
|||
* @author Benjamin Renaud
|
||||
* @since 1.1
|
||||
*
|
||||
* @deprecated This class is no longer used. Its functionality has been
|
||||
* replaced by {@code java.security.KeyStore}, the
|
||||
* {@code java.security.cert} package, and
|
||||
* {@code java.security.Principal}.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by
|
||||
* {@code java.security.KeyStore}, the {@code java.security.cert} package,
|
||||
* and {@code java.security.Principal}.
|
||||
*/
|
||||
@Deprecated(since="1.2")
|
||||
@Deprecated(since="1.2", forRemoval=true)
|
||||
@SuppressWarnings("removal")
|
||||
public abstract
|
||||
class IdentityScope extends Identity {
|
||||
|
||||
|
|
|
@ -40,12 +40,13 @@ import java.io.*;
|
|||
* @author Benjamin Renaud
|
||||
* @since 1.1
|
||||
*
|
||||
* @deprecated This class is no longer used. Its functionality has been
|
||||
* replaced by {@code java.security.KeyStore}, the
|
||||
* {@code java.security.cert} package, and
|
||||
* {@code java.security.Principal}.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by
|
||||
* {@code java.security.KeyStore}, the {@code java.security.cert} package,
|
||||
* and {@code java.security.Principal}.
|
||||
*/
|
||||
@Deprecated(since="1.2")
|
||||
@Deprecated(since="1.2", forRemoval=true)
|
||||
@SuppressWarnings("removal")
|
||||
public abstract class Signer extends Identity {
|
||||
|
||||
private static final long serialVersionUID = -1763464102261361480L;
|
||||
|
|
|
@ -84,11 +84,13 @@ import java.security.Principal;
|
|||
* @author Satish Dharmaraj
|
||||
* @since 1.1
|
||||
*
|
||||
* @deprecated This package has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
*/
|
||||
|
||||
@Deprecated(since="9")
|
||||
@Deprecated(since="9", forRemoval=true)
|
||||
@SuppressWarnings("removal")
|
||||
public interface Acl extends Owner {
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,10 +52,12 @@ import java.security.Principal;
|
|||
* @author Satish Dharmaraj
|
||||
* @since 1.1
|
||||
*
|
||||
* @deprecated This package has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
@Deprecated(since="9", forRemoval=true)
|
||||
@SuppressWarnings("removal")
|
||||
public interface AclEntry extends Cloneable {
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,10 +32,11 @@ package java.security.acl;
|
|||
* @author Satish Dharmaraj
|
||||
* @since 1.1
|
||||
*
|
||||
* @deprecated This package has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
@Deprecated(since="9", forRemoval=true)
|
||||
public class AclNotFoundException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 5684295034092681791L;
|
||||
|
|
|
@ -41,10 +41,11 @@ import java.security.Principal;
|
|||
* @author Satish Dharmaraj
|
||||
* @since 1.1
|
||||
*
|
||||
* @deprecated This package has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
@Deprecated(since="9", forRemoval=true)
|
||||
public interface Group extends Principal {
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,10 +34,11 @@ package java.security.acl;
|
|||
* @author Satish Dharmaraj
|
||||
* @since 1.1
|
||||
*
|
||||
* @deprecated This package has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
@Deprecated(since="9", forRemoval=true)
|
||||
public class LastOwnerException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5141997548211140359L;
|
||||
|
|
|
@ -33,10 +33,11 @@ package java.security.acl;
|
|||
* @author Satish Dharmaraj
|
||||
* @since 1.1
|
||||
*
|
||||
* @deprecated This package has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
@Deprecated(since="9", forRemoval=true)
|
||||
public class NotOwnerException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5555597911163362399L;
|
||||
|
|
|
@ -37,10 +37,12 @@ import java.security.Principal;
|
|||
* @since 1.1
|
||||
* @see java.security.acl.Acl
|
||||
*
|
||||
* @deprecated This package has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
@Deprecated(since="9", forRemoval=true)
|
||||
@SuppressWarnings("removal")
|
||||
public interface Owner {
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,10 +33,11 @@ package java.security.acl;
|
|||
* @author Satish Dharmaraj
|
||||
* @since 1.1
|
||||
*
|
||||
* @deprecated This package has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
* @deprecated This class is deprecated and subject to removal in a future
|
||||
* version of Java SE. It has been replaced by {@code java.security.Policy}
|
||||
* and related classes since 1.2.
|
||||
*/
|
||||
@Deprecated(since="9")
|
||||
@Deprecated(since="9", forRemoval=true)
|
||||
public interface Permission {
|
||||
|
||||
/**
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
* The classes and interfaces in this package have been deprecated. New
|
||||
* classes should not be added to this package. The {@code java.security}
|
||||
* package contains suitable replacements. See {@link java.security.Policy}
|
||||
* and related classes for details.
|
||||
* and related classes for details. This package is subject to removal in a
|
||||
* future version of Java SE.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2017, 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
|
||||
|
@ -192,7 +192,7 @@ class ZoneName {
|
|||
"Africa/Ndjamena", "Africa_Western", "Africa/Lagos",
|
||||
"Asia/Macau", "China", "Asia/Shanghai",
|
||||
"America/Lima", "Peru", "America/Lima",
|
||||
"Africa/Windhoek", "Africa_Western", "Africa/Lagos",
|
||||
"Africa/Windhoek", "Africa_Central", "Africa/Maputo",
|
||||
"America/Sitka", "Alaska", "America/Juneau",
|
||||
"America/Mazatlan", "America_Mountain", "America/Denver",
|
||||
"Asia/Saigon", "Indochina", "Asia/Saigon",
|
||||
|
@ -324,7 +324,7 @@ class ZoneName {
|
|||
"Atlantic/Faroe", "Europe_Western", "Atlantic/Canary",
|
||||
"America/Cambridge_Bay", "America_Mountain", "America/Denver",
|
||||
"America/Los_Angeles", "America_Pacific", "America/Los_Angeles",
|
||||
"Africa/Khartoum", "Africa_Eastern", "Africa/Nairobi",
|
||||
"Africa/Khartoum", "Africa_Central", "Africa/Maputo",
|
||||
"Europe/Simferopol", "Europe_Eastern", "Europe/Bucharest",
|
||||
"Australia/Currie", "Australia_Eastern", "Australia/Sydney",
|
||||
"Europe/Guernsey", "GMT", "Atlantic/Reykjavik",
|
||||
|
@ -744,7 +744,6 @@ class ZoneName {
|
|||
"UTC", "Etc/UTC",
|
||||
"Canada/Newfoundland", "America/St_Johns",
|
||||
"Europe/Skopje", "Europe/Belgrade",
|
||||
"Canada/East-Saskatchewan", "America/Regina",
|
||||
"PRC", "Asia/Shanghai",
|
||||
"UCT", "Etc/UCT",
|
||||
"America/Mendoza", "America/Argentina/Mendoza",
|
||||
|
|
|
@ -695,8 +695,9 @@ public class ConcurrentLinkedDeque<E>
|
|||
* stale pointer that is now off the list.
|
||||
*/
|
||||
final Node<E> pred(Node<E> p) {
|
||||
Node<E> q = p.prev;
|
||||
return (p == q) ? last() : q;
|
||||
if (p == (p = p.prev))
|
||||
p = last();
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -867,31 +868,31 @@ public class ConcurrentLinkedDeque<E>
|
|||
|
||||
public E peekFirst() {
|
||||
restart: for (;;) {
|
||||
for (Node<E> first = first(), p = first;;) {
|
||||
final E item;
|
||||
if ((item = p.item) != null) {
|
||||
// recheck for linearizability
|
||||
if (first.prev != null) continue restart;
|
||||
return item;
|
||||
}
|
||||
if ((p = succ(p)) == null)
|
||||
return null;
|
||||
E item;
|
||||
Node<E> first = first(), p = first;
|
||||
while ((item = p.item) == null) {
|
||||
if (p == (p = p.next)) continue restart;
|
||||
if (p == null)
|
||||
break;
|
||||
}
|
||||
// recheck for linearizability
|
||||
if (first.prev != null) continue restart;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
public E peekLast() {
|
||||
restart: for (;;) {
|
||||
for (Node<E> last = last(), p = last;;) {
|
||||
final E item;
|
||||
if ((item = p.item) != null) {
|
||||
// recheck for linearizability
|
||||
if (last.next != null) continue restart;
|
||||
return item;
|
||||
}
|
||||
if ((p = pred(p)) == null)
|
||||
return null;
|
||||
E item;
|
||||
Node<E> last = last(), p = last;
|
||||
while ((item = p.item) == null) {
|
||||
if (p == (p = p.prev)) continue restart;
|
||||
if (p == null)
|
||||
break;
|
||||
}
|
||||
// recheck for linearizability
|
||||
if (last.next != null) continue restart;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -921,8 +922,11 @@ public class ConcurrentLinkedDeque<E>
|
|||
return item;
|
||||
}
|
||||
}
|
||||
if ((p = succ(p)) == null)
|
||||
if (p == (p = p.next)) continue restart;
|
||||
if (p == null) {
|
||||
if (first.prev != null) continue restart;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -939,8 +943,11 @@ public class ConcurrentLinkedDeque<E>
|
|||
return item;
|
||||
}
|
||||
}
|
||||
if ((p = pred(p)) == null)
|
||||
if (p == (p = p.prev)) continue restart;
|
||||
if (p == null) {
|
||||
if (last.next != null) continue restart;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2017, 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
|
||||
|
@ -27,6 +27,7 @@ package java.util.stream;
|
|||
import java.util.Spliterator;
|
||||
import java.util.concurrent.CountedCompleter;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
|
||||
/**
|
||||
* Abstract base class for most fork-join tasks used to implement stream ops.
|
||||
|
@ -88,13 +89,7 @@ abstract class AbstractTask<P_IN, P_OUT, R,
|
|||
K extends AbstractTask<P_IN, P_OUT, R, K>>
|
||||
extends CountedCompleter<R> {
|
||||
|
||||
/**
|
||||
* Default target factor of leaf tasks for parallel decomposition.
|
||||
* To allow load balancing, we over-partition, currently to approximately
|
||||
* four tasks per processor, which enables others to help out
|
||||
* if leaf tasks are uneven or some processors are otherwise busy.
|
||||
*/
|
||||
static final int LEAF_TARGET = ForkJoinPool.getCommonPoolParallelism() << 2;
|
||||
private static final int LEAF_TARGET = ForkJoinPool.getCommonPoolParallelism() << 2;
|
||||
|
||||
/** The pipeline helper, common to all tasks in a computation */
|
||||
protected final PipelineHelper<P_OUT> helper;
|
||||
|
@ -156,6 +151,22 @@ abstract class AbstractTask<P_IN, P_OUT, R,
|
|||
this.targetSize = parent.targetSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default target of leaf tasks for parallel decomposition.
|
||||
* To allow load balancing, we over-partition, currently to approximately
|
||||
* four tasks per processor, which enables others to help out
|
||||
* if leaf tasks are uneven or some processors are otherwise busy.
|
||||
*/
|
||||
public static int getLeafTarget() {
|
||||
Thread t = Thread.currentThread();
|
||||
if (t instanceof ForkJoinWorkerThread) {
|
||||
return ((ForkJoinWorkerThread) t).getPool().getParallelism() << 2;
|
||||
}
|
||||
else {
|
||||
return LEAF_TARGET;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new node of type T whose parent is the receiver; must call
|
||||
* the AbstractTask(T, Spliterator) constructor with the receiver and the
|
||||
|
@ -181,7 +192,7 @@ abstract class AbstractTask<P_IN, P_OUT, R,
|
|||
* @return suggested target leaf size
|
||||
*/
|
||||
public static long suggestTargetSize(long sizeEstimate) {
|
||||
long est = sizeEstimate / LEAF_TARGET;
|
||||
long est = sizeEstimate / getLeafTarget();
|
||||
return est > 0L ? est : 1L;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2017, 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
|
||||
|
@ -28,7 +28,6 @@ import java.util.Objects;
|
|||
import java.util.Spliterator;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountedCompleter;
|
||||
import java.util.concurrent.ForkJoinTask;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.DoubleConsumer;
|
||||
import java.util.function.IntConsumer;
|
||||
|
@ -378,7 +377,7 @@ final class ForEachOps {
|
|||
this.spliterator = spliterator;
|
||||
this.targetSize = AbstractTask.suggestTargetSize(spliterator.estimateSize());
|
||||
// Size map to avoid concurrent re-sizes
|
||||
this.completionMap = new ConcurrentHashMap<>(Math.max(16, AbstractTask.LEAF_TARGET << 1));
|
||||
this.completionMap = new ConcurrentHashMap<>(Math.max(16, AbstractTask.getLeafTarget() << 1));
|
||||
this.action = action;
|
||||
this.leftPredecessor = null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2017, 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
|
||||
|
@ -897,7 +897,7 @@ class StreamSpliterators {
|
|||
* Note: The source spliterator may report {@code ORDERED} since that
|
||||
* spliterator be the result of a previous pipeline stage that was
|
||||
* collected to a {@code Node}. It is the order of the pipeline stage
|
||||
* that governs whether the this slice spliterator is to be used or not.
|
||||
* that governs whether this slice spliterator is to be used or not.
|
||||
*/
|
||||
abstract static class UnorderedSliceSpliterator<T, T_SPLITR extends Spliterator<T>> {
|
||||
static final int CHUNK_SIZE = 1 << 7;
|
||||
|
@ -914,7 +914,7 @@ class StreamSpliterators {
|
|||
this.unlimited = limit < 0;
|
||||
this.skipThreshold = limit >= 0 ? limit : 0;
|
||||
this.chunkSize = limit >= 0 ? (int)Math.min(CHUNK_SIZE,
|
||||
((skip + limit) / AbstractTask.LEAF_TARGET) + 1) : CHUNK_SIZE;
|
||||
((skip + limit) / AbstractTask.getLeafTarget()) + 1) : CHUNK_SIZE;
|
||||
this.permits = new AtomicLong(limit >= 0 ? skip + limit : skip);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue