Skip to content

Commit f702105

Browse files
committed
Merging master HEAD into openj9-staging
2 parents 3f09cef + 11ff3af commit f702105

File tree

77 files changed

+2459
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2459
-243
lines changed

make/autoconf/help.m4

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ AC_DEFUN_ONCE([HELP_PRINT_SUMMARY_AND_WARNINGS],
238238
239239
printf "\n"
240240
printf "Configuration summary:\n"
241+
printf "* Name: $CONF_NAME\n"
241242
printf "* Debug level: $DEBUG_LEVEL\n"
242243
printf "* HS debug level: $HOTSPOT_DEBUG_LEVEL\n"
243244
printf "* JVM variants: $JVM_VARIANTS\n"

src/java.base/share/classes/java/io/InputStream.java

+17-16
Original file line numberDiff line numberDiff line change
@@ -577,13 +577,15 @@ public long skip(long n) throws IOException {
577577
* @implSpec
578578
* If {@code n} is zero or negative, then no bytes are skipped.
579579
* If {@code n} is positive, the default implementation of this method
580-
* invokes {@link #skip(long) skip()} with parameter {@code n}. If the
581-
* return value of {@code skip(n)} is non-negative and less than {@code n},
582-
* then {@link #read()} is invoked repeatedly until the stream is {@code n}
583-
* bytes beyond its position when this method was invoked or end of stream
584-
* is reached. If the return value of {@code skip(n)} is negative or
585-
* greater than {@code n}, then an {@code IOException} is thrown. Any
586-
* exception thrown by {@code skip()} or {@code read()} will be propagated.
580+
* invokes {@link #skip(long) skip()} repeatedly with its parameter equal
581+
* to the remaining number of bytes to skip until the requested number
582+
* of bytes has been skipped or an error condition occurs. If at any
583+
* point the return value of {@code skip()} is negative or greater than the
584+
* remaining number of bytes to be skipped, then an {@code IOException} is
585+
* thrown. If {@code skip()} ever returns zero, then {@link #read()} is
586+
* invoked to read a single byte, and if it returns {@code -1}, then an
587+
* {@code EOFException} is thrown. Any exception thrown by {@code skip()}
588+
* or {@code read()} will be propagated.
587589
*
588590
* @param n the number of bytes to be skipped.
589591
* @throws EOFException if end of stream is encountered before the
@@ -596,20 +598,19 @@ public long skip(long n) throws IOException {
596598
* @since 12
597599
*/
598600
public void skipNBytes(long n) throws IOException {
599-
if (n > 0) {
601+
while (n > 0) {
600602
long ns = skip(n);
601-
if (ns >= 0 && ns < n) { // skipped too few bytes
603+
if (ns > 0 && ns <= n) {
602604
// adjust number to skip
603605
n -= ns;
604-
// read until requested number skipped or EOS reached
605-
while (n > 0 && read() != -1) {
606-
n--;
607-
}
608-
// if not enough skipped, then EOFE
609-
if (n != 0) {
606+
} else if (ns == 0) { // no bytes skipped
607+
// read one byte to check for EOS
608+
if (read() == -1) {
610609
throw new EOFException();
611610
}
612-
} else if (ns != n) { // skipped negative or too many bytes
611+
// one byte read so decrement number to skip
612+
n--;
613+
} else { // skipped negative or too many bytes
613614
throw new IOException("Unable to skip exactly");
614615
}
615616
}

src/java.base/share/classes/java/lang/AbstractStringBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ private void putStringAt(int index, String str, int off, int end) {
17171717
if (getCoder() != str.coder()) {
17181718
inflate();
17191719
}
1720-
str.getBytes(value, off, index, coder, end);
1720+
str.getBytes(value, off, index, coder, end - off);
17211721
}
17221722

17231723
private void putStringAt(int index, String str) {

src/java.base/share/classes/java/lang/System.java

+3
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,9 @@ public void addReads(Module m1, Module m2) {
22212221
public void addReadsAllUnnamed(Module m) {
22222222
m.implAddReadsAllUnnamed();
22232223
}
2224+
public void addExports(Module m, String pn) {
2225+
m.implAddExports(pn);
2226+
}
22242227
public void addExports(Module m, String pn, Module other) {
22252228
m.implAddExports(pn, other);
22262229
}

src/java.base/share/classes/java/lang/module/Resolver.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -560,7 +560,7 @@ private Map<ResolvedModule, Set<ResolvedModule>> makeGraph(Configuration cf) {
560560
for (ModuleDescriptor.Requires requires : descriptor.requires()) {
561561
String dn = requires.name();
562562

563-
ResolvedModule m2 = null;
563+
ResolvedModule m2;
564564
ModuleReference mref2 = nameToReference.get(dn);
565565
if (mref2 != null) {
566566
// same configuration
@@ -572,6 +572,14 @@ private Map<ResolvedModule, Set<ResolvedModule>> makeGraph(Configuration cf) {
572572
assert requires.modifiers().contains(Modifier.STATIC);
573573
continue;
574574
}
575+
576+
// m2 is automatic module in parent configuration => m1 reads
577+
// all automatic modules that m2 reads.
578+
if (m2.descriptor().isAutomatic()) {
579+
m2.reads().stream()
580+
.filter(d -> d.descriptor().isAutomatic())
581+
.forEach(reads::add);
582+
}
575583
}
576584

577585
// m1 requires m2 => m1 reads m2
@@ -838,9 +846,7 @@ private ResolvedModule findInParent(String mn) {
838846
* Invokes the beforeFinder to find method to find the given module.
839847
*/
840848
private ModuleReference findWithBeforeFinder(String mn) {
841-
842849
return beforeFinder.find(mn).orElse(null);
843-
844850
}
845851

846852
/**

src/java.base/share/classes/java/lang/reflect/InvocationHandler.java

+200-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,12 @@
2525

2626
package java.lang.reflect;
2727

28+
import jdk.internal.reflect.CallerSensitive;
29+
import jdk.internal.reflect.Reflection;
30+
31+
import java.lang.invoke.MethodHandle;
32+
import java.util.Objects;
33+
2834
/**
2935
* {@code InvocationHandler} is the interface implemented by
3036
* the <i>invocation handler</i> of a proxy instance.
@@ -92,4 +98,197 @@ public interface InvocationHandler {
9298
*/
9399
public Object invoke(Object proxy, Method method, Object[] args)
94100
throws Throwable;
101+
102+
/**
103+
* Invokes the specified default method on the given {@code proxy} instance with
104+
* the given parameters. The given {@code method} must be a default method
105+
* declared in a proxy interface of the {@code proxy}'s class or inherited
106+
* from its superinterface directly or indirectly.
107+
* <p>
108+
* Invoking this method behaves as if {@code invokespecial} instruction executed
109+
* from the proxy class, targeting the default method in a proxy interface.
110+
* This is equivalent to the invocation:
111+
* {@code X.super.m(A* a)} where {@code X} is a proxy interface and the call to
112+
* {@code X.super::m(A*)} is resolved to the given {@code method}.
113+
* <p>
114+
* Examples: interface {@code A} and {@code B} both declare a default
115+
* implementation of method {@code m}. Interface {@code C} extends {@code A}
116+
* and inherits the default method {@code m} from its superinterface {@code A}.
117+
*
118+
* <blockquote><pre>{@code
119+
* interface A {
120+
* default T m(A a) { return t1; }
121+
* }
122+
* interface B {
123+
* default T m(A a) { return t2; }
124+
* }
125+
* interface C extends A {}
126+
* }</pre></blockquote>
127+
*
128+
* The following creates a proxy instance that implements {@code A}
129+
* and invokes the default method {@code A::m}.
130+
*
131+
* <blockquote><pre>{@code
132+
* Object proxy = Proxy.newProxyInstance(loader, new Class<?>[] { A.class },
133+
* (o, m, params) -> {
134+
* if (m.isDefault()) {
135+
* // if it's a default method, invoke it
136+
* return InvocationHandler.invokeDefault(o, m, params);
137+
* }
138+
* });
139+
* }</pre></blockquote>
140+
*
141+
* If a proxy instance implements both {@code A} and {@code B}, both
142+
* of which provides the default implementation of method {@code m},
143+
* the invocation handler can dispatch the method invocation to
144+
* {@code A::m} or {@code B::m} via the {@code invokeDefault} method.
145+
* For example, the following code delegates the method invocation
146+
* to {@code B::m}.
147+
*
148+
* <blockquote><pre>{@code
149+
* Object proxy = Proxy.newProxyInstance(loader, new Class<?>[] { A.class, B.class },
150+
* (o, m, params) -> {
151+
* if (m.getName().equals("m")) {
152+
* // invoke B::m instead of A::m
153+
* Method bMethod = B.class.getMethod(m.getName(), m.getParameterTypes());
154+
* return InvocationHandler.invokeDefault(o, bMethod, params);
155+
* }
156+
* });
157+
* }</pre></blockquote>
158+
*
159+
* If a proxy instance implements {@code C} that inherits the default
160+
* method {@code m} from its superinterface {@code A}, then
161+
* the interface method invocation on {@code "m"} is dispatched to
162+
* the invocation handler's {@link #invoke(Object, Method, Object[]) invoke}
163+
* method with the {@code Method} object argument representing the
164+
* default method {@code A::m}.
165+
*
166+
* <blockquote><pre>{@code
167+
* Object proxy = Proxy.newProxyInstance(loader, new Class<?>[] { C.class },
168+
* (o, m, params) -> {
169+
* if (m.isDefault()) {
170+
* // behaves as if calling C.super.m(params)
171+
* return InvocationHandler.invokeDefault(o, m, params);
172+
* }
173+
* });
174+
* }</pre></blockquote>
175+
*
176+
* The invocation of method {@code "m"} on this {@code proxy} will behave
177+
* as if {@code C.super::m} is called and that is resolved to invoking
178+
* {@code A::m}.
179+
* <p>
180+
* Adding a default method, or changing a method from abstract to default
181+
* may cause an exception if an existing code attempts to call {@code invokeDefault}
182+
* to invoke a default method.
183+
*
184+
* For example, if {@code C} is modified to implement a default method
185+
* {@code m}:
186+
*
187+
* <blockquote><pre>{@code
188+
* interface C extends A {
189+
* default T m(A a) { return t3; }
190+
* }
191+
* }</pre></blockquote>
192+
*
193+
* The code above that creates proxy instance {@code proxy} with
194+
* the modified {@code C} will run with no exception and it will result in
195+
* calling {@code C::m} instead of {@code A::m}.
196+
* <p>
197+
* The following is another example that creates a proxy instance of {@code C}
198+
* and the invocation handler calls the {@code invokeDefault} method
199+
* to invoke {@code A::m}:
200+
*
201+
* <blockquote><pre>{@code
202+
* C c = (C) Proxy.newProxyInstance(loader, new Class<?>[] { C.class },
203+
* (o, m, params) -> {
204+
* if (m.getName().equals("m")) {
205+
* // IllegalArgumentException thrown as {@code A::m} is not a method
206+
* // inherited from its proxy interface C
207+
* Method aMethod = A.class.getMethod(m.getName(), m.getParameterTypes());
208+
* return InvocationHandler.invokeDefault(o, aMethod params);
209+
* }
210+
* });
211+
* c.m(...);
212+
* }</pre></blockquote>
213+
*
214+
* The above code runs successfully with the old version of {@code C} and
215+
* {@code A::m} is invoked. When running with the new version of {@code C},
216+
* the above code will fail with {@code IllegalArgumentException} because
217+
* {@code C} overrides the implementation of the same method and
218+
* {@code A::m} is not accessible by a proxy instance.
219+
*
220+
* @apiNote
221+
* The {@code proxy} parameter is of type {@code Object} rather than {@code Proxy}
222+
* to make it easy for {@link InvocationHandler#invoke(Object, Method, Object[])
223+
* InvocationHandler::invoke} implementation to call directly without the need
224+
* of casting.
225+
*
226+
* @param proxy the {@code Proxy} instance on which the default method to be invoked
227+
* @param method the {@code Method} instance corresponding to a default method
228+
* declared in a proxy interface of the proxy class or inherited
229+
* from its superinterface directly or indirectly
230+
* @param args the parameters used for the method invocation; can be {@code null}
231+
* if the number of formal parameters required by the method is zero.
232+
* @return the value returned from the method invocation
233+
*
234+
* @throws IllegalArgumentException if any of the following conditions is {@code true}:
235+
* <ul>
236+
* <li>{@code proxy} is not {@linkplain Proxy#isProxyClass(Class)
237+
* a proxy instance}; or</li>
238+
* <li>the given {@code method} is not a default method declared
239+
* in a proxy interface of the proxy class and not inherited from
240+
* any of its superinterfaces; or</li>
241+
* <li>the given {@code method} is overridden directly or indirectly by
242+
* the proxy interfaces and the method reference to the named
243+
* method never resolves to the given {@code method}; or</li>
244+
* <li>the length of the given {@code args} array does not match the
245+
* number of parameters of the method to be invoked; or</li>
246+
* <li>any of the {@code args} elements fails the unboxing
247+
* conversion if the corresponding method parameter type is
248+
* a primitive type; or if, after possible unboxing, any of the
249+
* {@code args} elements cannot be assigned to the corresponding
250+
* method parameter type.</li>
251+
* </ul>
252+
* @throws IllegalAccessException if the declaring class of the specified
253+
* default method is inaccessible to the caller class
254+
* @throws NullPointerException if {@code proxy} or {@code method} is {@code null}
255+
* @throws Throwable anything thrown by the default method
256+
257+
* @since 16
258+
* @jvms 5.4.3. Method Resolution
259+
*/
260+
@CallerSensitive
261+
public static Object invokeDefault(Object proxy, Method method, Object... args)
262+
throws Throwable {
263+
Objects.requireNonNull(proxy);
264+
Objects.requireNonNull(method);
265+
266+
// verify that the object is actually a proxy instance
267+
if (!Proxy.isProxyClass(proxy.getClass())) {
268+
throw new IllegalArgumentException("'proxy' is not a proxy instance");
269+
}
270+
if (!method.isDefault()) {
271+
throw new IllegalArgumentException("\"" + method + "\" is not a default method");
272+
}
273+
@SuppressWarnings("unchecked")
274+
Class<? extends Proxy> proxyClass = (Class<? extends Proxy>)proxy.getClass();
275+
276+
Class<?> intf = method.getDeclaringClass();
277+
// access check on the default method
278+
method.checkAccess(Reflection.getCallerClass(), intf, proxyClass, method.getModifiers());
279+
280+
MethodHandle mh = Proxy.defaultMethodHandle(proxyClass, method);
281+
// invoke the super method
282+
try {
283+
// the args array can be null if the number of formal parameters required by
284+
// the method is zero (consistent with Method::invoke)
285+
Object[] params = args != null ? args : Proxy.EMPTY_ARGS;
286+
return mh.invokeExact(proxy, params);
287+
} catch (ClassCastException | NullPointerException e) {
288+
throw new IllegalArgumentException(e.getMessage(), e);
289+
} catch (Proxy.InvocationException e) {
290+
// unwrap and throw the exception thrown by the default method
291+
throw e.getCause();
292+
}
293+
}
95294
}

src/java.base/share/classes/java/lang/reflect/Method.java

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import jdk.internal.reflect.Reflection;
3232
import jdk.internal.vm.annotation.ForceInline;
3333
import jdk.internal.vm.annotation.IntrinsicCandidate;
34+
import jdk.internal.vm.annotation.Stable;
3435
import sun.reflect.annotation.ExceptionProxy;
3536
import sun.reflect.annotation.TypeNotPresentExceptionProxy;
3637
import sun.reflect.generics.repository.MethodRepository;
@@ -66,6 +67,7 @@
6667
* @since 1.1
6768
*/
6869
public final class Method extends Executable {
70+
@Stable
6971
private Class<?> clazz;
7072
private int slot;
7173
// This is guaranteed to be interned by the VM in the 1.4
@@ -74,6 +76,7 @@ public final class Method extends Executable {
7476
private Class<?> returnType;
7577
private Class<?>[] parameterTypes;
7678
private Class<?>[] exceptionTypes;
79+
@Stable
7780
private int modifiers;
7881
// Generics and annotations support
7982
private transient String signature;

0 commit comments

Comments
 (0)