-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
383 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id 'java' | ||
id 'java-library' | ||
} | ||
|
||
println("JDK 17") | ||
|
||
ext.set('versionOverrided', true) | ||
|
||
compileJava { | ||
sourceCompatibility = JavaVersion.VERSION_16 | ||
targetCompatibility = JavaVersion.VERSION_16 | ||
options.compilerArgs.addAll([ | ||
'--add-exports', 'java.base/jdk.internal.misc=ALL-UNNAMED', | ||
'--add-exports', 'java.base/jdk.internal.access=ALL-UNNAMED' | ||
]) | ||
} | ||
|
||
dependencies { | ||
api(project(':impl.jdk9')) | ||
} |
19 changes: 19 additions & 0 deletions
19
impl/jdk17/src/main/java/io/github/karlatemp/unsafeaccessor/UsfAllocImpl17.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.github.karlatemp.unsafeaccessor; | ||
|
||
class UsfAllocImpl17 extends UsfAllocImpl9 { | ||
@SuppressWarnings("JavaReflectionMemberAccess") | ||
@Override | ||
UsfAlloc checkSelectedRequirement() throws Exception { | ||
try { | ||
Class.forName("jdk.internal.misc.Unsafe").getMethod( | ||
"defineAnonymousClass", | ||
Class.class, | ||
byte[].class, | ||
Object[].class | ||
); | ||
} catch (NoSuchMethodException ignore) { | ||
return this; | ||
} | ||
return null; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
impl/jdk17/src/main/java/io/github/karlatemp/unsafeaccessor/UsfImpl17.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.github.karlatemp.unsafeaccessor; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
class UsfImpl17 extends Impl9 { | ||
@Override | ||
public Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches) { | ||
try { | ||
MethodHandles.Lookup lookup = Root.RootLookupHolder.trustedIn(hostClass).in(hostClass); | ||
if (cpPatches == null) { | ||
return lookup.defineHiddenClass(data, false).lookupClass(); | ||
} | ||
return lookup.defineHiddenClassWithClassData(data, cpPatches, false).lookupClass(); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
plugins { | ||
id 'java' | ||
id 'java-library' | ||
} | ||
|
||
dependencies { | ||
implementation(project(':api')) | ||
api(project(':api')) | ||
} |
File renamed without changes.
25 changes: 25 additions & 0 deletions
25
impl/jdk8/src/main/java/io/github/karlatemp/unsafeaccessor/UsfAlloc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.github.karlatemp.unsafeaccessor; | ||
|
||
abstract class UsfAlloc { | ||
|
||
Unsafe newUnsafe(UsfAllocCtx ctx) throws Exception { | ||
return ctx.newUsfImpl(this); | ||
} | ||
|
||
void prepare(UsfAllocCtx ctx) throws Exception { | ||
} | ||
|
||
void destroyLimit(UsfAllocCtx ctx) throws Exception { | ||
} | ||
|
||
void completed(UsfAllocCtx ctx) throws Exception { | ||
} | ||
|
||
ModuleAccess newModuleAccess(UsfAllocCtx ctx) throws Exception { | ||
return new ModuleAccessImpl.Noop(); | ||
} | ||
|
||
UsfAlloc checkSelectedRequirement() throws Exception { | ||
return this; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
impl/jdk8/src/main/java/io/github/karlatemp/unsafeaccessor/UsfAllocCtx.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.github.karlatemp.unsafeaccessor; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
class UsfAllocCtx { | ||
private DynClassLoader loader; | ||
|
||
void putUnsafeInstance(Unsafe usf) { | ||
Unsafe.theUnsafe = usf; | ||
} | ||
|
||
void putModuleAccess(ModuleAccess ma) { | ||
Root.Secret.MACCESS = ma; | ||
} | ||
|
||
DynClassLoader loader() { | ||
if (loader == null) | ||
return loader = new DynClassLoader(); | ||
return loader; | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
static class DynClassLoader extends ClassLoader implements Supplier, Consumer { | ||
Object env; | ||
|
||
DynClassLoader() { | ||
super(DynClassLoader.class.getClassLoader()); | ||
} | ||
|
||
@Override | ||
public Object get() { | ||
return env; | ||
} | ||
|
||
@Override | ||
public void accept(Object o) { | ||
env = o; | ||
} | ||
|
||
Class<?> define(byte[] code) { | ||
return defineClass(null, code, 0, code.length, null); | ||
} | ||
|
||
Class<?> defineAndLoad(byte[] data) throws ClassNotFoundException { | ||
return Class.forName(define(data).getName(), true, this); | ||
} | ||
} | ||
|
||
String namespace; | ||
Class<?>[] ACCESS_C; | ||
|
||
Unsafe newUsfImpl(UsfAlloc thiz) throws Exception { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
impl/jdk8/src/main/java/io/github/karlatemp/unsafeaccessor/UsfAllocImpl8.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package io.github.karlatemp.unsafeaccessor; | ||
|
||
class UsfAllocImpl8 extends UsfAlloc { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.