Skip to content

Commit 4251028

Browse files
committed
better headless operation -- removes exit() dependencies
1 parent ea44a96 commit 4251028

File tree

6 files changed

+72
-24
lines changed

6 files changed

+72
-24
lines changed

sources/net.sf.j2s.java.core/src/java/lang/Runtime.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private Runtime() {}
104104
*/
105105
public void exit(int status) {
106106
Thread.currentThread().getThreadGroup().秘exit();
107-
JSAppletViewer v = JSToolkit.getAppletViewer();
107+
JSAppletViewer v = /** @j2sNative !swingjs.JSToolkit ? null : */JSToolkit.getAppletViewer();
108108
if (v != null)
109109
v.exit();
110110

sources/net.sf.j2s.java.core/src/java/lang/ThreadGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ public String toString() {
10551055
}
10561056

10571057
public void 秘exit() {
1058-
ArrayList<Object> q = 秘getTimerQueue();
1058+
ArrayList<Object> q = 秘systemExited ? null : 秘timerQueue;//秘getTimerQueue();
10591059
if (q != null)
10601060
for (int i = q.size(); --i >= 0;) {
10611061
Timer t = (Timer) q.get(i);

sources/net.sf.j2s.java.core/src/java/nio/MappedByteBuffer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package java.nio;
2727

2828
import java.io.FileDescriptor;
29-
import sun.misc.Unsafe;
3029

3130
/**
3231
* A direct byte buffer whose content is a memory-mapped region of a file.

sources/net.sf.j2s.java.core/src/sun/util/resources/ParallelListResourceBundle.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import java.util.NoSuchElementException;
3434
import java.util.ResourceBundle;
3535
import java.util.Set;
36-
import java.util.concurrent.ConcurrentHashMap;
37-
import java.util.concurrent.ConcurrentMap;
38-
import java.util.concurrent.atomic.AtomicMarkableReference;
36+
import java.util.HashMap; // SwingJS was Concurrent
37+
import java.util.Map; // SwingJS was Concurrent
38+
//import java.util.concurrent.atomic.AtomicMarkableReference;
3939

4040
/**
4141
* ParallelListResourceBundle is another variant of ListResourceBundle
@@ -46,11 +46,10 @@
4646
* @author Masayoshi Okutsu
4747
*/
4848
public abstract class ParallelListResourceBundle extends ResourceBundle {
49-
private volatile ConcurrentMap<String, Object> lookup;
49+
private volatile Map<String, Object> lookup;
5050
private volatile Set<String> keyset;
51-
private final AtomicMarkableReference<Object[][]> parallelContents
52-
= new AtomicMarkableReference<>(null, false);
53-
51+
private Object[][] parallelContents;
52+
private boolean done = false;
5453
/**
5554
* Sole constructor. (For invocation by subclass constructors, typically
5655
* implicit.)
@@ -87,26 +86,34 @@ ResourceBundle getParent() {
8786
*/
8887
public void setParallelContents(OpenListResourceBundle rb) {
8988
if (rb == null) {
90-
parallelContents.compareAndSet(null, null, false, true);
89+
compareAndSet(null, null, false, true);
9190
} else {
92-
parallelContents.compareAndSet(null, rb.getContents(), false, false);
91+
compareAndSet(null, rb.getContents(), false, false);
9392
}
9493
}
9594

96-
/**
95+
private void compareAndSet(Object[][] orig, Object[][] val, boolean wasdone, boolean done) {
96+
if (parallelContents == orig && this.done == wasdone) {
97+
parallelContents = val; this.done = done;
98+
}
99+
}
100+
101+
/**
97102
* Returns true if any parallel contents have been set or if this bundle is
98103
* marked as complete.
99104
*
100105
* @return true if any parallel contents have been processed
101106
*/
102107
boolean areParallelContentsComplete() {
103-
// Quick check for `complete'
104-
if (parallelContents.isMarked()) {
105-
return true;
106-
}
107-
boolean[] done = new boolean[1];
108-
Object[][] data = parallelContents.get(done);
109-
return data != null || done[0];
108+
return parallelContents != null;
109+
// return true;
110+
// // Quick check for `complete'
111+
// if (parallelContents.isMarked()) {
112+
// return true;
113+
// }
114+
// boolean[] done = new boolean[1];
115+
// Object[][] data = parallelContents.get(done);
116+
// return data != null || done[0];
110117
}
111118

112119
@Override
@@ -162,21 +169,21 @@ synchronized void resetKeySet() {
162169
* Loads the lookup table if they haven't been loaded already.
163170
*/
164171
void loadLookupTablesIfNecessary() {
165-
ConcurrentMap<String, Object> map = lookup;
172+
Map<String, Object> map = lookup;
166173
if (map == null) {
167-
map = new ConcurrentHashMap<>();
174+
map = new HashMap<>();
168175
for (Object[] item : getContents()) {
169176
map.put((String) item[0], item[1]);
170177
}
171178
}
172179

173180
// If there's any parallel contents data, merge the data into map.
174-
Object[][] data = parallelContents.getReference();
181+
Object[][] data = parallelContents;
175182
if (data != null) {
176183
for (Object[] item : data) {
177184
map.putIfAbsent((String) item[0], item[1]);
178185
}
179-
parallelContents.set(null, true);
186+
parallelContents = null;
180187
}
181188
if (lookup == null) {
182189
synchronized (this) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package test;
2+
3+
/**
4+
* See also Test_HeadlessNot
5+
*
6+
* Use ?j2sverbose to see the difference in adding headless:true to Info{}
7+
*
8+
* @author hansonr
9+
*
10+
*/
11+
class Test_Headless extends Test_ {
12+
13+
static {
14+
/**
15+
* @j2sNative J2S.thisApplet.__Info.headless=true;
16+
*
17+
*/
18+
}
19+
public static void main(String[] args) {
20+
String[] files = /** @j2sNative Clazz.ClassFilesLoaded.sort() || */null;
21+
String s = /** @j2sNative files.join('\n') || */null;
22+
System.out.println("Hello, world! (headless) \n" + s + "\n\n" + files.length + " classes loaded");
23+
}
24+
25+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package test;
2+
3+
/**
4+
* See also Test_Headless
5+
*
6+
* @author hansonr
7+
*
8+
*/
9+
class Test_HeadlessNot extends Test_ {
10+
11+
public static void main(String[] args) {
12+
String[] files = /** @j2sNative Clazz.ClassFilesLoaded.sort() || */null;
13+
String s = /** @j2sNative files.join('\n') || */null;
14+
System.out.println("Hello, world! (not headless) \n" + s + "\n\n" + files.length + " classes loaded");
15+
}
16+
17+
}

0 commit comments

Comments
 (0)