Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8263459: Add better support for restricted methods #471

Closed
Closed
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -93,6 +93,12 @@ public String toString() {
return "MemoryAddress{ base: " + base + " offset=0x" + Long.toHexString(offset) + " }";
}

@Override
@NativeAccess
public MemorySegment asSegmentRestricted(long bytesSize) {
return MemoryAddress.super.asSegmentRestricted(bytesSize);
}

@Override
@NativeAccess
public MemorySegment asSegmentRestricted(long bytesSize, Runnable cleanupAction, Object attachment) {
19 changes: 18 additions & 1 deletion test/jdk/java/foreign/TestRestricted.java
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
* questions.
*/

import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemorySegment;
import org.testng.annotations.Test;

@@ -33,7 +34,6 @@
* @run testng TestRestricted
*/
public class TestRestricted {

@Test(expectedExceptions = IllegalAccessException.class)
public void testReflection() throws Throwable {
Method method = MemorySegment.class.getDeclaredMethod("ofNativeRestricted");
@@ -49,4 +49,21 @@ public void testLookup() throws Throwable {
public void testDirectAccess() throws Throwable {
MemorySegment.ofNativeRestricted();
}

@Test(expectedExceptions = IllegalAccessException.class)
public void testReflection2() throws Throwable {
Method method = MemoryAddress.class.getDeclaredMethod("asSegmentRestricted", long.class);
method.invoke(MemoryAddress.NULL, 4000L);
}

@Test(expectedExceptions = IllegalAccessException.class)
public void testLookup2() throws Throwable {
MethodHandles.lookup().findVirtual(MemoryAddress.class, "asSegmentRestricted",
MethodType.methodType(MemorySegment.class, long.class));
}

@Test(expectedExceptions = IllegalAccessException.class)
public void testDirectAccess2() throws Throwable {
MemoryAddress.NULL.asSegmentRestricted(4000L);
}
}