GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 1,支持multi-release · dreamlike-ocean/UnsafeJava@8fd3eaf

This repository was archived by the owner on Jun 30, 2026. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pom.xml
  • readme.md
  • unsafe-core
    • pom.xml
    • src/main
      • java22/top/dreamlike/unsafe/core
        • helper
          • GlobalRef.java
          • JValue.java
        • jni
          • JNIEnv.java
          • JNIEnvExt.java
          • JNIEnvFunctions.java
        • unreflection
          • MasterKey.java
      • java/top/dreamlike/unsafe/core
        • helper
          • NativeHelper.java
        • unreflection
          • MasterKey.java
  • unsafe-vthread
    • pom.xml
  • vertx-ext
    • pom.xml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pom.xml‎

Copy file name to clipboardExpand all lines: pom.xml
+119-38Lines changed: 119 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,38 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>top.dreamlike</groupId>
7+
<name>UnsafeJava</name>
8+
<description>提供无需添加额外启动参数就可以使用各种内部api的解决方案</description>
9+
<url>https://github.com/dreamlike-ocean/UnsafeJava</url>
10+
<groupId>io.github.dreamlike-ocean</groupId>
811
<artifactId>unsafe-java</artifactId>
9-
<version>1.0-SNAPSHOT</version>
12+
<version>1.0</version>
1013
<packaging>pom</packaging>
1114

15+
<licenses>
16+
<license>
17+
<name>MIT License</name>
18+
<url>https://opensource.org/licenses/MIT</url>
19+
<distribution>repo</distribution>
20+
</license>
21+
</licenses>
22+
<scm>
23+
<url>https://github.com/dreamlike-ocean/UnsafeJava</url>
24+
<connection>https://github.com/dreamlike-ocean/UnsafeJava.git</connection>
25+
</scm>
26+
27+
<developers>
28+
<developer>
29+
<name>dreamlike-ocean</name>
30+
<id>dreamlike-ocean</id>
31+
<email>[email protected]</email>
32+
<roles>
33+
<role>owner</role>
34+
</roles>
35+
<timezone>+8</timezone>
36+
</developer>
37+
</developers>
38+
1239
<modules>
1340
<module>unsafe-vthread</module>
1441
<module>vertx-ext</module>
@@ -17,50 +44,104 @@
1744

1845
<properties>
1946
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20-
<java.version>21</java.version>
47+
<java.version>22</java.version>
48+
<core.version>1.2</core.version>
2149
</properties>
2250

2351
<dependencyManagement>
2452
<dependencies>
2553
<dependency>
26-
<groupId>top.dreamlike</groupId>
54+
<groupId>io.github.dreamlike-ocean</groupId>
2755
<artifactId>unsafe-core</artifactId>
28-
<version>1.0</version>
56+
<version>${core.version}</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>io.github.dreamlike-ocean</groupId>
60+
<artifactId>unsafe-vthread</artifactId>
61+
<version>1.0.0</version>
2962
</dependency>
3063
</dependencies>
3164
</dependencyManagement>
3265

33-
<build>
34-
<plugins>
35-
<plugin>
36-
<groupId>org.apache.maven.plugins</groupId>
37-
<artifactId>maven-compiler-plugin</artifactId>
38-
<executions>
39-
<execution>
40-
<id>compile</id>
41-
<phase>compile</phase>
42-
<goals>
43-
<goal>compile</goal>
44-
</goals>
45-
</execution>
46-
<execution>
47-
<id>testCompile</id>
48-
<phase>test-compile</phase>
49-
<goals>
50-
<goal>testCompile</goal>
51-
</goals>
52-
</execution>
53-
</executions>
54-
<configuration>
55-
<parameters>true</parameters>
56-
<source>${java.version}</source>
57-
<target>${java.version}</target>
58-
<encoding>UTF-8</encoding>
59-
<compilerArgument>
60-
--enable-preview
61-
</compilerArgument>
62-
</configuration>
63-
</plugin>
64-
</plugins>
65-
</build>
66+
<profiles>
67+
<profile>
68+
<id>default</id>
69+
<activation>
70+
<activeByDefault>true</activeByDefault>
71+
</activation>
72+
<build>
73+
<plugins>
74+
<plugin>
75+
<groupId>org.sonatype.plugins</groupId>
76+
<artifactId>nexus-staging-maven-plugin</artifactId>
77+
<version>1.6.13</version>
78+
<extensions>true</extensions>
79+
<configuration>
80+
<serverId>ossrh</serverId>
81+
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
82+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-source-plugin</artifactId>
88+
<version>3.2.1</version>
89+
<executions>
90+
<execution>
91+
<id>attach-sources</id>
92+
<goals>
93+
<goal>jar-no-fork</goal>
94+
</goals>
95+
</execution>
96+
</executions>
97+
</plugin>
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-javadoc-plugin</artifactId>
101+
<version>3.4.1</version>
102+
<configuration>
103+
<release>${java.version}</release>
104+
<!-- jdk1.8要加上,1.7要去掉,否则会报错 -->
105+
<additionalJOptions>
106+
<additionalJOption>-Xdoclint:none</additionalJOption>
107+
<additonalJOption>--enable-preview</additonalJOption>
108+
</additionalJOptions>
109+
</configuration>
110+
<executions>
111+
<execution>
112+
<id>attach-javadocs</id>
113+
<goals>
114+
<goal>jar</goal>
115+
</goals>
116+
</execution>
117+
</executions>
118+
</plugin>
119+
<plugin>
120+
<groupId>org.apache.maven.plugins</groupId>
121+
<artifactId>maven-gpg-plugin</artifactId>
122+
<version>1.5</version>
123+
<executions>
124+
<execution>
125+
<id>sign-artifacts</id>
126+
<phase>verify</phase>
127+
<goals>
128+
<goal>sign</goal>
129+
</goals>
130+
</execution>
131+
</executions>
132+
</plugin>
133+
</plugins>
134+
</build>
135+
<distributionManagement>
136+
<snapshotRepository>
137+
<id>ossrh</id>
138+
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
139+
</snapshotRepository>
140+
<repository>
141+
<id>ossrh</id>
142+
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
143+
</repository>
144+
</distributionManagement>
145+
</profile>
146+
</profiles>
66147
</project>
Collapse file

