Skip to content

Commit 09e213f

Browse files
committed
[GR-64626] Implement boot libraries in Java for Espresso.
PullRequest: graal/20306
2 parents 8f76090 + afba7e2 commit 09e213f

File tree

86 files changed

+7699
-32
lines changed

Some content is hidden

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

86 files changed

+7699
-32
lines changed

espresso/mx.espresso/suite.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@
9696
"license": "UPL",
9797
},
9898

99+
"com.oracle.truffle.espresso.io": {
100+
"subDir": "src",
101+
"sourceDirs": ["src"],
102+
# Contains classes in sun.nio.* that only compile with javac.
103+
"forceJavac": "true",
104+
"javaCompliance": "8+",
105+
"checkPackagePrefix": False, # Contains classes in java.io and sun.nio.
106+
"checkstyle": "com.oracle.truffle.espresso",
107+
},
108+
99109
"com.oracle.truffle.espresso.hotswap": {
100110
"subDir": "src",
101111
"sourceDirs": ["src"],
@@ -512,6 +522,7 @@
512522
"dependency:espresso:HOTSWAP",
513523
"dependency:espresso:CONTINUATIONS",
514524
"dependency:espresso:ESPRESSO_JVMCI",
525+
"dependency:espresso:ESPRESSO_IO",
515526
],
516527
},
517528
},
@@ -527,6 +538,7 @@
527538
"dependency:espresso:HOTSWAP",
528539
"dependency:espresso:CONTINUATIONS",
529540
"dependency:espresso:ESPRESSO_JVMCI",
541+
"dependency:espresso:ESPRESSO_IO",
530542
],
531543
},
532544
},
@@ -542,6 +554,7 @@
542554
"dependency:espresso:HOTSWAP",
543555
"dependency:espresso:CONTINUATIONS",
544556
"dependency:espresso:ESPRESSO_JVMCI",
557+
"dependency:espresso:ESPRESSO_IO",
545558
],
546559
},
547560
},
@@ -569,6 +582,7 @@
569582
"dependency:espresso:HOTSWAP/*",
570583
"dependency:espresso:CONTINUATIONS/*",
571584
"dependency:espresso:ESPRESSO_JVMCI/*",
585+
"dependency:espresso:ESPRESSO_IO",
572586
],
573587
},
574588
},
@@ -586,6 +600,7 @@
586600
"dependency:espresso:HOTSWAP/*",
587601
"dependency:espresso:CONTINUATIONS/*",
588602
"dependency:espresso:ESPRESSO_JVMCI/*",
603+
"dependency:espresso:ESPRESSO_IO",
589604
],
590605
},
591606
},
@@ -603,6 +618,7 @@
603618
"dependency:espresso:HOTSWAP/*",
604619
"dependency:espresso:CONTINUATIONS/*",
605620
"dependency:espresso:ESPRESSO_JVMCI/*",
621+
"dependency:espresso:ESPRESSO_IO",
606622
],
607623
},
608624
},
@@ -623,6 +639,15 @@
623639
"maven": False,
624640
},
625641

