Merge branch 'master' into stubby

This commit is contained in:
Jack Conradson 2016-06-10 16:22:17 -07:00
commit e293000d8d
42 changed files with 593 additions and 294 deletions

View File

@ -33,8 +33,6 @@ import org.elasticsearch.common.unit.TimeValue;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static org.elasticsearch.common.unit.TimeValue.readTimeValue;
/**
*
*/
@ -160,7 +158,7 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
indices[i] = in.readString();
}
}
timeout = readTimeValue(in);
timeout = new TimeValue(in);
if (in.readBoolean()) {
waitForStatus = ClusterHealthStatus.fromValue(in.readByte());
}

View File

@ -187,7 +187,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
timedOut = in.readBoolean();
numberOfInFlightFetch = in.readInt();
delayedUnassignedShards= in.readInt();
taskMaxWaitingTime = TimeValue.readTimeValue(in);
taskMaxWaitingTime = new TimeValue(in);
}
@Override

View File

@ -101,7 +101,7 @@ public class NodesHotThreadsRequest extends BaseNodesRequest<NodesHotThreadsRequ
threads = in.readInt();
ignoreIdleThreads = in.readBoolean();
type = in.readString();
interval = TimeValue.readTimeValue(in);
interval = new TimeValue(in);
snapshots = in.readInt();
}

View File

@ -544,7 +544,7 @@ public class BulkRequest extends ActionRequest<BulkRequest> implements Composite
}
}
refreshPolicy = RefreshPolicy.readFrom(in);
timeout = TimeValue.readTimeValue(in);
timeout = new TimeValue(in);
}
@Override

View File

@ -633,9 +633,8 @@ public class IndexRequest extends ReplicatedWriteRequest<IndexRequest> implement
routing = in.readOptionalString();
parent = in.readOptionalString();
timestamp = in.readOptionalString();
ttl = in.readBoolean() ? TimeValue.readTimeValue(in) : null;
ttl = in.readOptionalWriteable(TimeValue::new);
source = in.readBytesReference();
opType = OpType.fromId(in.readByte());
version = in.readLong();
versionType = VersionType.fromValue(in.readByte());
@ -650,12 +649,7 @@ public class IndexRequest extends ReplicatedWriteRequest<IndexRequest> implement
out.writeOptionalString(routing);
out.writeOptionalString(parent);
out.writeOptionalString(timestamp);
if (ttl == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
ttl.writeTo(out);
}
out.writeOptionalWriteable(ttl);
out.writeBytesReference(source);
out.writeByte(opType.id());
out.writeLong(version);

View File