‎readme.md‎

Copy file name to clipboardExpand all lines: readme.md
+9Lines changed: 9 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ IMPL_LOOKUP这个是无视各种权限的lookup,从它这里获取到的Method
3030
> 目前只在Linux以及Windows x86_64,Mac(aarch64以及amd64)上测试过,其他平台可能需要评估兼容性问题
3131
3232

33+
maven 坐标为,本库以multi-release的形式发布,所以你可以在jdk8-jdk22上使用,从jdk22开始默认使用的Panama的实现
34+
```xml
35+
<dependency>
36+
<groupId>io.github.dreamlike-ocean</groupId>
37+
<artifactId>unsafe-core</artifactId>
38+
<version>1.2</version>
39+
</dependency>
40+
```
41+
3342
当然你也会发现项目里面有另外一种写法,即获取到MethodHandle之后转换为`java.util.function.Function`,这两种形式核心原理是一样的
3443
```java
3544
private static Function<Executor, Thread.Builder.OfVirtual> fetchVirtualThreadBuilder() {
Collapse file

‎unsafe-core/pom.xml‎

Copy file name to clipboardExpand all lines: unsafe-core/pom.xml
+41-11Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<parent>
7-
<groupId>top.dreamlike</groupId>
7+
<groupId>io.github.dreamlike-ocean</groupId>
88
<artifactId>unsafe-java</artifactId>
9-
<version>1.0-SNAPSHOT</version>
9+
<version>1.0</version>
1010
</parent>
1111

1212
<artifactId>unsafe-core</artifactId>
13-
<version>1.0</version>
13+
<version>${core.version}</version>
1414

1515
<properties>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -28,23 +28,53 @@
2828
<plugin>
2929
<groupId>org.apache.maven.plugins</groupId>
3030
<artifactId>maven-jar-plugin</artifactId>
31+
<version>3.3.0</version>
3132
<configuration>
33+
3234
<archive>
33-
<manifest>
35+
<manifestEntries>
3436
<addClasspath>true</addClasspath>
35-
<mainClass>top.dreamlike.unsafe.main</mainClass>
36-
</manifest>
37+
<Multi-Release>true</Multi-Release>
38+
</manifestEntries>
3739
</archive>
3840
</configuration>
3941
</plugin>
42+
4043
<plugin>
4144
<groupId>org.apache.maven.plugins</groupId>
4245
<artifactId>maven-compiler-plugin</artifactId>
43-
<configuration>
44-
<source>${java.version}</source>
45-
<target>${java.version}</target>
46-
<compilerArgs>--enable-preview</compilerArgs>
47-
</configuration>
46+
<version>3.12.1</version>
47+
<executions>
48+
<execution>
49+
<id>compile-java-8</id>
50+
<goals>
51+
<goal>compile</goal>
52+
</goals>
53+
<configuration>
54+
<source>1.8</source>
55+
<target>1.8</target>
56+
<compileSourceRoots>
57+
<!---旧版本代码的位置-->
58+
<compileSourceRoot>${project.basedir}/src/main/java</compileSourceRoot>
59+
</compileSourceRoots>
60+
</configuration>
61+
</execution>
62+
<execution>
63+
<id>compile-java-9</id>
64+
<phase>compile</phase>
65+
<goals>
66+
<goal>compile</goal>
67+
</goals>
68+
<configuration>
69+
<release>22</release>
70+
<compileSourceRoots>
71+
<!---新版本代码的位置-->
72+
<compileSourceRoot>${project.basedir}/src/main/java22</compileSourceRoot>
73+
</compileSourceRoots>
74+
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/22</outputDirectory>
75+
</configuration>
76+
</execution>
77+
</executions>
4878
</plugin>
4979
</plugins>
5080
</build>
Collapse file

‎unsafe-core/src/main/java/top/dreamlike/unsafe/core/helper/NativeHelper.java‎

Copy file name to clipboardExpand all lines: unsafe-core/src/main/java/top/dreamlike/unsafe/core/helper/NativeHelper.java
+13-14Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package top.dreamlike.unsafe.core.helper;
22

3-
import java.util.concurrent.Callable;
43

54
public class NativeHelper {
65

@@ -33,19 +32,19 @@ public static void throwable(VoidThrowableFn r) {
3332

3433
public static String classToSig(Class c) {
3534
if (c.isArray()) {
36-
return STR."[\{classToSig(c.getComponentType())}";
35+
return "[" + classToSig(c.getComponentType());
36+
}
37+
switch (c.getName()) {
38+
case "void" : return "V";
39+
case "boolean" : return "Z";
40+
case "byte" : return "B";
41+
case "char" : return "C";
42+
case "short" : return "S";
43+
case "int" : return "I";
44+
case "long" : return "J";
45+
case "float" : return "F";
46+
case "double" : return "D";
47+
default : return "L" + c.getName().replace('.', '/') + ";";
3748
}
38-
return switch (c.getName()) {
39-
case "void" -> "V";
40-
case "boolean" -> "Z";
41-
case "byte" -> "B";
42-
case "char" -> "C";
43-
case "short" -> "S";
44-
case "int" -> "I";
45-
case "long" -> "J";
46-
case "float" -> "F";
47-
case "double" -> "D";
48-
default -> STR."L\{c.getName().replace('.', '/')};";
49-
};
5049
}
5150
}
Collapse file

‎unsafe-core/src/main/java/top/dreamlike/unsafe/core/unreflection/MasterKey.java‎

Copy file name to clipboard
+14-14Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
package top.dreamlike.unsafe.core.unreflection;
22

3-
import top.dreamlike.unsafe.core.helper.GlobalRef;
3+
import sun.misc.Unsafe;
44
import top.dreamlike.unsafe.core.helper.NativeHelper;
5-
import top.dreamlike.unsafe.core.jni.JNIEnv;
65

7-
import java.lang.foreign.Arena;
6+
87
import java.lang.invoke.MethodHandle;
98
import java.lang.invoke.MethodHandles;
109
import java.lang.invoke.VarHandle;
1110
import java.lang.reflect.Constructor;
1211
import java.lang.reflect.Field;
1312
import java.lang.reflect.Method;
1413

15-
import static top.dreamlike.unsafe.core.helper.NativeHelper.throwable;
16-
1714
public class MasterKey {
1815
public static MethodHandles.Lookup lookup;
1916
static {
20-
try (Arena arena = Arena.ofConfined()) {
21-
JNIEnv jniEnv = new JNIEnv(arena);
22-
GlobalRef implLookup = jniEnv.GetStaticFieldByName(MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP"));
23-
Object o = jniEnv.jObjectToJavaObject(implLookup.ref());
24-
lookup = (MethodHandles.Lookup) o;
25-
}catch (Throwable e){
26-
throw new RuntimeException(e);
27-
}
17+
try {
18+
Field field = Unsafe.class.getDeclaredField("theUnsafe");
19+
field.setAccessible(true);
20+
Unsafe unsafe = (Unsafe) field.get(null);
21+
Field implLookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
22+
Object base = unsafe.staticFieldBase(implLookupField);
23+
long fieldOffset = unsafe.staticFieldOffset(implLookupField);
24+
lookup = ((MethodHandles.Lookup) unsafe.getObject(base, fieldOffset));
25+
System.out.println("unsafe impl");
26+
}catch (Exception e) {
27+
throw new RuntimeException(e);
28+
}
2829
}
2930

3031
public static MethodHandle openTheDoor(Method method) {
@@ -38,5 +39,4 @@ public static MethodHandle openTheDoor(Constructor ctor) {
3839
public static VarHandle openTheDoor(Field field) {
3940
return NativeHelper.throwable(() -> lookup.unreflectVarHandle(field));
4041
}
41-
4242
}
Collapse file

‎…amlike/unsafe/core/helper/GlobalRef.java‎ ‎…amlike/unsafe/core/helper/GlobalRef.java‎unsafe-core/src/main/java/top/dreamlike/unsafe/core/helper/GlobalRef.java renamed to unsafe-core/src/main/java22/top/dreamlike/unsafe/core/helper/GlobalRef.java unsafe-core/src/main/java/top/dreamlike/unsafe/core/helper/GlobalRef.java renamed to unsafe-core/src/main/java22/top/dreamlike/unsafe/core/helper/GlobalRef.java

Copy file name to clipboard
File renamed without changes.

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.