8187237: Need to define the behaviour for 0 and 1 argument method type in StringConcatFactory.makeConcat

8186737: Lookup argument for StringConcatFactory.makeConcat & makeConcatWithConstants cannot have privileges less than PRIVATE

Reviewed-by: mchung
This commit is contained in:
Paul Sandoz 2017-11-29 12:39:59 -08:00
parent f7aba189f0
commit 012e103e91
3 changed files with 77 additions and 20 deletions

View file

@ -263,8 +263,12 @@ public final class LambdaMetafactory {
* methods from {@code Object}. * methods from {@code Object}.
* *
* @param caller Represents a lookup context with the accessibility * @param caller Represents a lookup context with the accessibility
* privileges of the caller. When used with {@code invokedynamic}, * privileges of the caller. Specifically, the lookup context
* this is stacked automatically by the VM. * must have
* <a href="MethodHandles.Lookup.html#privacc">private access</a>
* privileges.
* When used with {@code invokedynamic}, this is stacked
* automatically by the VM.
* @param invokedName The name of the method to implement. When used with * @param invokedName The name of the method to implement. When used with
* {@code invokedynamic}, this is provided by the * {@code invokedynamic}, this is provided by the
* {@code NameAndType} of the {@code InvokeDynamic} * {@code NameAndType} of the {@code InvokeDynamic}
@ -294,7 +298,8 @@ public final class LambdaMetafactory {
* instances of the interface named by {@code invokedType} * instances of the interface named by {@code invokedType}
* @throws LambdaConversionException If any of the linkage invariants * @throws LambdaConversionException If any of the linkage invariants
* described {@link LambdaMetafactory above} * described {@link LambdaMetafactory above}
* are violated * are violated, or the lookup context
* does not have private access privileges.
*/ */
public static CallSite metafactory(MethodHandles.Lookup caller, public static CallSite metafactory(MethodHandles.Lookup caller,
String invokedName, String invokedName,
@ -404,8 +409,12 @@ public final class LambdaMetafactory {
* </ul> * </ul>
* *
* @param caller Represents a lookup context with the accessibility * @param caller Represents a lookup context with the accessibility
* privileges of the caller. When used with {@code invokedynamic}, * privileges of the caller. Specifically, the lookup context
* this is stacked automatically by the VM. * must have
* <a href="MethodHandles.Lookup.html#privacc">private access</a>
* privileges.
* When used with {@code invokedynamic}, this is stacked
* automatically by the VM.
* @param invokedName The name of the method to implement. When used with * @param invokedName The name of the method to implement. When used with
* {@code invokedynamic}, this is provided by the * {@code invokedynamic}, this is provided by the
* {@code NameAndType} of the {@code InvokeDynamic} * {@code NameAndType} of the {@code InvokeDynamic}
@ -429,7 +438,8 @@ public final class LambdaMetafactory {
* instances of the interface named by {@code invokedType} * instances of the interface named by {@code invokedType}
* @throws LambdaConversionException If any of the linkage invariants * @throws LambdaConversionException If any of the linkage invariants
* described {@link LambdaMetafactory above} * described {@link LambdaMetafactory above}
* are violated * are violated, or the lookup context
* does not have private access privileges.
*/ */
public static CallSite altMetafactory(MethodHandles.Lookup caller, public static CallSite altMetafactory(MethodHandles.Lookup caller,
String invokedName, String invokedName,

View file

@ -385,9 +385,16 @@ public final class StringConcatFactory {
* invoked, it returns the result of String concatenation, taking all * invoked, it returns the result of String concatenation, taking all
* function arguments passed to the linkage method as inputs for * function arguments passed to the linkage method as inputs for
* concatenation. The target signature is given by {@code concatType}. * concatenation. The target signature is given by {@code concatType}.
* The arguments are concatenated as per requirements stated in JLS 15.18.1 * For a target accepting:
* "String Concatenation Operator +". Notably, the inputs are converted as * <ul>
* per JLS 5.1.11 "String Conversion", and combined from left to right. * <li>zero inputs, concatenation results in an empty string;</li>
* <li>one input, concatenation results in the single
* input converted as per JLS 5.1.11 "String Conversion"; otherwise</li>
* <li>two or more inputs, the inputs are concatenated as per
* requirements stated in JLS 15.18.1 "String Concatenation Operator +".
* The inputs are converted as per JLS 5.1.11 "String Conversion",
* and combined from left to right.</li>
* </ul>
* *
* <p>Assume the linkage arguments are as follows: * <p>Assume the linkage arguments are as follows:
* *
@ -404,8 +411,12 @@ public final class StringConcatFactory {
* </ul> * </ul>
* *
* @param lookup Represents a lookup context with the accessibility * @param lookup Represents a lookup context with the accessibility
* privileges of the caller. When used with {@code * privileges of the caller. Specifically, the lookup
* invokedynamic}, this is stacked automatically by the VM. * context must have
* <a href="MethodHandles.Lookup.html#privacc">private access</a>
* privileges.
* When used with {@code invokedynamic}, this is stacked
* automatically by the VM.
* @param name The name of the method to implement. This name is * @param name The name of the method to implement. This name is
* arbitrary, and has no meaning for this linkage method. * arbitrary, and has no meaning for this linkage method.
* When used with {@code invokedynamic}, this is provided by * When used with {@code invokedynamic}, this is provided by
@ -422,7 +433,8 @@ public final class StringConcatFactory {
* concatenation, with dynamic concatenation arguments described by the given * concatenation, with dynamic concatenation arguments described by the given
* {@code concatType}. * {@code concatType}.
* @throws StringConcatException If any of the linkage invariants described * @throws StringConcatException If any of the linkage invariants described
* here are violated. * here are violated, or the lookup context
* does not have private access privileges.
* @throws NullPointerException If any of the incoming arguments is null. * @throws NullPointerException If any of the incoming arguments is null.
* This will never happen when a bootstrap method * This will never happen when a bootstrap method
* is called with invokedynamic. * is called with invokedynamic.
@ -452,10 +464,17 @@ public final class StringConcatFactory {
* invoked, it returns the result of String concatenation, taking all * invoked, it returns the result of String concatenation, taking all
* function arguments and constants passed to the linkage method as inputs for * function arguments and constants passed to the linkage method as inputs for
* concatenation. The target signature is given by {@code concatType}, and * concatenation. The target signature is given by {@code concatType}, and
* does not include constants. The arguments are concatenated as per requirements * does not include constants.
* stated in JLS 15.18.1 "String Concatenation Operator +". Notably, the inputs * For a target accepting:
* are converted as per JLS 5.1.11 "String Conversion", and combined from left * <ul>
* to right. * <li>zero inputs, concatenation results in an empty string;</li>
* <li>one input, concatenation results in the single
* input converted as per JLS 5.1.11 "String Conversion"; otherwise</li>
* <li>two or more inputs, the inputs are concatenated as per
* requirements stated in JLS 15.18.1 "String Concatenation Operator +".
* The inputs are converted as per JLS 5.1.11 "String Conversion",
* and combined from left to right.</li>
* </ul>
* *
* <p>The concatenation <em>recipe</em> is a String description for the way to * <p>The concatenation <em>recipe</em> is a String description for the way to
* construct a concatenated String from the arguments and constants. The * construct a concatenated String from the arguments and constants. The
@ -502,9 +521,12 @@ public final class StringConcatFactory {
* </ul> * </ul>
* *
* @param lookup Represents a lookup context with the accessibility * @param lookup Represents a lookup context with the accessibility
* privileges of the caller. When used with {@code * privileges of the caller. Specifically, the lookup
* invokedynamic}, this is stacked automatically by the * context must have
* VM. * <a href="MethodHandles.Lookup.html#privacc">private access</a>
* privileges.
* When used with {@code invokedynamic}, this is stacked
* automatically by the VM.
* @param name The name of the method to implement. This name is * @param name The name of the method to implement. This name is
* arbitrary, and has no meaning for this linkage method. * arbitrary, and has no meaning for this linkage method.
* When used with {@code invokedynamic}, this is provided * When used with {@code invokedynamic}, this is provided
@ -524,7 +546,8 @@ public final class StringConcatFactory {
* concatenation, with dynamic concatenation arguments described by the given * concatenation, with dynamic concatenation arguments described by the given
* {@code concatType}. * {@code concatType}.
* @throws StringConcatException If any of the linkage invariants described * @throws StringConcatException If any of the linkage invariants described
* here are violated. * here are violated, or the lookup context
* does not have private access privileges.
* @throws NullPointerException If any of the incoming arguments is null, or * @throws NullPointerException If any of the incoming arguments is null, or
* any constant in {@code recipe} is null. * any constant in {@code recipe} is null.
* This will never happen when a bootstrap method * This will never happen when a bootstrap method

View file

@ -282,6 +282,30 @@ public class StringConcatFactoryInvariants {
// Advanced factory: public Lookup is rejected // Advanced factory: public Lookup is rejected
fail("Passing public Lookup", fail("Passing public Lookup",
() -> StringConcatFactory.makeConcatWithConstants(MethodHandles.publicLookup(), methodName, mtEmpty, recipeEmpty)); () -> StringConcatFactory.makeConcatWithConstants(MethodHandles.publicLookup(), methodName, mtEmpty, recipeEmpty));
// Zero inputs
{
MethodType zero = MethodType.methodType(String.class);
CallSite cs = StringConcatFactory.makeConcat(lookup, methodName, zero);
test("", (String) cs.getTarget().invokeExact());
cs = StringConcatFactory.makeConcatWithConstants(lookup, methodName, zero, "");
test("", (String) cs.getTarget().invokeExact());
}
// One input
{
MethodType zero = MethodType.methodType(String.class);
MethodType one = MethodType.methodType(String.class, String.class);
CallSite cs = StringConcatFactory.makeConcat(lookup, methodName, one);
test("A", (String) cs.getTarget().invokeExact("A"));
cs = StringConcatFactory.makeConcatWithConstants(lookup, methodName, one, "\1");
test("A", (String) cs.getTarget().invokeExact("A"));
cs = StringConcatFactory.makeConcatWithConstants(lookup, methodName, zero, "\2", "A");
test("A", (String) cs.getTarget().invokeExact());
}
} }
public static void ok(String msg, Callable runnable) { public static void ok(String msg, Callable runnable) {