642+
"ESPRESSO_IO": {
643+
"subDir": "src",
644+
"dependencies": [
645+
"com.oracle.truffle.espresso.io"
646+
],
647+
"description": "Injection of Truffle file system to guest java.base",
648+
"maven": False,
649+
},
650+
626651
"ESPRESSO_POLYGLOT": {
627652
"subDir": "src",
628653
"dependencies": [

espresso/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/descriptors/TypeSymbols.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ public static ByteSequence typeToName(Symbol<Type> type) {
158158
return type.subSequence(1, type.length() - 1);
159159
}
160160

161+
@TruffleBoundary
162+
public Symbol<Type> fromDescriptorString(String desc) {
163+
JavaKind kind = JavaKind.fromTypeString(desc);
164+
if (kind.isPrimitive()) {
165+
return TypeSymbols.forPrimitive(kind);
166+
}
167+
return fromClassGetName(desc);
168+
}
169+
161170
@TruffleBoundary
162171
public Symbol<Type> fromClassGetName(String className) {
163172
String internalName = internalFromClassName(className);
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package java.io;
24+
25+
/**
26+
* Truffle-based implementation of {@link FileSystem}.
27+
* <p>
28+
* Its native methods are provided by Espresso's custom {@code libjava} implementation.
29+
* <p>
30+
* This file must be compatible with all Java versions supported by Espresso, strict Java 8
31+
* compatibility is required.
32+
*
33+
*/
34+
final class TruffleFileSystem extends FileSystem {
35+
36+
static {
37+
// Ensure the default file system is the correct one.
38+
FileSystem tfs = DefaultFileSystem.getFileSystem();
39+
if (!(tfs instanceof TruffleFileSystem)) {
40+
throw new IncompatibleClassChangeError("Failed to set TruffleFileSystem as default file system.");
41+
}
42+
}
43+
44+
@Override
45+
public char getSeparator() {
46+
return getSeparator0();
47+
}
48+
49+
@Override
50+
public char getPathSeparator() {
51+
return getPathSeparator0();
52+
}
53+
54+
@Override
55+
public String normalize(String path) {
56+
return normalize0(path);
57+
}
58+
59+
@Override
60+
public int prefixLength(String path) {
61+
return prefixLength0(path);
62+
}
63+
64+
@Override
65+
public String resolve(String parent, String child) {
66+
return resolve0(parent, child);
67+
}
68+
69+
@Override
70+
public String getDefaultParent() {
71+
return getDefaultParent0();
72+
}
73+
74+
@Override
75+
public String fromURIPath(String path) {
76+
return fromURIPath0(path);
77+
}
78+
79+
@Override
80+
public boolean isAbsolute(File f) {
81+
return isAbsolute0(f);
82+
}
83+
84+
@Override
85+
public boolean isInvalid(File f) {
86+
return isInvalid0(f);
87+
}
88+
89+
@Override
90+
public String resolve(File f) {
91+
return resolve0(f);
92+
}
93+
94+
@Override
95+
public String canonicalize(String path) throws IOException {
96+
return canonicalize0(path);
97+
}
98+
99+
@Override
100+
public int getBooleanAttributes(File f) {
101+
return getBooleanAttributes0(f);
102+
}
103+
104+
@Override
105+
public boolean checkAccess(File f, int access) {
106+
return checkAccess0(f, access);
107+
}
108+
109+
@Override
110+
public boolean setPermission(File f, int access, boolean enable, boolean owneronly) {
111+
return setPermission0(f, access, enable, owneronly);
112+
}
113+
114+
@Override
115+
public long getLastModifiedTime(File f) {
116+
return getLastModifiedTime0(f);
117+
}
118+
119+
@Override
120+
public long getLength(File f) {
121+
return getLength0(f);
122+
}
123+
124+
@Override
125+
public boolean createFileExclusively(String pathname) throws IOException {
126+
return createFileExclusively0(pathname);
127+
}
128+
129+
@Override
130+
public boolean delete(File f) {
131+
return delete0(f);
132+
}
133+
134+
@Override
135+
public String[] list(File f) {
136+
return list0(f);
137+
}
138+
139+
@Override
140+
public boolean createDirectory(File f) {
141+
return createDirectory0(f);
142+
}
143+
144+
@Override
145+
public boolean rename(File f1, File f2) {
146+
return rename0(f1, f2);
147+
}
148+
149+
@Override
150+
public boolean setLastModifiedTime(File f, long time) {
151+
return setLastModifiedTime0(f, time);
152+
}
153+
154+
@Override
155+
public boolean setReadOnly(File f) {
156+
return setReadOnly0(f);
157+
}
158+
159+
@Override
160+
public File[] listRoots() {
161+
return listRoots0();
162+
}
163+
164+
@Override
165+
public long getSpace(File f, int t) {
166+
return getSpace0(f, t);
167+
}
168+
169+
@Override
170+
public int getNameMax(String path) {
171+
return getNameMax0(path);
172+
}
173+
174+
@Override
175+
public int compare(File f1, File f2) {
176+
return compare0(f1, f2);
177+
}
178+
179+
@Override
180+
public int hashCode(File f) {
181+
return hashCode0(f);
182+
}
183+
184+
private static native char getSeparator0();
185+
186+
private static native char getPathSeparator0();
187+
188+
private static native String normalize0(String path);
189+
190+
private static native int prefixLength0(String path);
191+
192+
private static native String resolve0(String parent, String child);
193+
194+
private static native String getDefaultParent0();
195+
196+
private static native String fromURIPath0(String path);
197+
198+
private static native boolean isAbsolute0(File f);
199+
200+
private static native boolean isInvalid0(File f);
201+
202+
private static native String resolve0(File f);
203+
204+
private static native String canonicalize0(String path) throws IOException;
205+
206+
private static native int getBooleanAttributes0(File f);
207+
208+
private static native boolean checkAccess0(File f, int access);
209+
210+
private static native boolean setPermission0(File f, int access, boolean enable, boolean owneronly);
211+
212+
private static native long getLastModifiedTime0(File f);
213+
214+
private static native long getLength0(File path);
215+
216+
private static native boolean createFileExclusively0(String pathname) throws IOException;
217+
218+
private static native boolean delete0(File path);
219+
220+
private static native String[] list0(File path);
221+
222+
private static native boolean createDirectory0(File f);
223+
224+
private static native boolean rename0(File from, File to);
225+
226+
private static native boolean setLastModifiedTime0(File path, long time);
227+
228+
private static native boolean setReadOnly0(File f);
229+
230+
private static native File[] listRoots0();
231+
232+
private static native long getSpace0(File f, int t);
233+
234+
private static native int getNameMax0(String path);
235+
236+
private static native int compare0(File f1, File f2);
237+
238+
private static native int hashCode0(File f);
239+
}

0 commit comments

Comments
 (0)