@ -25,7 +25,6 @@ import org.elasticsearch.common.unit.TimeValue;
import java.io.IOException;
import static org.elasticsearch.common.unit.TimeValue.readTimeValue;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
/**
@ -75,7 +74,7 @@ public abstract class AcknowledgedRequest<Request extends MasterNodeRequest<Requ
* Reads the timeout value
*/
protected void readTimeout(StreamInput in) throws IOException {
timeout = readTimeValue(in);
timeout = new TimeValue(in);
}
/**

View File

@ -61,7 +61,7 @@ public abstract class MasterNodeRequest<Request extends MasterNodeRequest<Reques
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
masterNodeTimeout = TimeValue.readTimeValue(in);
masterNodeTimeout = new TimeValue(in);
}
@Override

View File

@ -82,20 +82,13 @@ public abstract class BaseNodesRequest<Request extends BaseNodesRequest<Request>
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
nodesIds = in.readStringArray();
if (in.readBoolean()) {
timeout = TimeValue.readTimeValue(in);
}
timeout = in.readOptionalWriteable(TimeValue::new);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArrayNullable(nodesIds);
if (timeout == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
timeout.writeTo(out);
}
out.writeOptionalWriteable(timeout);
}
}

View File

@ -181,7 +181,7 @@ public abstract class ReplicationRequest<Request extends ReplicationRequest<Requ
shardId = null;
}
consistencyLevel = WriteConsistencyLevel.fromId(in.readByte());
timeout = TimeValue.readTimeValue(in);
timeout = new TimeValue(in);
index = in.readString();
routedBasedOnClusterVersion = in.readVLong();
primaryTerm = in.readVLong();

View File

@ -121,7 +121,7 @@ public abstract class InstanceShardOperationRequest<Request extends InstanceShar
} else {
shardId = null;
}
timeout = TimeValue.readTimeValue(in);
timeout = new TimeValue(in);
concreteIndex = in.readOptionalString();
}

View File

@ -144,9 +144,7 @@ public class BaseTasksRequest<Request extends BaseTasksRequest<Request>> extends
parentTaskId = TaskId.readFromStream(in);
nodesIds = in.readStringArray();
actions = in.readStringArray();
if (in.readBoolean()) {
timeout = TimeValue.readTimeValue(in);
}
timeout = in.readOptionalWriteable(TimeValue::new);
}
@Override
@ -156,7 +154,7 @@ public class BaseTasksRequest<Request extends BaseTasksRequest<Request>> extends
parentTaskId.writeTo(out);
out.writeStringArrayNullable(nodesIds);
out.writeStringArrayNullable(actions);
out.writeOptionalStreamable(timeout);
out.writeOptionalWriteable(timeout);
}
public boolean match(Task task) {

View File

@ -26,6 +26,8 @@ import java.io.IOException;
* across the wire" using Elasticsearch's internal protocol. If the implementer also implements equals and hashCode then a copy made by
* serializing and deserializing must be equal and have the same hashCode. It isn't required that such a copy be entirely unchanged. For
* example, {@link org.elasticsearch.common.unit.TimeValue} converts the time to nanoseconds for serialization.
* {@linkplain org.elasticsearch.common.unit.TimeValue} actually implements {@linkplain Writeable} not {@linkplain Streamable} but it has
* the same contract.
*
* Prefer implementing {@link Writeable} over implementing this interface where possible. Lots of code depends on this interface so this
* isn't always possible.

View File

@ -26,8 +26,6 @@ import java.io.IOException;
* across the wire" using Elasticsearch's internal protocol. If the implementer also implements equals and hashCode then a copy made by
* serializing and deserializing must be equal and have the same hashCode. It isn't required that such a copy be entirely unchanged. For
* example, {@link org.elasticsearch.common.unit.TimeValue} converts the time to nanoseconds for serialization.
* {@linkplain org.elasticsearch.common.unit.TimeValue} actually implements {@linkplain Streamable} not {@linkplain Writeable} but it has
* the same contract.
*
* Prefer implementing this interface over implementing {@link Streamable} where possible. Lots of code depends on {@linkplain Streamable}
* so this isn't always possible.

View File

@ -23,7 +23,7 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.io.stream.Writeable;
import org.joda.time.Period;
import org.joda.time.PeriodType;
import org.joda.time.format.PeriodFormat;
@ -34,7 +34,7 @@ import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
public class TimeValue implements Streamable {
public class TimeValue implements Writeable {
/** How many nano-seconds in one milli-second */
public static final long NSEC_PER_MSEC = 1000000;
@ -59,13 +59,8 @@ public class TimeValue implements Streamable {
return new TimeValue(hours, TimeUnit.HOURS);
}
private long duration;
private TimeUnit timeUnit;
private TimeValue() {
}
private final long duration;
private final TimeUnit timeUnit;
public TimeValue(long millis) {
this(millis, TimeUnit.MILLISECONDS);
@ -76,6 +71,19 @@ public class TimeValue implements Streamable {
this.timeUnit = timeUnit;
}
/**
* Read from a stream.
*/
public TimeValue(StreamInput in) throws IOException {
duration = in.readZLong();
timeUnit = TimeUnit.NANOSECONDS;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeZLong(nanos());
}
public long nanos() {
return timeUnit.toNanos(duration);
}
@ -304,26 +312,6 @@ public class TimeValue implements Streamable {
static final long C5 = C4 * 60L;
static final long C6 = C5 * 24L;
public static TimeValue readTimeValue(StreamInput in) throws IOException {
TimeValue timeValue = new TimeValue();
timeValue.readFrom(in);
return timeValue;
}
/**
* serialization converts TimeValue internally to NANOSECONDS
*/
@Override
public void readFrom(StreamInput in) throws IOException {
duration = in.readLong();
timeUnit = TimeUnit.NANOSECONDS;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeLong(nanos());
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -20,6 +20,7 @@
package org.elasticsearch.discovery.zen.ping.unicast;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
@ -79,7 +80,6 @@ import java.util.function.Function;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static org.elasticsearch.common.unit.TimeValue.readTimeValue;
import static org.elasticsearch.common.util.concurrent.ConcurrentCollections.newConcurrentMap;
import static org.elasticsearch.discovery.zen.ping.ZenPing.PingResponse.readPingResponse;
@ -545,7 +545,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent<ZenPing> implemen
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
id = in.readInt();
timeout = readTimeValue(in);
timeout = new TimeValue(in);
pingResponse = readPingResponse(in);
}

View File

@ -26,8 +26,6 @@ import org.elasticsearch.common.unit.TimeValue;
import java.io.IOException;
import static org.elasticsearch.common.unit.TimeValue.readTimeValue;
/**
* A scroll enables scrolling of search request. It holds a {@link #keepAlive()} time that
* will control how long to keep the scrolling resources open.
@ -64,18 +62,11 @@ public class Scroll implements Streamable {
@Override
public void readFrom(StreamInput in) throws IOException {
if (in.readBoolean()) {
keepAlive = readTimeValue(in);
}
in.readOptionalWriteable(TimeValue::new);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
if (keepAlive == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
keepAlive.writeTo(out);
}
out.writeOptionalWriteable(keepAlive);
}
}

View File

@ -579,7 +579,7 @@ public class ThreadPool extends AbstractComponent implements Closeable {
min = in.readInt();
max = in.readInt();
if (in.readBoolean()) {
keepAlive = TimeValue.readTimeValue(in);
keepAlive = new TimeValue(in);
}
if (in.readBoolean()) {
queueSize = SizeValue.readSizeValue(in);

View File

@ -28,6 +28,8 @@ import org.joda.time.PeriodType;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static org.elasticsearch.common.unit.TimeValue.timeValueNanos;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThan;
@ -123,20 +125,22 @@ public class TimeValueTests extends ESTestCase {
TimeValue.parseTimeValue("10W", null, "test"));
}
private void assertEqualityAfterSerialize(TimeValue value) throws IOException {
private void assertEqualityAfterSerialize(TimeValue value, int expectedSize) throws IOException {
BytesStreamOutput out = new BytesStreamOutput();
value.writeTo(out);
assertEquals(expectedSize, out.size());
StreamInput in = StreamInput.wrap(out.bytes());
TimeValue inValue = TimeValue.readTimeValue(in);
TimeValue inValue = new TimeValue(in);
assertThat(inValue, equalTo(value));
}
public void testSerialize() throws Exception {
assertEqualityAfterSerialize(new TimeValue(100, TimeUnit.DAYS));
assertEqualityAfterSerialize(new TimeValue(-1));
assertEqualityAfterSerialize(new TimeValue(1, TimeUnit.NANOSECONDS));
assertEqualityAfterSerialize(new TimeValue(100, TimeUnit.DAYS), 8);
assertEqualityAfterSerialize(timeValueNanos(-1), 1);
assertEqualityAfterSerialize(timeValueNanos(1), 1);
assertEqualityAfterSerialize(timeValueSeconds(30), 6);
}
public void testFailOnUnknownUnits() {

View File

@ -185,4 +185,5 @@ lamtype
funcref
: TYPE REF ( ID | NEW )
| ID REF ID
;

View File

@ -212,6 +212,8 @@ public final class Def {
* until it finds a matching whitelisted method. If one is not found, it throws an exception.
* Otherwise it returns a handle to the matching method.
* <p>
* @param lookup caller's lookup
* @param callSiteType callsite's type
* @param receiverClass Class of the object to invoke the method on.
* @param name Name of the method.
* @param args args passed to callsite
@ -220,31 +222,103 @@ public final class Def {
* @throws LambdaConversionException if a method reference cannot be converted to an functional interface
* @throws IllegalArgumentException if no matching whitelisted method was found.
*/
static MethodHandle lookupMethod(Lookup lookup, Class<?> receiverClass, String name,
Object args[], long recipe) throws LambdaConversionException {
Method method = lookupMethodInternal(receiverClass, name, args.length - 1);
static MethodHandle lookupMethod(Lookup lookup, MethodType callSiteType,
Class<?> receiverClass, String name, Object args[], long recipe) throws LambdaConversionException {
// simple case: no lambdas
if (recipe == 0) {
return lookupMethodInternal(receiverClass, name, args.length - 1).handle;
}
// otherwise: first we have to compute the "real" arity. This is because we have extra arguments:
// e.g. f(a, g(x), b, h(y), i()) looks like f(a, g, x, b, h, y, i).
int arity = args.length - 1;
for (int i = 0; i < args.length; i++) {
if ((recipe & (1L << (i - 1))) != 0) {
String signature = (String) args[i];
int numCaptures = Integer.parseInt(signature.substring(signature.indexOf(',')+1));
arity -= numCaptures;
}
}
// lookup the method with the proper arity, then we know everything (e.g. interface types of parameters).
// based on these we can finally link any remaining lambdas that were deferred.
Method method = lookupMethodInternal(receiverClass, name, arity);
MethodHandle handle = method.handle;
if (recipe != 0) {
MethodHandle filters[] = new MethodHandle[args.length];
for (int i = 0; i < args.length; i++) {
int replaced = 0;
for (int i = 1; i < args.length; i++) {
// its a functional reference, replace the argument with an impl
if ((recipe & (1L << (i - 1))) != 0) {
filters[i] = lookupReference(lookup, method.arguments.get(i - 1), (String) args[i]);
// decode signature of form 'type.call,2'
String signature = (String) args[i];
int separator = signature.indexOf('.');
int separator2 = signature.indexOf(',');
String type = signature.substring(1, separator);
String call = signature.substring(separator+1, separator2);
int numCaptures = Integer.parseInt(signature.substring(separator2+1));
Class<?> captures[] = new Class<?>[numCaptures];
for (int capture = 0; capture < captures.length; capture++) {
captures[capture] = callSiteType.parameterType(i + 1 + capture);
}
MethodHandle filter;
Definition.Type interfaceType = method.arguments.get(i - 1 - replaced);
if (signature.charAt(0) == 'S') {
// the implementation is strongly typed, now that we know the interface type,
// we have everything.
filter = lookupReferenceInternal(lookup,
interfaceType,
type,
call,
captures);
} else if (signature.charAt(0) == 'D') {
// the interface type is now known, but we need to get the implementation.
// this is dynamically based on the receiver type (and cached separately, underneath
// this cache). It won't blow up since we never nest here (just references)
MethodType nestedType = MethodType.methodType(interfaceType.clazz, captures);
CallSite nested = DefBootstrap.bootstrap(lookup,
call,
nestedType,
DefBootstrap.REFERENCE,
interfaceType.name);
filter = nested.dynamicInvoker();
} else {
throw new AssertionError();
}
// the filter now ignores the signature (placeholder) on the stack
filter = MethodHandles.dropArguments(filter, 0, String.class);
handle = MethodHandles.collectArguments(handle, i, filter);
i += numCaptures;
replaced += numCaptures;
}
handle = MethodHandles.filterArguments(handle, 0, filters);
}
return handle;
}
/**
* Returns an implementation of interfaceClass that calls receiverClass.name
* <p>
* This is just like LambdaMetaFactory, only with a dynamic type. The interface type is known,
* so we simply need to lookup the matching implementation method based on receiver type.
*/
static MethodHandle lookupReference(Lookup lookup, String interfaceClass,
Class<?> receiverClass, String name) throws LambdaConversionException {
Definition.Type interfaceType = Definition.getType(interfaceClass);
Method interfaceMethod = interfaceType.struct.getFunctionalMethod();
if (interfaceMethod == null) {
throw new IllegalArgumentException("Class [" + interfaceClass + "] is not a functional interface");
}
int arity = interfaceMethod.arguments.size();
Method implMethod = lookupMethodInternal(receiverClass, name, arity);
return lookupReferenceInternal(lookup, interfaceType, implMethod.owner.name, implMethod.name, receiverClass);
}
/** Returns a method handle to an implementation of clazz, given method reference signature
* @throws LambdaConversionException if a method reference cannot be converted to an functional interface
*/
private static MethodHandle lookupReference(Lookup lookup, Definition.Type clazz, String signature) throws LambdaConversionException {
int separator = signature.indexOf('.');
FunctionRef ref = new FunctionRef(clazz, signature.substring(0, separator), signature.substring(separator+1));
private static MethodHandle lookupReferenceInternal(Lookup lookup, Definition.Type clazz, String type,
String call, Class<?>... captures) throws LambdaConversionException {
FunctionRef ref = new FunctionRef(clazz, type, call, captures);
final CallSite callSite;
if (ref.needsBridges()) {
callSite = LambdaMetafactory.altMetafactory(lookup,
@ -265,9 +339,7 @@ public final class Def {
ref.samMethodType,
0);
}
// we could actually invoke and cache here (in non-capturing cases), but this is not a speedup.
MethodHandle factory = callSite.dynamicInvoker().asType(MethodType.methodType(clazz.clazz));
return MethodHandles.dropArguments(factory, 0, Object.class);
return callSite.dynamicInvoker().asType(MethodType.methodType(clazz.clazz, captures));
}

View File

@ -60,6 +60,8 @@ public final class DefBootstrap {
public static final int ARRAY_STORE = 4;
/** static bootstrap parameter indicating a dynamic iteration, e.g. for (x : y) */
public static final int ITERATOR = 5;
/** static bootstrap parameter indicating a dynamic method reference, e.g. foo::bar */
public static final int REFERENCE = 6;
/**
* CallSite that implements the polymorphic inlining cache (PIC).
@ -71,17 +73,15 @@ public final class DefBootstrap {
private final Lookup lookup;
private final String name;
private final int flavor;
private final long recipe;
private final Object[] args;
int depth; // pkg-protected for testing
PIC(Lookup lookup, String name, MethodType type, int flavor, long recipe) {
PIC(Lookup lookup, String name, MethodType type, int flavor, Object[] args) {
super(type);
this.lookup = lookup;
this.name = name;
this.flavor = flavor;
this.recipe = recipe;
assert recipe == 0 || flavor == METHOD_CALL;
assert Long.bitCount(recipe) <= type.parameterCount();
this.args = args;
final MethodHandle fallback = FALLBACK.bindTo(this)
.asCollector(Object[].class, type.parameterCount())
@ -101,10 +101,10 @@ public final class DefBootstrap {
/**
* Does a slow lookup against the whitelist.
*/
private MethodHandle lookup(int flavor, Class<?> clazz, String name, Object[] args, long recipe) throws Throwable {
private MethodHandle lookup(int flavor, Class<?> clazz, String name, Object[] args) throws Throwable {
switch(flavor) {
case METHOD_CALL:
return Def.lookupMethod(lookup, clazz, name, args, recipe);
return Def.lookupMethod(lookup, type(), clazz, name, args, (Long) this.args[0]);
case LOAD:
return Def.lookupGetter(clazz, name);
case STORE:
@ -115,6 +115,8 @@ public final class DefBootstrap {
return Def.lookupArrayStore(clazz);
case ITERATOR:
return Def.lookupIterator(clazz);
case REFERENCE:
return Def.lookupReference(lookup, (String) this.args[0], clazz, name);
default: throw new AssertionError();
}
}
@ -128,7 +130,7 @@ public final class DefBootstrap {
final MethodType type = type();
final Object receiver = args[0];
final Class<?> receiverClass = receiver.getClass();
final MethodHandle target = lookup(flavor, receiverClass, name, args, recipe).asType(type);
final MethodHandle target = lookup(flavor, receiverClass, name, args).asType(type);
if (depth >= MAX_DEPTH) {
// revert to a vtable call
@ -170,8 +172,36 @@ public final class DefBootstrap {
* <p>
* see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokedynamic
*/
public static CallSite bootstrap(Lookup lookup, String name, MethodType type, int flavor, long recipe) {
return new PIC(lookup, name, type, flavor, recipe);
public static CallSite bootstrap(Lookup lookup, String name, MethodType type, int flavor, Object... args) {
// validate arguments
switch(flavor) {
case METHOD_CALL:
if (args.length != 1) {
throw new BootstrapMethodError("Invalid number of parameters for method call");
}
if (args[0] instanceof Long == false) {
throw new BootstrapMethodError("Illegal parameter for method call: " + args[0]);
}
long recipe = (Long) args[0];
if (Long.bitCount(recipe) > type.parameterCount()) {
throw new BootstrapMethodError("Illegal recipe for method call: too many bits");
}
break;
case REFERENCE:
if (args.length != 1) {
throw new BootstrapMethodError("Invalid number of parameters for reference call");
}
if (args[0] instanceof String == false) {
throw new BootstrapMethodError("Illegal parameter for reference call: " + args[0]);
}
break;
default:
if (args.length > 0) {
throw new BootstrapMethodError("Illegal static bootstrap parameters for flavor: " + flavor);
}
break;
}
return new PIC(lookup, name, type, flavor, args);
}
}

View File

@ -890,8 +890,7 @@ public final class Definition {
throw new AssertionError(e);
}
}
owner.methods.put(methodKey,
new Method(method.name, owner, method.rtn, method.arguments, method.method, method.modifiers, method.handle));
owner.methods.put(methodKey, method);
}
}

View File

@ -1,5 +1,7 @@
package org.elasticsearch.painless;
import java.util.function.Function;
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
@ -63,4 +65,9 @@ public class FeatureTest {
public static boolean overloadedStatic(boolean whatToReturn) {
return whatToReturn;
}
/** method taking two functions! */
public Object twoFunctionsOfX(Function<Object,Object> f, Function<Object,Object> g) {
return f.apply(g.apply(x));
}
}

View File

@ -53,8 +53,9 @@ public class FunctionRef {
* @param expected interface type to implement.
* @param type the left hand side of a method reference expression
* @param call the right hand side of a method reference expression
* @param captures captured arguments
*/
public FunctionRef(Definition.Type expected, String type, String call) {
public FunctionRef(Definition.Type expected, String type, String call, Class<?>... captures) {
boolean isCtorReference = "new".equals(call);
// check its really a functional interface
// for e.g. Comparable
@ -66,7 +67,7 @@ public class FunctionRef {
// e.g. compareTo
invokedName = method.name;
// e.g. (Object)Comparator
invokedType = MethodType.methodType(expected.clazz);
invokedType = MethodType.methodType(expected.clazz, captures);
// e.g. (Object,Object)int
interfaceMethodType = method.handle.type().dropParameterTypes(0, 1);
// lookup requested method
@ -80,7 +81,15 @@ public class FunctionRef {
Definition.Method staticImpl = struct.staticMethods.get(new Definition.MethodKey(call, method.arguments.size()));
if (staticImpl == null) {
// otherwise a virtual impl
impl = struct.methods.get(new Definition.MethodKey(call, method.arguments.size()-1));
final int arity;
if (captures.length > 0) {
// receiver captured
arity = method.arguments.size();
} else {
// receiver passed
arity = method.arguments.size() - 1;
}
impl = struct.methods.get(new Definition.MethodKey(call, arity));
} else {
impl = staticImpl;
}
@ -98,12 +107,19 @@ public class FunctionRef {
} else {
tag = Opcodes.H_INVOKEVIRTUAL;
}
if (impl.owner.clazz.isInterface()) {
implMethodASM = new Handle(tag, struct.type.getInternalName(), impl.name, impl.method.getDescriptor());
} else {
implMethodASM = new Handle(tag, impl.owner.type.getInternalName(), impl.name, impl.method.getDescriptor());
}
implMethod = impl.handle;
if (isCtorReference) {
samMethodType = MethodType.methodType(interfaceMethodType.returnType(), impl.handle.type().parameterArray());
} else if (Modifier.isStatic(impl.modifiers)) {
samMethodType = impl.handle.type();
} else if (captures.length > 0) {
// drop the receiver, we capture it
samMethodType = impl.handle.type().dropParameterTypes(0, 1);
} else {
// ensure the receiver type is exact and not a superclass type
samMethodType = impl.handle.type().changeParameterType(0, struct.clazz);

View File

@ -22,7 +22,6 @@ package org.elasticsearch.painless;
import org.elasticsearch.painless.Definition.Cast;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;

View File

@ -119,7 +119,7 @@ final class ScriptImpl implements ExecutableScript, LeafSearchScript {
public Object run() {
try {
return executable.execute(variables, scorer, doc, aggregationValue);
} catch (PainlessError | BootstrapMethodError | Exception t) {
} catch (PainlessError | BootstrapMethodError | IllegalAccessError | Exception t) {
throw convertToScriptException(t);
}
}

View File

@ -68,7 +68,7 @@ public final class WriterConstants {
/** dynamic callsite bootstrap signature */
public final static MethodType DEF_BOOTSTRAP_TYPE =
MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, int.class, long.class);
MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, int.class, Object[].class);
public final static Handle DEF_BOOTSTRAP_HANDLE =
new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(DefBootstrap.class),
"bootstrap", DEF_BOOTSTRAP_TYPE.toMethodDescriptorString());

View File

@ -2840,7 +2840,10 @@ class PainlessParser extends Parser {
public static class FuncrefContext extends ParserRuleContext {
public TerminalNode TYPE() { return getToken(PainlessParser.TYPE, 0); }
public TerminalNode REF() { return getToken(PainlessParser.REF, 0); }
public TerminalNode ID() { return getToken(PainlessParser.ID, 0); }
public List<TerminalNode> ID() { return getTokens(PainlessParser.ID); }
public TerminalNode ID(int i) {
return getToken(PainlessParser.ID, i);
}
public TerminalNode NEW() { return getToken(PainlessParser.NEW, 0); }
public FuncrefContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
@ -2858,6 +2861,9 @@ class PainlessParser extends Parser {
enterRule(_localctx, 50, RULE_funcref);
int _la;
try {
setState(443);
switch (_input.LA(1)) {
case TYPE:
enterOuterAlt(_localctx, 1);
{
setState(437);
@ -2872,6 +2878,21 @@ class PainlessParser extends Parser {
consume();
}
}
break;
case ID:
enterOuterAlt(_localctx, 2);
{
setState(440);
match(ID);
setState(441);
match(REF);
setState(442);
match(ID);
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
@ -2974,7 +2995,7 @@ class PainlessParser extends Parser {
}
public static final String _serializedATN =
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3N\u01bc\4\2\t\2\4"+
"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3N\u01c0\4\2\t\2\4"+
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
"\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+
"\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+
@ -3007,138 +3028,140 @@ class PainlessParser extends Parser {
"\3\27\7\27\u0193\n\27\f\27\16\27\u0196\13\27\5\27\u0198\n\27\3\27\3\27"+
"\3\30\3\30\3\30\5\30\u019f\n\30\3\31\3\31\3\31\3\31\3\31\7\31\u01a6\n"+
"\31\f\31\16\31\u01a9\13\31\5\31\u01ab\n\31\3\31\5\31\u01ae\n\31\3\31\3"+
"\31\3\31\3\32\5\32\u01b4\n\32\3\32\3\32\3\33\3\33\3\33\3\33\3\33\2\3\36"+
"\34\2\4\6\b\n\f\16\20\22\24\26\30\32\34\36 \"$&(*,.\60\62\64\2\16\3\3"+
"\r\r\3\2\67B\3\2\34\36\3\2\37 \3\2!#\3\2$\'\3\2(+\3\2\65\66\3\2CF\4\2"+
"\32\33\37 \3\2MN\4\2\26\26LL\u01e7\29\3\2\2\2\4D\3\2\2\2\6I\3\2\2\2\b"+
"\u00a7\3\2\2\2\n\u00ab\3\2\2\2\f\u00ad\3\2\2\2\16\u00b6\3\2\2\2\20\u00ba"+
"\3\2\2\2\22\u00bc\3\2\2\2\24\u00be\3\2\2\2\26\u00c7\3\2\2\2\30\u00cf\3"+
"\2\2\2\32\u00d4\3\2\2\2\34\u00db\3\2\2\2\36\u00e6\3\2\2\2 \u0143\3\2\2"+
"\2\"\u0167\3\2\2\2$\u017b\3\2\2\2&\u0181\3\2\2\2(\u0188\3\2\2\2*\u018a"+
"\3\2\2\2,\u018e\3\2\2\2.\u019e\3\2\2\2\60\u01ad\3\2\2\2\62\u01b3\3\2\2"+
"\2\64\u01b7\3\2\2\2\668\5\4\3\2\67\66\3\2\2\28;\3\2\2\29\67\3\2\2\29:"+
"\3\2\2\2:?\3\2\2\2;9\3\2\2\2<>\5\b\5\2=<\3\2\2\2>A\3\2\2\2?=\3\2\2\2?"+
"@\3\2\2\2@B\3\2\2\2A?\3\2\2\2BC\7\2\2\3C\3\3\2\2\2DE\5\26\f\2EF\7L\2\2"+
"FG\5\6\4\2GH\5\f\7\2H\5\3\2\2\2IU\7\t\2\2JK\5\26\f\2KR\7L\2\2LM\7\f\2"+
"\2MN\5\26\f\2NO\7L\2\2OQ\3\2\2\2PL\3\2\2\2QT\3\2\2\2RP\3\2\2\2RS\3\2\2"+
"\2SV\3\2\2\2TR\3\2\2\2UJ\3\2\2\2UV\3\2\2\2VW\3\2\2\2WX\7\n\2\2X\7\3\2"+
"\2\2YZ\7\16\2\2Z[\7\t\2\2[\\\5\36\20\2\\]\7\n\2\2]a\5\n\6\2^_\7\17\2\2"+
"_b\5\n\6\2`b\6\5\2\2a^\3\2\2\2a`\3\2\2\2b\u00a8\3\2\2\2cd\7\20\2\2de\7"+
"\t\2\2ef\5\36\20\2fi\7\n\2\2gj\5\n\6\2hj\5\16\b\2ig\3\2\2\2ih\3\2\2\2"+
"j\u00a8\3\2\2\2kl\7\21\2\2lm\5\f\7\2mn\7\20\2\2no\7\t\2\2op\5\36\20\2"+
"pq\7\n\2\2qr\5\34\17\2r\u00a8\3\2\2\2st\7\22\2\2tv\7\t\2\2uw\5\20\t\2"+
"vu\3\2\2\2vw\3\2\2\2wx\3\2\2\2xz\7\r\2\2y{\5\36\20\2zy\3\2\2\2z{\3\2\2"+
"\2{|\3\2\2\2|~\7\r\2\2}\177\5\22\n\2~}\3\2\2\2~\177\3\2\2\2\177\u0080"+
"\3\2\2\2\u0080\u0083\7\n\2\2\u0081\u0084\5\n\6\2\u0082\u0084\5\16\b\2"+
"\u0083\u0081\3\2\2\2\u0083\u0082\3\2\2\2\u0084\u00a8\3\2\2\2\u0085\u0086"+
"\7\22\2\2\u0086\u0087\7\t\2\2\u0087\u0088\5\26\f\2\u0088\u0089\7L\2\2"+
"\u0089\u008a\7\62\2\2\u008a\u008b\5\36\20\2\u008b\u008c\7\n\2\2\u008c"+
"\u008d\5\n\6\2\u008d\u00a8\3\2\2\2\u008e\u008f\5\24\13\2\u008f\u0090\5"+
"\34\17\2\u0090\u00a8\3\2\2\2\u0091\u0092\7\23\2\2\u0092\u00a8\5\34\17"+
"\2\u0093\u0094\7\24\2\2\u0094\u00a8\5\34\17\2\u0095\u0096\7\25\2\2\u0096"+
"\u0097\5\36\20\2\u0097\u0098\5\34\17\2\u0098\u00a8\3\2\2\2\u0099\u009a"+
"\7\27\2\2\u009a\u009c\5\f\7\2\u009b\u009d\5\32\16\2\u009c\u009b\3\2\2"+
"\2\u009d\u009e\3\2\2\2\u009e\u009c\3\2\2\2\u009e\u009f\3\2\2\2\u009f\u00a8"+
"\3\2\2\2\u00a0\u00a1\7\31\2\2\u00a1\u00a2\5\36\20\2\u00a2\u00a3\5\34\17"+
"\2\u00a3\u00a8\3\2\2\2\u00a4\u00a5\5\36\20\2\u00a5\u00a6\5\34\17\2\u00a6"+
"\u00a8\3\2\2\2\u00a7Y\3\2\2\2\u00a7c\3\2\2\2\u00a7k\3\2\2\2\u00a7s\3\2"+
"\2\2\u00a7\u0085\3\2\2\2\u00a7\u008e\3\2\2\2\u00a7\u0091\3\2\2\2\u00a7"+
"\u0093\3\2\2\2\u00a7\u0095\3\2\2\2\u00a7\u0099\3\2\2\2\u00a7\u00a0\3\2"+
"\2\2\u00a7\u00a4\3\2\2\2\u00a8\t\3\2\2\2\u00a9\u00ac\5\f\7\2\u00aa\u00ac"+
"\5\b\5\2\u00ab\u00a9\3\2\2\2\u00ab\u00aa\3\2\2\2\u00ac\13\3\2\2\2\u00ad"+
"\u00b1\7\5\2\2\u00ae\u00b0\5\b\5\2\u00af\u00ae\3\2\2\2\u00b0\u00b3\3\2"+
"\2\2\u00b1\u00af\3\2\2\2\u00b1\u00b2\3\2\2\2\u00b2\u00b4\3\2\2\2\u00b3"+
"\u00b1\3\2\2\2\u00b4\u00b5\7\6\2\2\u00b5\r\3\2\2\2\u00b6\u00b7\7\r\2\2"+
"\u00b7\17\3\2\2\2\u00b8\u00bb\5\24\13\2\u00b9\u00bb\5\36\20\2\u00ba\u00b8"+
"\3\2\2\2\u00ba\u00b9\3\2\2\2\u00bb\21\3\2\2\2\u00bc\u00bd\5\36\20\2\u00bd"+
"\23\3\2\2\2\u00be\u00bf\5\26\f\2\u00bf\u00c4\5\30\r\2\u00c0\u00c1\7\f"+
"\2\2\u00c1\u00c3\5\30\r\2\u00c2\u00c0\3\2\2\2\u00c3\u00c6\3\2\2\2\u00c4"+
"\u00c2\3\2\2\2\u00c4\u00c5\3\2\2\2\u00c5\25\3\2\2\2\u00c6\u00c4\3\2\2"+
"\2\u00c7\u00cc\7K\2\2\u00c8\u00c9\7\7\2\2\u00c9\u00cb\7\b\2\2\u00ca\u00c8"+
"\3\2\2\2\u00cb\u00ce\3\2\2\2\u00cc\u00ca\3\2\2\2\u00cc\u00cd\3\2\2\2\u00cd"+
"\27\3\2\2\2\u00ce\u00cc\3\2\2\2\u00cf\u00d2\7L\2\2\u00d0\u00d1\7\67\2"+
"\2\u00d1\u00d3\5\36\20\2\u00d2\u00d0\3\2\2\2\u00d2\u00d3\3\2\2\2\u00d3"+
"\31\3\2\2\2\u00d4\u00d5\7\30\2\2\u00d5\u00d6\7\t\2\2\u00d6\u00d7\7K\2"+
"\2\u00d7\u00d8\7L\2\2\u00d8\u00d9\7\n\2\2\u00d9\u00da\5\f\7\2\u00da\33"+
"\3\2\2\2\u00db\u00dc\t\2\2\2\u00dc\35\3\2\2\2\u00dd\u00de\b\20\1\2\u00de"+
"\u00df\5\"\22\2\u00df\u00e0\t\3\2\2\u00e0\u00e1\5\36\20\3\u00e1\u00e2"+
"\b\20\1\2\u00e2\u00e7\3\2\2\2\u00e3\u00e4\5 \21\2\u00e4\u00e5\b\20\1\2"+
"\u00e5\u00e7\3\2\2\2\u00e6\u00dd\3\2\2\2\u00e6\u00e3\3\2\2\2\u00e7\u0123"+
"\3\2\2\2\u00e8\u00e9\f\16\2\2\u00e9\u00ea\t\4\2\2\u00ea\u00eb\5\36\20"+
"\17\u00eb\u00ec\b\20\1\2\u00ec\u0122\3\2\2\2\u00ed\u00ee\f\r\2\2\u00ee"+
"\u00ef\t\5\2\2\u00ef\u00f0\5\36\20\16\u00f0\u00f1\b\20\1\2\u00f1\u0122"+
"\3\2\2\2\u00f2\u00f3\f\f\2\2\u00f3\u00f4\t\6\2\2\u00f4\u00f5\5\36\20\r"+
"\u00f5\u00f6\b\20\1\2\u00f6\u0122\3\2\2\2\u00f7\u00f8\f\13\2\2\u00f8\u00f9"+
"\t\7\2\2\u00f9\u00fa\5\36\20\f\u00fa\u00fb\b\20\1\2\u00fb\u0122\3\2\2"+
"\2\u00fc\u00fd\f\n\2\2\u00fd\u00fe\t\b\2\2\u00fe\u00ff\5\36\20\13\u00ff"+
"\u0100\b\20\1\2\u0100\u0122\3\2\2\2\u0101\u0102\f\t\2\2\u0102\u0103\7"+
",\2\2\u0103\u0104\5\36\20\n\u0104\u0105\b\20\1\2\u0105\u0122\3\2\2\2\u0106"+
"\u0107\f\b\2\2\u0107\u0108\7-\2\2\u0108\u0109\5\36\20\t\u0109\u010a\b"+
"\20\1\2\u010a\u0122\3\2\2\2\u010b\u010c\f\7\2\2\u010c\u010d\7.\2\2\u010d"+
"\u010e\5\36\20\b\u010e\u010f\b\20\1\2\u010f\u0122\3\2\2\2\u0110\u0111"+
"\f\6\2\2\u0111\u0112\7/\2\2\u0112\u0113\5\36\20\7\u0113\u0114\b\20\1\2"+
"\u0114\u0122\3\2\2\2\u0115\u0116\f\5\2\2\u0116\u0117\7\60\2\2\u0117\u0118"+
"\5\36\20\6\u0118\u0119\b\20\1\2\u0119\u0122\3\2\2\2\u011a\u011b\f\4\2"+
"\2\u011b\u011c\7\61\2\2\u011c\u011d\5\36\20\2\u011d\u011e\7\62\2\2\u011e"+
"\u011f\5\36\20\4\u011f\u0120\b\20\1\2\u0120\u0122\3\2\2\2\u0121\u00e8"+
"\3\2\2\2\u0121\u00ed\3\2\2\2\u0121\u00f2\3\2\2\2\u0121\u00f7\3\2\2\2\u0121"+
"\u00fc\3\2\2\2\u0121\u0101\3\2\2\2\u0121\u0106\3\2\2\2\u0121\u010b\3\2"+
"\2\2\u0121\u0110\3\2\2\2\u0121\u0115\3\2\2\2\u0121\u011a\3\2\2\2\u0122"+
"\u0125\3\2\2\2\u0123\u0121\3\2\2\2\u0123\u0124\3\2\2\2\u0124\37\3\2\2"+
"\2\u0125\u0123\3\2\2\2\u0126\u0127\6\21\16\3\u0127\u0128\t\t\2\2\u0128"+
"\u0144\5\"\22\2\u0129\u012a\6\21\17\3\u012a\u012b\5\"\22\2\u012b\u012c"+
"\t\t\2\2\u012c\u0144\3\2\2\2\u012d\u012e\6\21\20\3\u012e\u0144\5\"\22"+
"\2\u012f\u0130\6\21\21\3\u0130\u0131\t\n\2\2\u0131\u0144\b\21\1\2\u0132"+
"\u0133\6\21\22\3\u0133\u0134\7H\2\2\u0134\u0144\b\21\1\2\u0135\u0136\6"+
"\21\23\3\u0136\u0137\7I\2\2\u0137\u0144\b\21\1\2\u0138\u0139\6\21\24\3"+
"\u0139\u013a\7J\2\2\u013a\u0144\b\21\1\2\u013b\u013c\6\21\25\3\u013c\u013d"+
"\t\13\2\2\u013d\u0144\5 \21\2\u013e\u013f\7\t\2\2\u013f\u0140\5\26\f\2"+
"\u0140\u0141\7\n\2\2\u0141\u0142\5 \21\2\u0142\u0144\3\2\2\2\u0143\u0126"+
"\3\2\2\2\u0143\u0129\3\2\2\2\u0143\u012d\3\2\2\2\u0143\u012f\3\2\2\2\u0143"+
"\u0132\3\2\2\2\u0143\u0135\3\2\2\2\u0143\u0138\3\2\2\2\u0143\u013b\3\2"+
"\2\2\u0143\u013e\3\2\2\2\u0144!\3\2\2\2\u0145\u0149\5$\23\2\u0146\u0148"+
"\5&\24\2\u0147\u0146\3\2\2\2\u0148\u014b\3\2\2\2\u0149\u0147\3\2\2\2\u0149"+
"\u014a\3\2\2\2\u014a\u0168\3\2\2\2\u014b\u0149\3\2\2\2\u014c\u014d\5\26"+
"\f\2\u014d\u0151\5(\25\2\u014e\u0150\5&\24\2\u014f\u014e\3\2\2\2\u0150"+
"\u0153\3\2\2\2\u0151\u014f\3\2\2\2\u0151\u0152\3\2\2\2\u0152\u0168\3\2"+
"\2\2\u0153\u0151\3\2\2\2\u0154\u0155\7\26\2\2\u0155\u015a\7K\2\2\u0156"+
"\u0157\7\7\2\2\u0157\u0158\5\36\20\2\u0158\u0159\7\b\2\2\u0159\u015b\3"+
"\2\2\2\u015a\u0156\3\2\2\2\u015b\u015c\3\2\2\2\u015c\u015a\3\2\2\2\u015c"+
"\u015d\3\2\2\2\u015d\u0165\3\2\2\2\u015e\u0162\5(\25\2\u015f\u0161\5&"+
"\24\2\u0160\u015f\3\2\2\2\u0161\u0164\3\2\2\2\u0162\u0160\3\2\2\2\u0162"+
"\u0163\3\2\2\2\u0163\u0166\3\2\2\2\u0164\u0162\3\2\2\2\u0165\u015e\3\2"+
"\2\2\u0165\u0166\3\2\2\2\u0166\u0168\3\2\2\2\u0167\u0145\3\2\2\2\u0167"+
"\u014c\3\2\2\2\u0167\u0154\3\2\2\2\u0168#\3\2\2\2\u0169\u016a\6\23\26"+
"\3\u016a\u016b\7\t\2\2\u016b\u016c\5\36\20\2\u016c\u016d\7\n\2\2\u016d"+
"\u016e\b\23\1\2\u016e\u017c\3\2\2\2\u016f\u0170\6\23\27\3\u0170\u0171"+
"\7\t\2\2\u0171\u0172\5 \21\2\u0172\u0173\7\n\2\2\u0173\u017c\3\2\2\2\u0174"+
"\u017c\7G\2\2\u0175\u017c\7L\2\2\u0176\u0177\7L\2\2\u0177\u017c\5,\27"+
"\2\u0178\u0179\7\26\2\2\u0179\u017a\7K\2\2\u017a\u017c\5,\27\2\u017b\u0169"+
"\3\2\2\2\u017b\u016f\3\2\2\2\u017b\u0174\3\2\2\2\u017b\u0175\3\2\2\2\u017b"+
"\u0176\3\2\2\2\u017b\u0178\3\2\2\2\u017c%\3\2\2\2\u017d\u017e\6\24\30"+
"\3\u017e\u0182\5(\25\2\u017f\u0180\6\24\31\3\u0180\u0182\5*\26\2\u0181"+
"\u017d\3\2\2\2\u0181\u017f\3\2\2\2\u0182\'\3\2\2\2\u0183\u0184\7\13\2"+
"\2\u0184\u0185\7N\2\2\u0185\u0189\5,\27\2\u0186\u0187\7\13\2\2\u0187\u0189"+
"\t\f\2\2\u0188\u0183\3\2\2\2\u0188\u0186\3\2\2\2\u0189)\3\2\2\2\u018a"+
"\u018b\7\7\2\2\u018b\u018c\5\36\20\2\u018c\u018d\7\b\2\2\u018d+\3\2\2"+
"\2\u018e\u0197\7\t\2\2\u018f\u0194\5.\30\2\u0190\u0191\7\f\2\2\u0191\u0193"+
"\5.\30\2\u0192\u0190\3\2\2\2\u0193\u0196\3\2\2\2\u0194\u0192\3\2\2\2\u0194"+
"\u0195\3\2\2\2\u0195\u0198\3\2\2\2\u0196\u0194\3\2\2\2\u0197\u018f\3\2"+
"\2\2\u0197\u0198\3\2\2\2\u0198\u0199\3\2\2\2\u0199\u019a\7\n\2\2\u019a"+
"-\3\2\2\2\u019b\u019f\5\36\20\2\u019c\u019f\5\60\31\2\u019d\u019f\5\64"+
"\33\2\u019e\u019b\3\2\2\2\u019e\u019c\3\2\2\2\u019e\u019d\3\2\2\2\u019f"+
"/\3\2\2\2\u01a0\u01ae\5\62\32\2\u01a1\u01aa\7\t\2\2\u01a2\u01a7\5\62\32"+
"\2\u01a3\u01a4\7\f\2\2\u01a4\u01a6\5\62\32\2\u01a5\u01a3\3\2\2\2\u01a6"+
"\u01a9\3\2\2\2\u01a7\u01a5\3\2\2\2\u01a7\u01a8\3\2\2\2\u01a8\u01ab\3\2"+
"\2\2\u01a9\u01a7\3\2\2\2\u01aa\u01a2\3\2\2\2\u01aa\u01ab\3\2\2\2\u01ab"+
"\u01ac\3\2\2\2\u01ac\u01ae\7\n\2\2\u01ad\u01a0\3\2\2\2\u01ad\u01a1\3\2"+
"\2\2\u01ae\u01af\3\2\2\2\u01af\u01b0\7\64\2\2\u01b0\u01b1\5\f\7\2\u01b1"+
"\61\3\2\2\2\u01b2\u01b4\5\26\f\2\u01b3\u01b2\3\2\2\2\u01b3\u01b4\3\2\2"+
"\2\u01b4\u01b5\3\2\2\2\u01b5\u01b6\7L\2\2\u01b6\63\3\2\2\2\u01b7\u01b8"+
"\7K\2\2\u01b8\u01b9\7\63\2\2\u01b9\u01ba\t\r\2\2\u01ba\65\3\2\2\2(9?R"+
"Uaivz~\u0083\u009e\u00a7\u00ab\u00b1\u00ba\u00c4\u00cc\u00d2\u00e6\u0121"+
"\u0123\u0143\u0149\u0151\u015c\u0162\u0165\u0167\u017b\u0181\u0188\u0194"+
"\u0197\u019e\u01a7\u01aa\u01ad\u01b3";
"\31\3\31\3\32\5\32\u01b4\n\32\3\32\3\32\3\33\3\33\3\33\3\33\3\33\3\33"+
"\5\33\u01be\n\33\3\33\2\3\36\34\2\4\6\b\n\f\16\20\22\24\26\30\32\34\36"+
" \"$&(*,.\60\62\64\2\16\3\3\r\r\3\2\67B\3\2\34\36\3\2\37 \3\2!#\3\2$\'"+
"\3\2(+\3\2\65\66\3\2CF\4\2\32\33\37 \3\2MN\4\2\26\26LL\u01ec\29\3\2\2"+
"\2\4D\3\2\2\2\6I\3\2\2\2\b\u00a7\3\2\2\2\n\u00ab\3\2\2\2\f\u00ad\3\2\2"+
"\2\16\u00b6\3\2\2\2\20\u00ba\3\2\2\2\22\u00bc\3\2\2\2\24\u00be\3\2\2\2"+
"\26\u00c7\3\2\2\2\30\u00cf\3\2\2\2\32\u00d4\3\2\2\2\34\u00db\3\2\2\2\36"+
"\u00e6\3\2\2\2 \u0143\3\2\2\2\"\u0167\3\2\2\2$\u017b\3\2\2\2&\u0181\3"+
"\2\2\2(\u0188\3\2\2\2*\u018a\3\2\2\2,\u018e\3\2\2\2.\u019e\3\2\2\2\60"+
"\u01ad\3\2\2\2\62\u01b3\3\2\2\2\64\u01bd\3\2\2\2\668\5\4\3\2\67\66\3\2"+
"\2\28;\3\2\2\29\67\3\2\2\29:\3\2\2\2:?\3\2\2\2;9\3\2\2\2<>\5\b\5\2=<\3"+
"\2\2\2>A\3\2\2\2?=\3\2\2\2?@\3\2\2\2@B\3\2\2\2A?\3\2\2\2BC\7\2\2\3C\3"+
"\3\2\2\2DE\5\26\f\2EF\7L\2\2FG\5\6\4\2GH\5\f\7\2H\5\3\2\2\2IU\7\t\2\2"+
"JK\5\26\f\2KR\7L\2\2LM\7\f\2\2MN\5\26\f\2NO\7L\2\2OQ\3\2\2\2PL\3\2\2\2"+
"QT\3\2\2\2RP\3\2\2\2RS\3\2\2\2SV\3\2\2\2TR\3\2\2\2UJ\3\2\2\2UV\3\2\2\2"+
"VW\3\2\2\2WX\7\n\2\2X\7\3\2\2\2YZ\7\16\2\2Z[\7\t\2\2[\\\5\36\20\2\\]\7"+
"\n\2\2]a\5\n\6\2^_\7\17\2\2_b\5\n\6\2`b\6\5\2\2a^\3\2\2\2a`\3\2\2\2b\u00a8"+
"\3\2\2\2cd\7\20\2\2de\7\t\2\2ef\5\36\20\2fi\7\n\2\2gj\5\n\6\2hj\5\16\b"+
"\2ig\3\2\2\2ih\3\2\2\2j\u00a8\3\2\2\2kl\7\21\2\2lm\5\f\7\2mn\7\20\2\2"+
"no\7\t\2\2op\5\36\20\2pq\7\n\2\2qr\5\34\17\2r\u00a8\3\2\2\2st\7\22\2\2"+
"tv\7\t\2\2uw\5\20\t\2vu\3\2\2\2vw\3\2\2\2wx\3\2\2\2xz\7\r\2\2y{\5\36\20"+
"\2zy\3\2\2\2z{\3\2\2\2{|\3\2\2\2|~\7\r\2\2}\177\5\22\n\2~}\3\2\2\2~\177"+
"\3\2\2\2\177\u0080\3\2\2\2\u0080\u0083\7\n\2\2\u0081\u0084\5\n\6\2\u0082"+
"\u0084\5\16\b\2\u0083\u0081\3\2\2\2\u0083\u0082\3\2\2\2\u0084\u00a8\3"+
"\2\2\2\u0085\u0086\7\22\2\2\u0086\u0087\7\t\2\2\u0087\u0088\5\26\f\2\u0088"+
"\u0089\7L\2\2\u0089\u008a\7\62\2\2\u008a\u008b\5\36\20\2\u008b\u008c\7"+
"\n\2\2\u008c\u008d\5\n\6\2\u008d\u00a8\3\2\2\2\u008e\u008f\5\24\13\2\u008f"+
"\u0090\5\34\17\2\u0090\u00a8\3\2\2\2\u0091\u0092\7\23\2\2\u0092\u00a8"+
"\5\34\17\2\u0093\u0094\7\24\2\2\u0094\u00a8\5\34\17\2\u0095\u0096\7\25"+
"\2\2\u0096\u0097\5\36\20\2\u0097\u0098\5\34\17\2\u0098\u00a8\3\2\2\2\u0099"+
"\u009a\7\27\2\2\u009a\u009c\5\f\7\2\u009b\u009d\5\32\16\2\u009c\u009b"+
"\3\2\2\2\u009d\u009e\3\2\2\2\u009e\u009c\3\2\2\2\u009e\u009f\3\2\2\2\u009f"+
"\u00a8\3\2\2\2\u00a0\u00a1\7\31\2\2\u00a1\u00a2\5\36\20\2\u00a2\u00a3"+
"\5\34\17\2\u00a3\u00a8\3\2\2\2\u00a4\u00a5\5\36\20\2\u00a5\u00a6\5\34"+
"\17\2\u00a6\u00a8\3\2\2\2\u00a7Y\3\2\2\2\u00a7c\3\2\2\2\u00a7k\3\2\2\2"+
"\u00a7s\3\2\2\2\u00a7\u0085\3\2\2\2\u00a7\u008e\3\2\2\2\u00a7\u0091\3"+
"\2\2\2\u00a7\u0093\3\2\2\2\u00a7\u0095\3\2\2\2\u00a7\u0099\3\2\2\2\u00a7"+
"\u00a0\3\2\2\2\u00a7\u00a4\3\2\2\2\u00a8\t\3\2\2\2\u00a9\u00ac\5\f\7\2"+
"\u00aa\u00ac\5\b\5\2\u00ab\u00a9\3\2\2\2\u00ab\u00aa\3\2\2\2\u00ac\13"+
"\3\2\2\2\u00ad\u00b1\7\5\2\2\u00ae\u00b0\5\b\5\2\u00af\u00ae\3\2\2\2\u00b0"+
"\u00b3\3\2\2\2\u00b1\u00af\3\2\2\2\u00b1\u00b2\3\2\2\2\u00b2\u00b4\3\2"+
"\2\2\u00b3\u00b1\3\2\2\2\u00b4\u00b5\7\6\2\2\u00b5\r\3\2\2\2\u00b6\u00b7"+
"\7\r\2\2\u00b7\17\3\2\2\2\u00b8\u00bb\5\24\13\2\u00b9\u00bb\5\36\20\2"+
"\u00ba\u00b8\3\2\2\2\u00ba\u00b9\3\2\2\2\u00bb\21\3\2\2\2\u00bc\u00bd"+
"\5\36\20\2\u00bd\23\3\2\2\2\u00be\u00bf\5\26\f\2\u00bf\u00c4\5\30\r\2"+
"\u00c0\u00c1\7\f\2\2\u00c1\u00c3\5\30\r\2\u00c2\u00c0\3\2\2\2\u00c3\u00c6"+
"\3\2\2\2\u00c4\u00c2\3\2\2\2\u00c4\u00c5\3\2\2\2\u00c5\25\3\2\2\2\u00c6"+
"\u00c4\3\2\2\2\u00c7\u00cc\7K\2\2\u00c8\u00c9\7\7\2\2\u00c9\u00cb\7\b"+
"\2\2\u00ca\u00c8\3\2\2\2\u00cb\u00ce\3\2\2\2\u00cc\u00ca\3\2\2\2\u00cc"+
"\u00cd\3\2\2\2\u00cd\27\3\2\2\2\u00ce\u00cc\3\2\2\2\u00cf\u00d2\7L\2\2"+
"\u00d0\u00d1\7\67\2\2\u00d1\u00d3\5\36\20\2\u00d2\u00d0\3\2\2\2\u00d2"+
"\u00d3\3\2\2\2\u00d3\31\3\2\2\2\u00d4\u00d5\7\30\2\2\u00d5\u00d6\7\t\2"+
"\2\u00d6\u00d7\7K\2\2\u00d7\u00d8\7L\2\2\u00d8\u00d9\7\n\2\2\u00d9\u00da"+
"\5\f\7\2\u00da\33\3\2\2\2\u00db\u00dc\t\2\2\2\u00dc\35\3\2\2\2\u00dd\u00de"+
"\b\20\1\2\u00de\u00df\5\"\22\2\u00df\u00e0\t\3\2\2\u00e0\u00e1\5\36\20"+
"\3\u00e1\u00e2\b\20\1\2\u00e2\u00e7\3\2\2\2\u00e3\u00e4\5 \21\2\u00e4"+
"\u00e5\b\20\1\2\u00e5\u00e7\3\2\2\2\u00e6\u00dd\3\2\2\2\u00e6\u00e3\3"+
"\2\2\2\u00e7\u0123\3\2\2\2\u00e8\u00e9\f\16\2\2\u00e9\u00ea\t\4\2\2\u00ea"+
"\u00eb\5\36\20\17\u00eb\u00ec\b\20\1\2\u00ec\u0122\3\2\2\2\u00ed\u00ee"+
"\f\r\2\2\u00ee\u00ef\t\5\2\2\u00ef\u00f0\5\36\20\16\u00f0\u00f1\b\20\1"+
"\2\u00f1\u0122\3\2\2\2\u00f2\u00f3\f\f\2\2\u00f3\u00f4\t\6\2\2\u00f4\u00f5"+
"\5\36\20\r\u00f5\u00f6\b\20\1\2\u00f6\u0122\3\2\2\2\u00f7\u00f8\f\13\2"+
"\2\u00f8\u00f9\t\7\2\2\u00f9\u00fa\5\36\20\f\u00fa\u00fb\b\20\1\2\u00fb"+
"\u0122\3\2\2\2\u00fc\u00fd\f\n\2\2\u00fd\u00fe\t\b\2\2\u00fe\u00ff\5\36"+
"\20\13\u00ff\u0100\b\20\1\2\u0100\u0122\3\2\2\2\u0101\u0102\f\t\2\2\u0102"+
"\u0103\7,\2\2\u0103\u0104\5\36\20\n\u0104\u0105\b\20\1\2\u0105\u0122\3"+
"\2\2\2\u0106\u0107\f\b\2\2\u0107\u0108\7-\2\2\u0108\u0109\5\36\20\t\u0109"+
"\u010a\b\20\1\2\u010a\u0122\3\2\2\2\u010b\u010c\f\7\2\2\u010c\u010d\7"+
".\2\2\u010d\u010e\5\36\20\b\u010e\u010f\b\20\1\2\u010f\u0122\3\2\2\2\u0110"+
"\u0111\f\6\2\2\u0111\u0112\7/\2\2\u0112\u0113\5\36\20\7\u0113\u0114\b"+
"\20\1\2\u0114\u0122\3\2\2\2\u0115\u0116\f\5\2\2\u0116\u0117\7\60\2\2\u0117"+
"\u0118\5\36\20\6\u0118\u0119\b\20\1\2\u0119\u0122\3\2\2\2\u011a\u011b"+
"\f\4\2\2\u011b\u011c\7\61\2\2\u011c\u011d\5\36\20\2\u011d\u011e\7\62\2"+
"\2\u011e\u011f\5\36\20\4\u011f\u0120\b\20\1\2\u0120\u0122\3\2\2\2\u0121"+
"\u00e8\3\2\2\2\u0121\u00ed\3\2\2\2\u0121\u00f2\3\2\2\2\u0121\u00f7\3\2"+
"\2\2\u0121\u00fc\3\2\2\2\u0121\u0101\3\2\2\2\u0121\u0106\3\2\2\2\u0121"+
"\u010b\3\2\2\2\u0121\u0110\3\2\2\2\u0121\u0115\3\2\2\2\u0121\u011a\3\2"+
"\2\2\u0122\u0125\3\2\2\2\u0123\u0121\3\2\2\2\u0123\u0124\3\2\2\2\u0124"+
"\37\3\2\2\2\u0125\u0123\3\2\2\2\u0126\u0127\6\21\16\3\u0127\u0128\t\t"+
"\2\2\u0128\u0144\5\"\22\2\u0129\u012a\6\21\17\3\u012a\u012b\5\"\22\2\u012b"+
"\u012c\t\t\2\2\u012c\u0144\3\2\2\2\u012d\u012e\6\21\20\3\u012e\u0144\5"+
"\"\22\2\u012f\u0130\6\21\21\3\u0130\u0131\t\n\2\2\u0131\u0144\b\21\1\2"+
"\u0132\u0133\6\21\22\3\u0133\u0134\7H\2\2\u0134\u0144\b\21\1\2\u0135\u0136"+
"\6\21\23\3\u0136\u0137\7I\2\2\u0137\u0144\b\21\1\2\u0138\u0139\6\21\24"+
"\3\u0139\u013a\7J\2\2\u013a\u0144\b\21\1\2\u013b\u013c\6\21\25\3\u013c"+
"\u013d\t\13\2\2\u013d\u0144\5 \21\2\u013e\u013f\7\t\2\2\u013f\u0140\5"+
"\26\f\2\u0140\u0141\7\n\2\2\u0141\u0142\5 \21\2\u0142\u0144\3\2\2\2\u0143"+
"\u0126\3\2\2\2\u0143\u0129\3\2\2\2\u0143\u012d\3\2\2\2\u0143\u012f\3\2"+
"\2\2\u0143\u0132\3\2\2\2\u0143\u0135\3\2\2\2\u0143\u0138\3\2\2\2\u0143"+
"\u013b\3\2\2\2\u0143\u013e\3\2\2\2\u0144!\3\2\2\2\u0145\u0149\5$\23\2"+
"\u0146\u0148\5&\24\2\u0147\u0146\3\2\2\2\u0148\u014b\3\2\2\2\u0149\u0147"+
"\3\2\2\2\u0149\u014a\3\2\2\2\u014a\u0168\3\2\2\2\u014b\u0149\3\2\2\2\u014c"+
"\u014d\5\26\f\2\u014d\u0151\5(\25\2\u014e\u0150\5&\24\2\u014f\u014e\3"+
"\2\2\2\u0150\u0153\3\2\2\2\u0151\u014f\3\2\2\2\u0151\u0152\3\2\2\2\u0152"+
"\u0168\3\2\2\2\u0153\u0151\3\2\2\2\u0154\u0155\7\26\2\2\u0155\u015a\7"+
"K\2\2\u0156\u0157\7\7\2\2\u0157\u0158\5\36\20\2\u0158\u0159\7\b\2\2\u0159"+
"\u015b\3\2\2\2\u015a\u0156\3\2\2\2\u015b\u015c\3\2\2\2\u015c\u015a\3\2"+
"\2\2\u015c\u015d\3\2\2\2\u015d\u0165\3\2\2\2\u015e\u0162\5(\25\2\u015f"+
"\u0161\5&\24\2\u0160\u015f\3\2\2\2\u0161\u0164\3\2\2\2\u0162\u0160\3\2"+
"\2\2\u0162\u0163\3\2\2\2\u0163\u0166\3\2\2\2\u0164\u0162\3\2\2\2\u0165"+
"\u015e\3\2\2\2\u0165\u0166\3\2\2\2\u0166\u0168\3\2\2\2\u0167\u0145\3\2"+
"\2\2\u0167\u014c\3\2\2\2\u0167\u0154\3\2\2\2\u0168#\3\2\2\2\u0169\u016a"+
"\6\23\26\3\u016a\u016b\7\t\2\2\u016b\u016c\5\36\20\2\u016c\u016d\7\n\2"+
"\2\u016d\u016e\b\23\1\2\u016e\u017c\3\2\2\2\u016f\u0170\6\23\27\3\u0170"+
"\u0171\7\t\2\2\u0171\u0172\5 \21\2\u0172\u0173\7\n\2\2\u0173\u017c\3\2"+
"\2\2\u0174\u017c\7G\2\2\u0175\u017c\7L\2\2\u0176\u0177\7L\2\2\u0177\u017c"+
"\5,\27\2\u0178\u0179\7\26\2\2\u0179\u017a\7K\2\2\u017a\u017c\5,\27\2\u017b"+
"\u0169\3\2\2\2\u017b\u016f\3\2\2\2\u017b\u0174\3\2\2\2\u017b\u0175\3\2"+
"\2\2\u017b\u0176\3\2\2\2\u017b\u0178\3\2\2\2\u017c%\3\2\2\2\u017d\u017e"+
"\6\24\30\3\u017e\u0182\5(\25\2\u017f\u0180\6\24\31\3\u0180\u0182\5*\26"+
"\2\u0181\u017d\3\2\2\2\u0181\u017f\3\2\2\2\u0182\'\3\2\2\2\u0183\u0184"+
"\7\13\2\2\u0184\u0185\7N\2\2\u0185\u0189\5,\27\2\u0186\u0187\7\13\2\2"+
"\u0187\u0189\t\f\2\2\u0188\u0183\3\2\2\2\u0188\u0186\3\2\2\2\u0189)\3"+
"\2\2\2\u018a\u018b\7\7\2\2\u018b\u018c\5\36\20\2\u018c\u018d\7\b\2\2\u018d"+
"+\3\2\2\2\u018e\u0197\7\t\2\2\u018f\u0194\5.\30\2\u0190\u0191\7\f\2\2"+
"\u0191\u0193\5.\30\2\u0192\u0190\3\2\2\2\u0193\u0196\3\2\2\2\u0194\u0192"+
"\3\2\2\2\u0194\u0195\3\2\2\2\u0195\u0198\3\2\2\2\u0196\u0194\3\2\2\2\u0197"+
"\u018f\3\2\2\2\u0197\u0198\3\2\2\2\u0198\u0199\3\2\2\2\u0199\u019a\7\n"+
"\2\2\u019a-\3\2\2\2\u019b\u019f\5\36\20\2\u019c\u019f\5\60\31\2\u019d"+
"\u019f\5\64\33\2\u019e\u019b\3\2\2\2\u019e\u019c\3\2\2\2\u019e\u019d\3"+
"\2\2\2\u019f/\3\2\2\2\u01a0\u01ae\5\62\32\2\u01a1\u01aa\7\t\2\2\u01a2"+
"\u01a7\5\62\32\2\u01a3\u01a4\7\f\2\2\u01a4\u01a6\5\62\32\2\u01a5\u01a3"+
"\3\2\2\2\u01a6\u01a9\3\2\2\2\u01a7\u01a5\3\2\2\2\u01a7\u01a8\3\2\2\2\u01a8"+
"\u01ab\3\2\2\2\u01a9\u01a7\3\2\2\2\u01aa\u01a2\3\2\2\2\u01aa\u01ab\3\2"+
"\2\2\u01ab\u01ac\3\2\2\2\u01ac\u01ae\7\n\2\2\u01ad\u01a0\3\2\2\2\u01ad"+
"\u01a1\3\2\2\2\u01ae\u01af\3\2\2\2\u01af\u01b0\7\64\2\2\u01b0\u01b1\5"+
"\f\7\2\u01b1\61\3\2\2\2\u01b2\u01b4\5\26\f\2\u01b3\u01b2\3\2\2\2\u01b3"+
"\u01b4\3\2\2\2\u01b4\u01b5\3\2\2\2\u01b5\u01b6\7L\2\2\u01b6\63\3\2\2\2"+
"\u01b7\u01b8\7K\2\2\u01b8\u01b9\7\63\2\2\u01b9\u01be\t\r\2\2\u01ba\u01bb"+
"\7L\2\2\u01bb\u01bc\7\63\2\2\u01bc\u01be\7L\2\2\u01bd\u01b7\3\2\2\2\u01bd"+
"\u01ba\3\2\2\2\u01be\65\3\2\2\2)9?RUaivz~\u0083\u009e\u00a7\u00ab\u00b1"+
"\u00ba\u00c4\u00cc\u00d2\u00e6\u0121\u0123\u0143\u0149\u0151\u015c\u0162"+
"\u0165\u0167\u017b\u0181\u0188\u0194\u0197\u019e\u01a7\u01aa\u01ad\u01b3"+
"\u01bd";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {

View File

@ -102,6 +102,7 @@ import org.elasticsearch.painless.node.AStatement;
import org.elasticsearch.painless.node.EBinary;
import org.elasticsearch.painless.node.EBool;
import org.elasticsearch.painless.node.EBoolean;
import org.elasticsearch.painless.node.ECapturingFunctionRef;
import org.elasticsearch.painless.node.EChain;
import org.elasticsearch.painless.node.EComp;
import org.elasticsearch.painless.node.EConditional;
@ -448,7 +449,6 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
}
@Override
public Object visitDeclvar(DeclvarContext ctx) {
throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
}
@ -949,14 +949,18 @@ public final class Walker extends PainlessParserBaseVisitor<Object> {
@Override
public Object visitFuncref(FuncrefContext ctx) {
if (ctx.TYPE() != null) {
// non-capturing Type::method or Type::new
final String methodText;
if (ctx.ID() != null) {
methodText = ctx.ID().getText();
} else if (ctx.NEW() != null ){
if (ctx.NEW() != null) {
methodText = ctx.NEW().getText();
} else {
throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
methodText = ctx.ID(0).getText();
}
return new EFunctionRef(location(ctx), ctx.TYPE().getText(), methodText);
} else {
// capturing object::method
return new ECapturingFunctionRef(location(ctx), ctx.ID(0).getText(), ctx.ID(1).getText());
}
}
}

View File

@ -0,0 +1,119 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.painless.node;
import org.elasticsearch.painless.DefBootstrap;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.FunctionRef;
import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.MethodWriter;
import org.elasticsearch.painless.Locals;
import org.elasticsearch.painless.Locals.Variable;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE;
import static org.elasticsearch.painless.WriterConstants.LAMBDA_BOOTSTRAP_HANDLE;
import java.lang.invoke.LambdaMetafactory;
/**
* Represents a capturing function reference.
*/
public class ECapturingFunctionRef extends AExpression {
public final String type;
public final String call;
private FunctionRef ref;
Variable captured;
private boolean defInterface;
public ECapturingFunctionRef(Location location, String type, String call) {
super(location);
this.type = type;
this.call = call;
}
@Override
void analyze(Locals variables) {
captured = variables.getVariable(location, type);
if (expected == null) {
defInterface = true;
actual = Definition.getType("String");
} else {
defInterface = false;
// static case
if (captured.type.sort != Definition.Sort.DEF) {
try {
ref = new FunctionRef(expected, captured.type.name, call, captured.type.clazz);
} catch (IllegalArgumentException e) {
throw createError(e);
}
}
actual = expected;
}
}
@Override
void write(MethodWriter writer) {
writer.writeDebugInfo(location);
if (defInterface && captured.type.sort == Definition.Sort.DEF) {
// dynamic interface, dynamic implementation
writer.push("D" + type + "." + call + ",1");
writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.slot);
} else if (defInterface) {
// dynamic interface, typed implementation
writer.push("S" + captured.type.name + "." + call + ",1");
writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.slot);
} else if (ref == null) {
// typed interface, dynamic implementation
writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.slot);
String descriptor = Type.getMethodType(expected.type, captured.type.type).getDescriptor();
writer.invokeDynamic(call, descriptor, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.REFERENCE, expected.name);
} else {
// typed interface, typed implementation
writer.visitVarInsn(captured.type.type.getOpcode(Opcodes.ILOAD), captured.slot);
// convert MethodTypes to asm Type for the constant pool.
String invokedType = ref.invokedType.toMethodDescriptorString();
Type samMethodType = Type.getMethodType(ref.samMethodType.toMethodDescriptorString());
Type interfaceType = Type.getMethodType(ref.interfaceMethodType.toMethodDescriptorString());
if (ref.needsBridges()) {
writer.invokeDynamic(ref.invokedName,
invokedType,
LAMBDA_BOOTSTRAP_HANDLE,
samMethodType,
ref.implMethodASM,
samMethodType,
LambdaMetafactory.FLAG_BRIDGES,
1,
interfaceType);
} else {
writer.invokeDynamic(ref.invokedName,
invokedType,
LAMBDA_BOOTSTRAP_HANDLE,
samMethodType,
ref.implMethodASM,
samMethodType,
0);
}
}
}
}

View File

@ -64,7 +64,7 @@ public class EFunctionRef extends AExpression {
@Override
void write(MethodWriter writer) {
if (ref == null) {
writer.push(type + "." + call);
writer.push("S" + type + "." + call + ",0");
} else {
writer.writeDebugInfo(location);
// convert MethodTypes to asm Type for the constant pool.

View File

@ -62,7 +62,7 @@ final class LDefArray extends ALink implements IDefLink {
writer.writeDebugInfo(location);
String desc = Type.getMethodDescriptor(after.type, Definition.DEF_TYPE.type, index.actual.type);
writer.invokeDynamic("arrayLoad", desc, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.ARRAY_LOAD, 0);
writer.invokeDynamic("arrayLoad", desc, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.ARRAY_LOAD);
}
@Override
@ -70,6 +70,6 @@ final class LDefArray extends ALink implements IDefLink {
writer.writeDebugInfo(location);
String desc = Type.getMethodDescriptor(Definition.VOID_TYPE.type, Definition.DEF_TYPE.type, index.actual.type, after.type);
writer.invokeDynamic("arrayStore", desc, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.ARRAY_STORE, 0);
writer.invokeDynamic("arrayStore", desc, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.ARRAY_STORE);
}
}

View File

@ -55,11 +55,15 @@ final class LDefCall extends ALink implements IDefLink {
}
recipe = 0;
int totalCaptures = 0;
for (int argument = 0; argument < arguments.size(); ++argument) {
AExpression expression = arguments.get(argument);
if (expression instanceof EFunctionRef) {
recipe |= (1L << argument); // mark argument as deferred reference
recipe |= (1L << (argument + totalCaptures)); // mark argument as deferred reference
} else if (expression instanceof ECapturingFunctionRef) {
recipe |= (1L << (argument + totalCaptures)); // mark argument as deferred reference
totalCaptures++;
}
expression.internal = true;
expression.analyze(locals);
@ -90,6 +94,10 @@ final class LDefCall extends ALink implements IDefLink {
for (AExpression argument : arguments) {
signature.append(argument.actual.type.getDescriptor());
if (argument instanceof ECapturingFunctionRef) {
ECapturingFunctionRef capturingRef = (ECapturingFunctionRef) argument;
signature.append(capturingRef.captured.type.type.getDescriptor());
}
argument.write(writer);
}

View File

@ -59,7 +59,7 @@ final class LDefField extends ALink implements IDefLink {
writer.writeDebugInfo(location);
String desc = Type.getMethodDescriptor(after.type, Definition.DEF_TYPE.type);
writer.invokeDynamic(value, desc, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.LOAD, 0);
writer.invokeDynamic(value, desc, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.LOAD);
}
@Override
@ -67,6 +67,6 @@ final class LDefField extends ALink implements IDefLink {
writer.writeDebugInfo(location);
String desc = Type.getMethodDescriptor(Definition.VOID_TYPE.type, Definition.DEF_TYPE.type, after.type);
writer.invokeDynamic(value, desc, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.STORE, 0);
writer.invokeDynamic(value, desc, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.STORE);
}
}

View File

@ -195,7 +195,7 @@ public class SEach extends AStatement {
if (method == null) {
Type itr = Definition.getType("Iterator");
String desc = org.objectweb.asm.Type.getMethodDescriptor(itr.type, Definition.DEF_TYPE.type);
writer.invokeDynamic("iterator", desc, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.ITERATOR, (Object)0);
writer.invokeDynamic("iterator", desc, DEF_BOOTSTRAP_HANDLE, (Object)DefBootstrap.ITERATOR);
} else if (java.lang.reflect.Modifier.isInterface(method.owner.clazz.getModifiers())) {
writer.invokeInterface(method.owner.type, method.method);
} else {

View File

@ -35,6 +35,7 @@
* {@link org.elasticsearch.painless.node.EBinary} - Represents a binary math expression.
* {@link org.elasticsearch.painless.node.EBool} - Represents a boolean expression.
* {@link org.elasticsearch.painless.node.EBoolean} - Represents a boolean constant.
* {@link org.elasticsearch.painless.node.ECapturingFunctionRef} - Represents a function reference (capturing).
* {@link org.elasticsearch.painless.node.ECast} - Represents an implicit cast in most cases. (Internal only.)
* {@link org.elasticsearch.painless.node.EChain} - Represents the entirety of a variable/method chain for read/write operations.
* {@link org.elasticsearch.painless.node.EComp} - Represents a comparison expression.
@ -42,7 +43,7 @@
* {@link org.elasticsearch.painless.node.EConstant} - Represents a constant. (Internal only.)
* {@link org.elasticsearch.painless.node.EDecimal} - Represents a decimal constant.
* {@link org.elasticsearch.painless.node.EExplicit} - Represents an explicit cast.
* {@link org.elasticsearch.painless.node.EFunctionRef} - Represents a function reference.
* {@link org.elasticsearch.painless.node.EFunctionRef} - Represents a function reference (non-capturing).
* {@link org.elasticsearch.painless.node.ENull} - Represents a null constant.
* {@link org.elasticsearch.painless.node.ENumeric} - Represents a non-decimal numeric constant.
* {@link org.elasticsearch.painless.node.EUnary} - Represents a unary math expression.

View File

@ -125,4 +125,5 @@ class org.elasticsearch.painless.FeatureTest -> org.elasticsearch.painless.Featu
void setY(int)
boolean overloadedStatic()
boolean overloadedStatic(boolean)
Object twoFunctionsOfX(Function,Function)
}

View File

@ -33,7 +33,7 @@ public class DefBootstrapTests extends ESTestCase {
CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(),
"toString",
MethodType.methodType(String.class, Object.class),
DefBootstrap.METHOD_CALL, 0);
DefBootstrap.METHOD_CALL, 0L);
MethodHandle handle = site.dynamicInvoker();
assertDepthEquals(site, 0);
@ -50,7 +50,7 @@ public class DefBootstrapTests extends ESTestCase {
CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(),
"toString",
MethodType.methodType(String.class, Object.class),
DefBootstrap.METHOD_CALL, 0);
DefBootstrap.METHOD_CALL, 0L);
MethodHandle handle = site.dynamicInvoker();
assertDepthEquals(site, 0);
@ -72,7 +72,7 @@ public class DefBootstrapTests extends ESTestCase {
CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(),
"toString",
MethodType.methodType(String.class, Object.class),
DefBootstrap.METHOD_CALL, 0);
DefBootstrap.METHOD_CALL, 0L);
MethodHandle handle = site.dynamicInvoker();
assertDepthEquals(site, 0);

View File

@ -19,6 +19,8 @@
package org.elasticsearch.painless;
import java.util.Comparator;
public class FunctionRefTests extends ScriptTestCase {
public void testStaticMethodReference() {
@ -57,6 +59,58 @@ public class FunctionRefTests extends ScriptTestCase {
"return stats.getSum()"));
}
public void testCapturingMethodReference() {
assertEquals("5", exec("Integer x = Integer.valueOf(5); return Optional.empty().orElseGet(x::toString);"));
assertEquals("[]", exec("List l = new ArrayList(); return Optional.empty().orElseGet(l::toString);"));
}
public void testCapturingMethodReferenceDefImpl() {
assertEquals("5", exec("def x = Integer.valueOf(5); return Optional.empty().orElseGet(x::toString);"));
assertEquals("[]", exec("def l = new ArrayList(); return Optional.empty().orElseGet(l::toString);"));
}
public void testCapturingMethodReferenceDefInterface() {
assertEquals("5", exec("Integer x = Integer.valueOf(5); def opt = Optional.empty(); return opt.orElseGet(x::toString);"));
assertEquals("[]", exec("List l = new ArrayList(); def opt = Optional.empty(); return opt.orElseGet(l::toString);"));
}
public void testCapturingMethodReferenceDefEverywhere() {
assertEquals("5", exec("def x = Integer.valueOf(5); def opt = Optional.empty(); return opt.orElseGet(x::toString);"));
assertEquals("[]", exec("def l = new ArrayList(); def opt = Optional.empty(); return opt.orElseGet(l::toString);"));
}
public void testCapturingMethodReferenceMultipleLambdas() {
assertEquals("testingcdefg", exec(
"String x = 'testing';" +
"String y = 'abcdefg';" +
"org.elasticsearch.painless.FeatureTest test = new org.elasticsearch.painless.FeatureTest(2,3);" +
"return test.twoFunctionsOfX(x::concat, y::substring);"));
}
public void testCapturingMethodReferenceMultipleLambdasDefImpls() {
assertEquals("testingcdefg", exec(
"def x = 'testing';" +
"def y = 'abcdefg';" +
"org.elasticsearch.painless.FeatureTest test = new org.elasticsearch.painless.FeatureTest(2,3);" +
"return test.twoFunctionsOfX(x::concat, y::substring);"));
}
public void testCapturingMethodReferenceMultipleLambdasDefInterface() {
assertEquals("testingcdefg", exec(
"String x = 'testing';" +
"String y = 'abcdefg';" +
"def test = new org.elasticsearch.painless.FeatureTest(2,3);" +
"return test.twoFunctionsOfX(x::concat, y::substring);"));
}
public void testCapturingMethodReferenceMultipleLambdasDefEverywhere() {
assertEquals("testingcdefg", exec(
"def x = 'testing';" +
"def y = 'abcdefg';" +
"def test = new org.elasticsearch.painless.FeatureTest(2,3);" +
"return test.twoFunctionsOfX(x::concat, y::substring);"));
}
public void testMethodMissing() {
IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> {
exec("List l = new ArrayList(); l.add(2); l.add(1); l.sort(Integer::bogus); return l.get(0);");

View File

@ -299,9 +299,9 @@ public abstract class AbstractBulkByScrollRequest<Self extends AbstractBulkByScr
abortOnVersionConflict = in.readBoolean();
size = in.readVInt();
refresh = in.readBoolean();
timeout = TimeValue.readTimeValue(in);
timeout = new TimeValue(in);
consistency = WriteConsistencyLevel.fromId(in.readByte());
retryBackoffInitialTime = TimeValue.readTimeValue(in);
retryBackoffInitialTime = new TimeValue(in);
maxRetries = in.readVInt();
requestsPerSecond = in.readFloat();
}

View File

@ -168,10 +168,10 @@ public class BulkByScrollTask extends CancellableTask {
noops = in.readVLong();
bulkRetries = in.readVLong();
searchRetries = in.readVLong();
throttled = TimeValue.readTimeValue(in);
throttled = new TimeValue(in);
requestsPerSecond = in.readFloat();
reasonCancelled = in.readOptionalString();
throttledUntil = TimeValue.readTimeValue(in);
throttledUntil = new TimeValue(in);
}
@Override

View File

@ -153,7 +153,7 @@ public class BulkIndexByScrollResponse extends ActionResponse implements ToXCont
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
took = TimeValue.readTimeValue(in);
took = new TimeValue(in);
status = new BulkByScrollTask.Status(in);
int indexingFailuresCount = in.readVInt();
List<Failure> indexingFailures = new ArrayList<>(indexingFailuresCount);