├── .gitignore
└── JavaInJava
├── .classpath
├── .gitignore
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
└── src
└── com
└── sun
├── cri
└── bytecode
│ ├── BytecodeLookupSwitch.java
│ ├── BytecodeStream.java
│ ├── BytecodeSwitch.java
│ ├── BytecodeTableSwitch.java
│ ├── Bytecodes.java
│ ├── Bytes.java
│ └── package-info.java
└── max
├── AbstractScheme.java
├── BasePackage.java
├── MaxPackage.java
├── Package.java
├── PackageLoader.java
├── Scheme.java
├── Utils.java
├── annotate
├── INLINE.java
├── INSPECTED.java
├── Package.java
├── RESET.java
└── package-info.java
├── gui
├── Package.java
├── SpringUtilities.java
├── ThrowableDialog.java
└── package-info.java
├── io
├── CharArraySource.java
├── FileTraversal.java
├── Files.java
├── IndentWriter.java
├── MultiOutputStream.java
├── NullOutputStream.java
├── Package.java
├── ReadableSource.java
├── SeekableByteArrayOutputStream.java
├── Streams.java
├── TemporaryFiles.java
├── TruncatedInputException.java
└── package-info.java
├── lang
├── Bytes.java
├── Chars.java
├── Classes.java
├── Endianness.java
├── Function.java
├── Ints.java
├── Longs.java
├── MutableInnerClassGlobal.java
├── Package.java
├── Procedure.java
├── Shorts.java
├── StaticFieldLiteral.java
├── StaticFieldName.java
├── Strings.java
├── WordWidth.java
└── package-info.java
├── package-info.java
├── program
├── ClassSearch.java
├── Classpath.java
├── ClasspathFile.java
├── ClasspathTraversal.java
├── Package.java
├── ProgramError.java
├── ProgramWarning.java
├── Trace.java
├── option
│ ├── FieldOption.java
│ ├── MaxPackageOptionType.java
│ ├── Option.java
│ ├── OptionSet.java
│ ├── OptionSettings.java
│ ├── OptionTypes.java
│ ├── Package.java
│ ├── gui
│ │ ├── OptionsDialog.java
│ │ ├── Package.java
│ │ └── package-info.java
│ └── package-info.java
└── package-info.java
├── tele
└── interpreter
│ ├── ExecutionFrame.java
│ ├── ExecutionThread.java
│ ├── Machine.java
│ ├── Package.java
│ ├── TeleInterpreter.java
│ ├── TeleInterpreterException.java
│ └── package-info.java
└── util
├── ArrayValueHistory.java
├── Deferrable.java
├── Enumerable.java
├── Enumerator.java
├── ListSymbolizer.java
├── Package.java
├── Predicate.java
├── Range.java
├── Registry.java
├── RuntimeInfo.java
├── SingleThread.java
├── Symbol.java
├── Symbolizer.java
├── Utf8.java
├── Utf8Exception.java
└── package-info.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .metadata
2 |
3 |
--------------------------------------------------------------------------------
/JavaInJava/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/JavaInJava/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 |
3 |
--------------------------------------------------------------------------------
/JavaInJava/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | JavaInJava
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/JavaInJava/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Mon Dec 27 21:03:43 CST 2010
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.6
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.source=1.6
13 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/cri/bytecode/BytecodeLookupSwitch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.cri.bytecode;
22 |
23 | /**
24 | * A utility for processing {@link Bytecodes#LOOKUPSWITCH} bytecodes.
25 | *
26 | * @author Ben L. Titzer
27 | */
28 | public class BytecodeLookupSwitch extends BytecodeSwitch {
29 | private static final int OFFSET_TO_NUMBER_PAIRS = 4;
30 | private static final int OFFSET_TO_FIRST_PAIR_MATCH = 8;
31 | private static final int OFFSET_TO_FIRST_PAIR_OFFSET = 12;
32 | private static final int PAIR_SIZE = 8;
33 |
34 | /**
35 | * Constructor for a {@link BytecodeStream}.
36 | * @param stream the {@code BytecodeStream} containing the switch instruction
37 | * @param bci the index in the stream of the switch instruction
38 | */
39 | public BytecodeLookupSwitch(BytecodeStream stream, int bci) {
40 | super(stream, bci);
41 | }
42 |
43 | /**
44 | * Constructor for a bytecode array.
45 | * @param code the bytecode array containing the switch instruction.
46 | * @param bci the index in the array of the switch instruction
47 | */
48 | public BytecodeLookupSwitch(byte[] code, int bci) {
49 | super(code, bci);
50 | }
51 |
52 | @Override
53 | public int defaultOffset() {
54 | return readWord(alignedBci);
55 | }
56 |
57 | @Override
58 | public int offsetAt(int i) {
59 | return readWord(alignedBci + OFFSET_TO_FIRST_PAIR_OFFSET + PAIR_SIZE * i);
60 | }
61 |
62 | @Override
63 | public int keyAt(int i) {
64 | return readWord(alignedBci + OFFSET_TO_FIRST_PAIR_MATCH + PAIR_SIZE * i);
65 | }
66 |
67 | @Override
68 | public int numberOfCases() {
69 | return readWord(alignedBci + OFFSET_TO_NUMBER_PAIRS);
70 | }
71 |
72 | @Override
73 | public int size() {
74 | return alignedBci + OFFSET_TO_FIRST_PAIR_MATCH + PAIR_SIZE * numberOfCases() - bci;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/cri/bytecode/BytecodeStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.cri.bytecode;
22 |
23 | /**
24 | * A utility class that makes iterating over bytecodes and reading operands
25 | * simpler and less error prone. For example, it handles the {@link Bytecodes#WIDE} instruction
26 | * and wide variants of instructions internally.
27 | *
28 | * @author Ben L. Titzer
29 | */
30 | public class BytecodeStream {
31 |
32 | final byte[] code;
33 | int opcode;
34 | int curBCI;
35 | int nextBCI;
36 |
37 | /**
38 | * Creates a new {@code BytecodeStream} for the specified bytecode.
39 | * @param code the array of bytes that contains the bytecode
40 | */
41 | public BytecodeStream(byte[] code) {
42 | this.code = code;
43 | setBCI(0);
44 | }
45 |
46 | /**
47 | * Advances to the next bytecode.
48 | */
49 | public void next() {
50 | setBCI(nextBCI);
51 | }
52 |
53 | /**
54 | * Gets the next bytecode index (no side-effects).
55 | * @return the next bytecode index
56 | */
57 | public int nextBCI() {
58 | return nextBCI;
59 | }
60 |
61 | /**
62 | * Gets the current bytecode index.
63 | * @return the current bytecode index
64 | */
65 | public int currentBCI() {
66 | return curBCI;
67 | }
68 |
69 | /**
70 | * Gets the bytecode index of the end of the code.
71 | * @return the index of the end of the code
72 | */
73 | public int endBCI() {
74 | return code.length;
75 | }
76 |
77 | /**
78 | * Gets the current opcode. This method will never return the
79 | * {@link Bytecodes#WIDE WIDE} opcode, but will instead
80 | * return the opcode that is modified by the {@code WIDE} opcode.
81 | * @return the current opcode; {@link Bytecodes#END} if at or beyond the end of the code
82 | */
83 | public int currentBC() {
84 | if (opcode == Bytecodes.WIDE) {
85 | return Bytes.beU1(code, curBCI + 1);
86 | } else {
87 | return opcode;
88 | }
89 | }
90 |
91 | /**
92 | * Reads the index of a local variable for one of the load or store instructions.
93 | * The WIDE modifier is handled internally.
94 | * @return the index of the local variable
95 | */
96 | public int readLocalIndex() {
97 | // read local variable index for load/store
98 | if (opcode == Bytecodes.WIDE) {
99 | return Bytes.beU2(code, curBCI + 2);
100 | }
101 | return Bytes.beU1(code, curBCI + 1);
102 | }
103 |
104 | /**
105 | * Read the delta for an {@link Bytecodes#IINC} bytecode.
106 | * @return the delta for the {@code IINC}
107 | */
108 | public int readIncrement() {
109 | // read the delta for the iinc bytecode
110 | if (opcode == Bytecodes.WIDE) {
111 | return Bytes.beS2(code, curBCI + 4);
112 | }
113 | return Bytes.beS1(code, curBCI + 2);
114 | }
115 |
116 | /**
117 | * Read the destination of a {@link Bytecodes#GOTO} or {@code IF} instructions.
118 | * @return the destination bytecode index
119 | */
120 | public int readBranchDest() {
121 | // reads the destination for a branch bytecode
122 | return curBCI + Bytes.beS2(code, curBCI + 1);
123 | }
124 |
125 | /**
126 | * Read the destination of a {@link Bytecodes#GOTO_W} or {@link Bytecodes#JSR_W} instructions.
127 | * @return the destination bytecode index
128 | */
129 | public int readFarBranchDest() {
130 | // reads the destination for a wide branch bytecode
131 | return curBCI + Bytes.beS4(code, curBCI + 2);
132 | }
133 |
134 | /**
135 | * Read a signed 4-byte integer from the bytecode stream at the specified bytecode index.
136 | * @param bci the bytecode index
137 | * @return the integer value
138 | */
139 | public int readInt(int bci) {
140 | // reads a 4-byte signed value
141 | return Bytes.beS4(code, bci);
142 | }
143 |
144 | /**
145 | * Reads an unsigned, 1-byte value from the bytecode stream at the specified bytecode index.
146 | * @param bci the bytecode index
147 | * @return the byte
148 | */
149 | public int readUByte(int bci) {
150 | return Bytes.beU1(code, bci);
151 | }
152 |
153 | /**
154 | * Reads a constant pool index for the current instruction.
155 | * @return the constant pool index
156 | */
157 | public char readCPI() {
158 | if (opcode == Bytecodes.LDC) {
159 | return (char) Bytes.beU1(code, curBCI + 1);
160 | }
161 | return (char) Bytes.beU2(code, curBCI + 1);
162 | }
163 |
164 | /**
165 | * Reads a signed, 1-byte value for the current instruction (e.g. BIPUSH).
166 | * @return the byte
167 | */
168 | public byte readByte() {
169 | return code[curBCI + 1];
170 | }
171 |
172 | /**
173 | * Reads a signed, 2-byte short for the current instruction (e.g. SIPUSH).
174 | * @return the short value
175 | */
176 | public short readShort() {
177 | return (short) Bytes.beS2(code, curBCI + 1);
178 | }
179 |
180 | /**
181 | * Sets the bytecode index to the specified value.
182 | * If {@code bci} is beyond the end of the array, {@link #currentBC} will return
183 | * {@link Bytecodes#END} and other methods may throw {@link ArrayIndexOutOfBoundsException}.
184 | * @param bci the new bytecode index
185 | */
186 | public void setBCI(int bci) {
187 | curBCI = bci;
188 | if (curBCI < code.length) {
189 | opcode = Bytes.beU1(code, bci);
190 | nextBCI = bci + Bytecodes.lengthOf(code, bci);
191 | } else {
192 | opcode = Bytecodes.END;
193 | nextBCI = curBCI;
194 | }
195 | }
196 | }
197 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/cri/bytecode/BytecodeSwitch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.cri.bytecode;
22 |
23 | /**
24 | * An abstract class that provides the state and methods common to {@link Bytecodes#LOOKUPSWITCH}
25 | * and {@link Bytecodes#TABLESWITCH} instructions.
26 | *
27 | * @author Ben L. Titzer
28 | */
29 | public abstract class BytecodeSwitch {
30 | /**
31 | * The {@link BytecodeStream} containing bytecode array or {@code null} if {@link #code} is not {@code null}.
32 | */
33 | private final BytecodeStream stream;
34 | /**
35 | * The bytecode array or {@code null} if {@link #stream} is not {@code null}.
36 | */
37 | private final byte[] code;
38 | /**
39 | * Index of start of switch instruction.
40 | */
41 | protected final int bci;
42 | /**
43 | * Index of the start of the additional data for the switch instruction, aligned to a multiple of four from the method start.
44 | */
45 | protected final int alignedBci;
46 |
47 | /**
48 | * Constructor for a {@link BytecodeStream}.
49 | * @param stream the {@code BytecodeStream} containing the switch instruction
50 | * @param bci the index in the stream of the switch instruction
51 | */
52 | public BytecodeSwitch(BytecodeStream stream, int bci) {
53 | this.alignedBci = (bci + 4) & 0xfffffffc;
54 | this.stream = stream;
55 | this.code = null;
56 | this.bci = bci;
57 | }
58 |
59 | /**
60 | * Constructor for a bytecode array.
61 | * @param code the bytecode array containing the switch instruction.
62 | * @param bci the index in the array of the switch instruction
63 | */
64 | public BytecodeSwitch(byte[] code, int bci) {
65 | this.alignedBci = (bci + 4) & 0xfffffffc;
66 | this.stream = null;
67 | this.code = code;
68 | this.bci = bci;
69 | }
70 |
71 | /**
72 | * Gets the current bytecode index.
73 | * @return the current bytecode index
74 | */
75 | public int bci() {
76 | return bci;
77 | }
78 |
79 | /**
80 | * Gets the index of the instruction denoted by the {@code i}'th switch target.
81 | * @param i index of the switch target
82 | * @return the index of the instruction denoted by the {@code i}'th switch target
83 | */
84 | public int targetAt(int i) {
85 | return bci + offsetAt(i);
86 | }
87 |
88 | /**
89 | * Gets the index of the instruction for the default switch target.
90 | * @return the index of the instruction for the default switch target
91 | */
92 | public int defaultTarget() {
93 | return bci + defaultOffset();
94 | }
95 |
96 | /**
97 | * Gets the offset from the start of the switch instruction to the default switch target.
98 | * @return the offset to the default switch target
99 | */
100 | public abstract int defaultOffset();
101 |
102 | /**
103 | * Gets the key at {@code i}'th switch target index.
104 | * @param i the switch target index
105 | * @return the key at {@code i}'th switch target index
106 | */
107 | public abstract int keyAt(int i);
108 |
109 | /**
110 | * Gets the offset from the start of the switch instruction for the {@code i}'th switch target.
111 | * @param i the switch target index
112 | * @return the offset to the {@code i}'th switch target
113 | */
114 | public abstract int offsetAt(int i);
115 |
116 | /**
117 | * Gets the number of switch targets.
118 | * @return the number of switch targets
119 | */
120 | public abstract int numberOfCases();
121 |
122 | /**
123 | * Gets the total size in bytes of the switch instruction.
124 | * @return the total size in bytes of the switch instruction
125 | */
126 | public abstract int size();
127 |
128 | /**
129 | * Reads the signed value at given bytecode index.
130 | * @param bci the start index of the value to retrieve
131 | * @return the signed, 4-byte value in the bytecode array starting at {@code bci}
132 | */
133 | protected int readWord(int bci) {
134 | if (code != null) {
135 | return Bytes.beS4(code, bci);
136 | }
137 | return stream.readInt(bci);
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/cri/bytecode/BytecodeTableSwitch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.cri.bytecode;
22 |
23 | /**
24 | * A utility for processing {@link Bytecodes#TABLESWITCH} bytecodes.
25 | *
26 | * @author Ben L. Titzer
27 | */
28 | public class BytecodeTableSwitch extends BytecodeSwitch {
29 | private static final int OFFSET_TO_LOW_KEY = 4;
30 | private static final int OFFSET_TO_HIGH_KEY = 8;
31 | private static final int OFFSET_TO_FIRST_JUMP_OFFSET = 12;
32 | private static final int JUMP_OFFSET_SIZE = 4;
33 |
34 | /**
35 | * Constructor for a {@link BytecodeStream}.
36 | * @param stream the {@code BytecodeStream} containing the switch instruction
37 | * @param bci the index in the stream of the switch instruction
38 | */
39 | public BytecodeTableSwitch(BytecodeStream stream, int bci) {
40 | super(stream, bci);
41 | }
42 |
43 | /**
44 | * Constructor for a bytecode array.
45 | * @param code the bytecode array containing the switch instruction.
46 | * @param bci the index in the array of the switch instruction
47 | */
48 | public BytecodeTableSwitch(byte[] code, int bci) {
49 | super(code, bci);
50 | }
51 |
52 | /**
53 | * Gets the low key of the table switch.
54 | * @return the low key
55 | */
56 | public int lowKey() {
57 | return readWord(alignedBci + OFFSET_TO_LOW_KEY);
58 | }
59 |
60 | /**
61 | * Gets the high key of the table switch.
62 | * @return the high key
63 | */
64 | public int highKey() {
65 | return readWord(alignedBci + OFFSET_TO_HIGH_KEY);
66 | }
67 |
68 | @Override
69 | public int keyAt(int i) {
70 | return lowKey() + i;
71 | }
72 |
73 | @Override
74 | public int defaultOffset() {
75 | return readWord(alignedBci);
76 | }
77 |
78 | @Override
79 | public int offsetAt(int i) {
80 | return readWord(alignedBci + OFFSET_TO_FIRST_JUMP_OFFSET + JUMP_OFFSET_SIZE * i);
81 | }
82 |
83 | @Override
84 | public int numberOfCases() {
85 | return highKey() - lowKey() + 1;
86 | }
87 |
88 | @Override
89 | public int size() {
90 | return alignedBci + OFFSET_TO_FIRST_JUMP_OFFSET + JUMP_OFFSET_SIZE * numberOfCases() - bci;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/cri/bytecode/Bytes.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.cri.bytecode;
22 |
23 | /**
24 | * A collection of utility methods for dealing with bytes, particularly in byte arrays.
25 | *
26 | * @author Ben L. Titzer
27 | */
28 | public class Bytes {
29 | /**
30 | * Gets a signed 1-byte value.
31 | * @param data the array containing the data
32 | * @param bci the start index of the value to retrieve
33 | * @return the signed 1-byte value at index {@code bci} in array {@code data}
34 | */
35 | public static int beS1(byte[] data, int bci) {
36 | return data[bci];
37 | }
38 |
39 | /**
40 | * Gets a signed 2-byte big-endian value.
41 | * @param data the array containing the data
42 | * @param bci the start index of the value to retrieve
43 | * @return the signed 2-byte, big-endian, value at index {@code bci} in array {@code data}
44 | */
45 | public static int beS2(byte[] data, int bci) {
46 | return (data[bci] << 8) | (data[bci + 1] & 0xff);
47 | }
48 |
49 | /**
50 | * Gets an unsigned 1-byte value.
51 | * @param data the array containing the data
52 | * @param bci the start index of the value to retrieve
53 | * @return the unsigned 1-byte value at index {@code bci} in array {@code data}
54 | */
55 | public static int beU1(byte[] data, int bci) {
56 | return data[bci] & 0xff;
57 | }
58 |
59 | /**
60 | * Gets an unsigned 2-byte big-endian value.
61 | * @param data the array containing the data
62 | * @param bci the start index of the value to retrieve
63 | * @return the unsigned 2-byte, big-endian, value at index {@code bci} in array {@code data}
64 | */
65 | public static int beU2(byte[] data, int bci) {
66 | return ((data[bci] & 0xff) << 8) | (data[bci + 1] & 0xff);
67 | }
68 |
69 | /**
70 | * Gets a signed 4-byte big-endian value.
71 | * @param data the array containing the data
72 | * @param bci the start index of the value to retrieve
73 | * @return the signed 4-byte, big-endian, value at index {@code bci} in array {@code data}
74 | */
75 | public static int beS4(byte[] data, int bci) {
76 | return (data[bci] << 24) | ((data[bci + 1] & 0xff) << 16) | ((data[bci + 2] & 0xff) << 8) | (data[bci + 3] & 0xff);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/cri/bytecode/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 |
22 | /**
23 | * A collection of classes that support the processing of bytecodes.
24 | * The majority are merely utility classes that simplify and reduce errors during bytecode processing,
25 | * whereas, {@link com.sun.cri.bytecode.INTRINSIC} and {@link com.sun.cri.bytecode.BytecodeIntrinsifier}
26 | * provide the capability to transform the bytecodes of a method by replacing certain bytecode instructions
27 | * with alternatives drawn from a set of extended bytecodes.
28 | *
29 | */
30 | package com.sun.cri.bytecode;
31 |
32 | /**
33 | * @author Ben Titzer
34 | * @author Mick Jordan
35 | */
36 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/AbstractScheme.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max;
22 |
23 | /**
24 | * @author Bernd Mathiske
25 | */
26 | public abstract class AbstractScheme {
27 |
28 | public final String name;
29 |
30 | protected AbstractScheme() {
31 | name = getClass().getSimpleName();
32 | }
33 |
34 | public String name() {
35 | return name;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return name;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/BasePackage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max;
22 |
23 | /**
24 | * @see MaxPackage
25 | *
26 | * @author Bernd Mathiske
27 | */
28 | public class BasePackage extends MaxPackage {
29 | protected BasePackage() {
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/Package.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max;
22 |
23 | /**
24 | * @see MaxPackage
25 | *
26 | * @author Bernd Mathiske
27 | */
28 | public class Package extends BasePackage {
29 | }
30 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/PackageLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max;
22 |
23 | import java.util.*;
24 |
25 | import com.sun.max.lang.*;
26 | import com.sun.max.program.*;
27 |
28 | /**
29 | * Loads all the classes in or under a given package.
30 | *
31 | * @author Bernd Mathiske
32 | * @author Doug Simon
33 | */
34 | public class PackageLoader {
35 |
36 | public final Classpath classpath;
37 | public final ClassLoader classLoader;
38 | private int traceLevel = 1;
39 |
40 | public PackageLoader(ClassLoader classLoader, Classpath classpath) {
41 | this.classpath = classpath;
42 | this.classLoader = classLoader;
43 | }
44 |
45 | public void setTraceLevel(int level) {
46 | traceLevel = level;
47 | }
48 |
49 | /**
50 | * Loads a given class.
51 | * A subclass can override this method to omit loading of certain classes in a package
52 | * which can result in this method returning {@code null}.
53 | *
54 | * @param className
55 | * @return the {@code Class} instance for {@code className}
56 | */
57 | protected Class loadClass(String className) {
58 | return Classes.load(classLoader, className);
59 | }
60 |
61 | /**
62 | * Loads classes under a given package.
63 | *
64 | * @param packageName the name of the package from which classes are loaded
65 | * @param recursive if true, then classes in sub-packages are loaded as well, otherwise only classes in the package
66 | * denoted by {@code packageName} are loaded
67 | * @return the loaded classes
68 | */
69 | public List load(final String packageName, final boolean recursive) {
70 | Trace.line(traceLevel, "loading: " + packageName);
71 | final List classes = new ArrayList();
72 | String[] classNames = listClassesInPackage(packageName, recursive);
73 | for (String className : classNames) {
74 | final Class javaClass = loadClass(className);
75 | if (javaClass != null) {
76 | Classes.initialize(javaClass);
77 | classes.add(javaClass);
78 | }
79 | }
80 | ProgramWarning.check(classNames.length != 0, "no classes found in package: " + packageName);
81 | return classes;
82 | }
83 |
84 | /**
85 | * Lists the classes under a given package.
86 | *
87 | * @param packageName the name of the package to search
88 | * @param recursive if true, then classes in sub-packages are listed as well
89 | * @return the class names
90 | */
91 | public String[] listClassesInPackage(final String packageName, final boolean recursive) {
92 | final HashSet classNames = new HashSet();
93 | final ClassSearch classSearch = new ClassSearch() {
94 | @Override
95 | protected boolean visitClass(boolean isArchiveEntry, String className) {
96 | if (!className.endsWith("package-info")) {
97 | if (!classNames.contains(className)) {
98 | if (recursive || Classes.getPackageName(className).equals(packageName)) {
99 | classNames.add(className);
100 | }
101 | }
102 | }
103 | return true;
104 | }
105 | };
106 | classSearch.run(classpath, packageName.replace('.', '/'));
107 | return classNames.toArray(new String[classNames.size()]);
108 | }
109 |
110 | /**
111 | * Loads classes under a given package.
112 | *
113 | * @param maxPackage the package from which classes are loaded
114 | * @param recursive if true, then classes in sub-packages are loaded as well, otherwise only classes in
115 | * {@code maxPackage} are loaded
116 | * @return the loaded classes
117 | */
118 | public List load(MaxPackage maxPackage, boolean recursive) {
119 | return load(maxPackage.name(), recursive);
120 | }
121 |
122 | /**
123 | * Initializes the given class and all its inner classes, recursively.
124 | */
125 | private void initializeAll(Class outerClass) {
126 | Classes.initialize(outerClass);
127 | for (Class innerClass : outerClass.getDeclaredClasses()) {
128 | initializeAll(innerClass);
129 | }
130 | }
131 |
132 | public void loadAndInitializeAll(Class representative) {
133 | try {
134 | for (Class outerClass : load(MaxPackage.fromClass(representative), false)) {
135 | initializeAll(outerClass);
136 | }
137 | } catch (Throwable throwable) {
138 | ProgramError.unexpected(throwable);
139 | }
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/Scheme.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max;
22 |
23 | /**
24 | * @author Bernd Mathiske
25 | */
26 | public interface Scheme {
27 |
28 | String name();
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/annotate/INLINE.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.annotate;
22 | import java.lang.annotation.*;
23 |
24 | /**
25 | * Every thus annotated method is to be inlined unconditionally by the VM's optimizing compiler
26 | * and the receiver is never null-checked.
27 | *
28 | * This annotation exists primarily for annotating methods that must be inlined
29 | * for semantic reasons as opposed to those that could be inlined for performance reasons.
30 | * Using this annotation for the latter should be done very rarely and only when
31 | * profiling highlights a performance bottleneck or such a bottleneck is known a priori.
32 | *
33 | * If the {@linkplain #override() override} element of this annotation is set to true, then
34 | * an annotated method must be {@code static} or {@code final} (implicitly or explicitly).
35 | * Additionally, only a INLINE virtual method with this element set to true can be overridden.
36 | *
37 | * @author Bernd Mathiske
38 | * @author Doug Simon
39 | */
40 | @Retention(RetentionPolicy.RUNTIME)
41 | @Target(ElementType.METHOD)
42 | public @interface INLINE {
43 |
44 | /**
45 | * If true, this element specifies that the annotated method provides the prototypical implementation
46 | * of the functionality expected (in the target VM) of every method that overrides
47 | * the annotated method. That is, the code produced by the compiler for every overriding method
48 | * must be functionality equivalent to the code produced for the prototypical method.
49 | *
50 | * WARNING: Setting this element to true implies that you guarantee that all overriders
51 | * satisfy the above stated invariant. There is no (easy) way to test for violations of
52 | * the invariant.
53 | *
54 | * A method annotated with INLINE should only be overridden for one of the following reasons:
55 | *
56 | * 1. To coerce the value returned by the overridden method to a subtype.
57 | * See {@link MemberActor#holder()} and {@link FieldActor#holder()} for an example.
58 | *
59 | * 2. A method is overridden to make bootstrapping work.
60 | * See {@link ClassActor#toJava()} and {@link ArrayClassActor#toJava()} for an example.
61 | *
62 | * 3. A method is overridden because a subclass can provide a more efficient implementation
63 | * and it is known that certain call sites will be reduced to a constant receiver
64 | * (not just a known receiver type but a known receiver object) via annotation driven
65 | * compile-time {@linkplain FOLD folding}. This is how calls to the {@link GeneralLayout layout}
66 | * interface methods are reduced to monomorphic calls at compile-time.
67 | *
68 | * See {@link ClassActor#toJava()} and {@link ArrayClassActor#toJava()} for an example.
69 | */
70 | boolean override() default false;
71 |
72 | /**
73 | * If true, this element specifies that inlining of the thus annotated method is only allowed
74 | * after snippet compilation has concluded.
75 | *
76 | * @see CompilerScheme#areSnippetsCompiled()
77 | */
78 | boolean afterSnippetsAreCompiled() default false;
79 | }
80 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/annotate/INSPECTED.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.annotate;
22 |
23 | import java.lang.annotation.*;
24 |
25 | /**
26 | * Marks a field, method or constructor that is reflected upon by the Inspector.
27 | *
28 | * The Inspector uses this annotation to auto-generate objects for accessing the
29 | * annotated entity in the remote VM process. See the {@code TeleFields}
30 | * and {@code TeleMethods} classes in the Tele project.
31 | *
32 | * @author Doug Simon
33 | */
34 | @Retention(RetentionPolicy.RUNTIME)
35 | @Target({ ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD })
36 | public @interface INSPECTED {
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/annotate/Package.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.annotate;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * @see MaxPackage
27 | *
28 | * @author Bernd Mathiske
29 | */
30 | public class Package extends BasePackage {
31 | public Package() {
32 | super();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/annotate/RESET.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.annotate;
22 |
23 | import java.lang.annotation.*;
24 |
25 | /**
26 | * Denotes a field whose value is reset to the default value for its type when it is copied into the Maxine boot image.
27 | *
28 | * @author Doug Simon
29 | */
30 | @Retention(RetentionPolicy.RUNTIME)
31 | @Target(ElementType.FIELD)
32 | public @interface RESET {
33 | }
34 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/annotate/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | /**
22 | * Annotations used throughout the Maxine project.
23 | *
24 | * @author Bernd Mathiske
25 | */
26 | package com.sun.max.annotate;
27 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/gui/Package.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.gui;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * This package is not included in the bootstrap as it would drag in most of Swing.
27 | *
28 | * @author Doug Simon
29 | */
30 | public class Package extends MaxPackage {
31 | public Package() {
32 | super();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/gui/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | /**
22 | * GUI utilities.
23 | *
24 | * @author Bernd Mathiske
25 | */
26 | package com.sun.max.gui;
27 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/CharArraySource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.io;
22 |
23 | import java.io.*;
24 |
25 | /**
26 | *
27 | *
28 | * @author Doug Simon
29 | */
30 | public class CharArraySource extends CharArrayWriter implements ReadableSource {
31 |
32 | public CharArraySource() {
33 | }
34 |
35 | public CharArraySource(int initialSize) {
36 | super(initialSize);
37 | }
38 |
39 | public Reader reader(boolean buffered) {
40 | final Reader reader = new CharArrayReader(buf, 0, count);
41 | return buffered ? new BufferedReader(reader) : reader;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/FileTraversal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.io;
22 |
23 | import java.io.*;
24 |
25 | /**
26 | * Provides a facility for walking a file system hierarchy similar to that provided by the Unix find(1) facility.
27 | *
28 | * @author Doug Simon
29 | */
30 | public class FileTraversal {
31 |
32 | private boolean stopped;
33 |
34 | /**
35 | * Handles a standard file resource encountered during the traversal.
36 | *
37 | * @param file a file resource for which {@link File#isFile()} returns {@code true}
38 | */
39 | protected void visitFile(File file) {
40 | }
41 |
42 | /**
43 | * Handles a directory encountered during the traversal.
44 | *
45 | * @param directory a file resource for which {@link File#isDirectory()} returns {@code true}
46 | * @return true if the traversal should process the file system hierarchy rooted at {@code directory}, false if it
47 | * should be skipped
48 | */
49 | protected boolean visitDirectory(File directory) {
50 | return true;
51 | }
52 |
53 | /**
54 | * Handles a file resource encountered during the traversal that is neither a standard file or directory.
55 | *
56 | * @param other a file resource for which neither {@link File#isFile()} nor {@link File#isDirectory()} returns
57 | * {@code true}
58 | */
59 | protected void visitOther(File other) {
60 | }
61 |
62 | /**
63 | * Stops the traversal after the current file resource has been processed. This can be called from within an
64 | * overriding implementation of {@link #visitFile(File)}, {@link #visitDirectory(File)} or
65 | * {@link #visitOther(File)} to prematurely terminate a traversal.
66 | */
67 | protected final void stop() {
68 | stopped = true;
69 | }
70 |
71 | /**
72 | * Traverses the file hierarchy rooted at a given file. The {@linkplain #wasStopped() stopped} status of this
73 | * traversal object is reset to {@code false} before the traversal begins.
74 | *
75 | * @param file the file or directory at which to start the traversal
76 | */
77 | public void run(File file) {
78 | stopped = false;
79 | visit(file);
80 | }
81 |
82 | /**
83 | * Determines if the traversal was stopped before every file in the file hierarchy was traversed.
84 | */
85 | public boolean wasStopped() {
86 | return stopped;
87 | }
88 |
89 | private boolean visit(File entry) {
90 | File subdirectoryToTraverse = null;
91 | if (entry.isFile()) {
92 | visitFile(entry);
93 | } else if (entry.isDirectory()) {
94 | if (visitDirectory(entry)) {
95 | subdirectoryToTraverse = entry;
96 | }
97 | } else {
98 | visitOther(entry);
99 | }
100 | if (stopped) {
101 | return false;
102 | }
103 | if (subdirectoryToTraverse != null) {
104 | traverse(subdirectoryToTraverse);
105 | if (stopped) {
106 | return false;
107 | }
108 | }
109 | return true;
110 | }
111 |
112 | private void traverse(File directory) {
113 | final File[] entries = directory.listFiles();
114 | if (entries != null) {
115 | for (File entry : entries) {
116 | if (!visit(entry)) {
117 | return;
118 | }
119 | }
120 | }
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/IndentWriter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.io;
22 |
23 | import java.io.*;
24 |
25 | import com.sun.max.program.*;
26 |
27 | /**
28 | * A line oriented character writer that indents line output on the left.
29 | *
30 | * @author Bernd Mathiske
31 | */
32 | public class IndentWriter {
33 |
34 | private final PrintWriter writer;
35 | private int lineCount;
36 |
37 | /**
38 | * Gets an IndentWriter that wraps the {@linkplain Trace#stream() trace stream}.
39 | * @return
40 | */
41 | public static IndentWriter traceStreamWriter() {
42 | return new IndentWriter(new OutputStreamWriter(Trace.stream()));
43 | }
44 |
45 | public IndentWriter(Writer writer) {
46 | this.writer = (writer instanceof PrintWriter) ? (PrintWriter) writer : new PrintWriter(writer);
47 | }
48 |
49 | public void close() {
50 | writer.close();
51 | }
52 |
53 | public void flush() {
54 | writer.flush();
55 | }
56 |
57 | private int indentation = 4;
58 |
59 | public int indentation() {
60 | return indentation;
61 | }
62 |
63 | public void setIndentation(int indentation) {
64 | this.indentation = indentation;
65 | }
66 |
67 | private int prefix;
68 |
69 | public void indent() {
70 | prefix += indentation;
71 | }
72 |
73 | public void outdent() {
74 | prefix -= indentation;
75 | assert prefix >= 0;
76 | }
77 |
78 | private boolean isCurrentLineIndented;
79 |
80 | private void writeIndentation() {
81 | if (!isCurrentLineIndented) {
82 | for (int i = 0; i < prefix; i++) {
83 | writer.print(" ");
84 | }
85 | isCurrentLineIndented = true;
86 | }
87 | }
88 |
89 | public void printSpaces(int width) {
90 | for (int i = 0; i < width; i++) {
91 | writer.print(" ");
92 | }
93 | }
94 |
95 | public void printFixedWidth(String s, int width) {
96 | assert width > 0 : "width must be positive";
97 | String text = s;
98 | if (text.length() + 1 > width) {
99 | if (width - 4 > 0) {
100 | text = s.substring(0, width - 4) + "...";
101 | } else {
102 | text = s.substring(0, width);
103 | }
104 | }
105 | writer.print(text);
106 | printSpaces(width - text.length());
107 | }
108 |
109 | public void print(String s) {
110 | writeIndentation();
111 | writer.print(s);
112 | }
113 |
114 | public void println() {
115 | writer.println();
116 | isCurrentLineIndented = false;
117 | ++lineCount;
118 | }
119 |
120 | public void println(String s) {
121 | writeIndentation();
122 | writer.println(s);
123 | isCurrentLineIndented = false;
124 | ++lineCount;
125 | }
126 |
127 | public void printLines(InputStream inputStream) {
128 | printLines(new InputStreamReader(inputStream));
129 | }
130 |
131 | public void printLines(Reader reader) {
132 | final BufferedReader bufferedReader = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
133 | String line;
134 | try {
135 | while ((line = bufferedReader.readLine()) != null) {
136 | println(line);
137 | }
138 | } catch (IOException e) {
139 | ProgramWarning.message(e.toString());
140 | }
141 | }
142 |
143 | public int lineCount() {
144 | return lineCount;
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/MultiOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.io;
22 |
23 | import java.io.*;
24 |
25 | /**
26 | * Writes the same output to several streams.
27 | *
28 | * @author Bernd Mathiske
29 | */
30 | public class MultiOutputStream extends OutputStream {
31 |
32 | private final OutputStream[] streams;
33 |
34 | public MultiOutputStream(OutputStream... streams) {
35 | this.streams = streams;
36 | }
37 |
38 | @Override
39 | public void write(int b) throws IOException {
40 | for (OutputStream stream : streams) {
41 | stream.write(b);
42 | }
43 | }
44 |
45 | @Override
46 | public void write(byte[] bytes) throws IOException {
47 | for (OutputStream stream : streams) {
48 | stream.write(bytes);
49 | }
50 | }
51 |
52 | @Override
53 | public void write(byte[] bytes, int startOffset, int numberOfBytes) throws IOException {
54 | for (OutputStream stream : streams) {
55 | stream.write(bytes, startOffset, numberOfBytes);
56 | }
57 | }
58 |
59 | @Override
60 | public void flush() throws IOException {
61 | for (OutputStream stream : streams) {
62 | stream.flush();
63 | }
64 | }
65 |
66 | @Override
67 | public void close() throws IOException {
68 | for (OutputStream stream : streams) {
69 | stream.close();
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/NullOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.io;
22 |
23 | import java.io.*;
24 |
25 | /**
26 | * An output stream that discards everything written to it.
27 | *
28 | * @author Doug Simon
29 | */
30 | public class NullOutputStream extends OutputStream {
31 |
32 | @Override
33 | public void write(int b) throws IOException {
34 | }
35 |
36 | @Override
37 | public void close() throws IOException {
38 | }
39 |
40 | @Override
41 | public void flush() throws IOException {
42 | }
43 |
44 | @Override
45 | public void write(byte[] b, int off, int len) throws IOException {
46 | }
47 |
48 | @Override
49 | public void write(byte[] b) throws IOException {
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/Package.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.io;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * @see MaxPackage
27 | *
28 | * @author Bernd Mathiske
29 | */
30 | public class Package extends BasePackage {
31 | public Package() {
32 | super();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/ReadableSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.io;
22 |
23 | import java.io.*;
24 |
25 | /**
26 | * A readable source is a character data source that provides a Reader to read the data.
27 | *
28 | * @author Doug Simon
29 | */
30 | public interface ReadableSource {
31 |
32 | /**
33 | * @param buffered if true, the returned reader is guaranteed to be a BufferedReader
34 | *
35 | * @return a reader to read the character data represented by this source
36 | */
37 | Reader reader(boolean buffered) throws IOException;
38 |
39 | public static final class Static {
40 |
41 | private Static() {
42 |
43 | }
44 |
45 | /**
46 | * Creates a ReadableSource to provides readers for the characters in a string.
47 | */
48 | public static ReadableSource fromString(final String s) {
49 | return new ReadableSource() {
50 | public Reader reader(boolean buffered) throws IOException {
51 | return buffered ? new BufferedReader(new StringReader(s)) : new StringReader(s);
52 | }
53 | };
54 | }
55 |
56 | /**
57 | * Creates a ReadableSource to provides readers for the characters in a file.
58 | */
59 | public static ReadableSource fromFile(final File file) {
60 | return new ReadableSource() {
61 | public Reader reader(boolean buffered) throws IOException {
62 | return buffered ? new BufferedReader(new FileReader(file)) : new FileReader(file);
63 | }
64 | };
65 |
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/SeekableByteArrayOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.io;
22 |
23 | import java.io.*;
24 |
25 | /**
26 | * A {@link ByteArrayOutputStream} that can have its write position {@linkplain #seek(int) updated}.
27 | *
28 | * @author Doug Simon
29 | */
30 | public class SeekableByteArrayOutputStream extends ByteArrayOutputStream {
31 |
32 | private int highestCount;
33 |
34 | /**
35 | * @see ByteArrayOutputStream#ByteArrayOutputStream()
36 | */
37 | public SeekableByteArrayOutputStream() {
38 | }
39 |
40 | /**
41 | * @see ByteArrayOutputStream#ByteArrayOutputStream(int)
42 | */
43 | public SeekableByteArrayOutputStream(int size) {
44 | super(size);
45 | }
46 |
47 | /**
48 | * Updates the write position of this stream. The stream can only be repositioned between 0 and the
49 | * {@linkplain #endOfStream() end of the stream}.
50 | *
51 | * @param index
52 | * the index to which the write position of this stream will be set
53 | * @throws IllegalArgumentException
54 | * if {@code index > highestSeekIndex()}
55 | */
56 | public void seek(int index) throws IllegalArgumentException {
57 | if (endOfStream() < index) {
58 | throw new IllegalArgumentException();
59 | }
60 | count = index;
61 | }
62 |
63 | /**
64 | * Gets the index one past the highest index that has been written to in this stream.
65 | */
66 | public int endOfStream() {
67 | if (highestCount < count) {
68 | highestCount = count;
69 | }
70 | return highestCount;
71 | }
72 |
73 | @Override
74 | public void reset() {
75 | super.reset();
76 | highestCount = 0;
77 | }
78 |
79 | /**
80 | * Copies the {@code length} bytes of this byte array output stream starting at {@code offset} to {@code buf}
81 | * starting at {@code bufOffset}.
82 | */
83 | public void copyTo(int offset, byte[] toBuffer, int toOffset, int length) {
84 | System.arraycopy(this.buf, offset, toBuffer, toOffset, length);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/TemporaryFiles.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.io;
22 |
23 | import java.io.*;
24 |
25 | import com.sun.max.program.*;
26 |
27 | public final class TemporaryFiles {
28 | private TemporaryFiles() {
29 | }
30 |
31 | public static void cleanup(final String prefix, final String suffix) {
32 | if ((prefix == null || prefix.length() == 0) && (suffix == null || suffix.length() == 0)) {
33 | return;
34 | }
35 | try {
36 | final File tempFile = File.createTempFile(prefix, suffix);
37 | final File directory = tempFile.getParentFile();
38 | final FilenameFilter filter = new FilenameFilter() {
39 | public boolean accept(File dir, String name) {
40 | if (prefix != null && prefix.length() > 0 && !name.startsWith(prefix)) {
41 | return false;
42 | }
43 | if (suffix != null && suffix.length() > 0 && !name.endsWith(suffix)) {
44 | return false;
45 | }
46 | return true;
47 | }
48 | };
49 | for (File file : directory.listFiles(filter)) {
50 | if (!file.delete()) {
51 | ProgramWarning.message("could not delete temporary file: " + file.getAbsolutePath());
52 | }
53 | }
54 | } catch (IOException ioException) {
55 | ProgramWarning.message("could not delete temporary files");
56 | }
57 | }
58 |
59 | public static void cleanup(String prefix) {
60 | cleanup(prefix, null);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/TruncatedInputException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.io;
22 |
23 | import java.io.*;
24 |
25 | /**
26 | * Unexpected EOF during input.
27 | *
28 | * @author Michael Van De Vanter
29 | */
30 | public class TruncatedInputException extends EOFException {
31 |
32 | private final int nRead;
33 |
34 | /**
35 | * @param s Exception message
36 | * @param n Length of input read before EOF.
37 | */
38 | public TruncatedInputException(String s, int n) {
39 | super(s);
40 | nRead = n;
41 | }
42 |
43 | /**
44 | *
45 | * @return Length of input read before EOF.
46 | */
47 | public int inputLength() {
48 | return nRead;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/io/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | /**
22 | * Supplementing java.io.
23 | *
24 | * @author Bernd Mathiske
25 | */
26 | package com.sun.max.io;
27 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/Chars.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.lang;
22 |
23 | import com.sun.max.util.*;
24 |
25 | /**
26 | * @author Bernd Mathiske
27 | */
28 | public final class Chars {
29 |
30 | private Chars() {
31 | }
32 |
33 | public static final int SIZE = 2;
34 |
35 | public static final Range VALUE_RANGE = new Range(Character.MIN_VALUE, Character.MAX_VALUE);
36 |
37 | public static boolean isHexDigit(char c) {
38 | switch (c) {
39 | case '0':
40 | case '1':
41 | case '2':
42 | case '3':
43 | case '4':
44 | case '5':
45 | case '6':
46 | case '7':
47 | case '8':
48 | case '9':
49 | case 'a':
50 | case 'b':
51 | case 'c':
52 | case 'd':
53 | case 'e':
54 | case 'f':
55 | case 'A':
56 | case 'B':
57 | case 'C':
58 | case 'D':
59 | case 'E':
60 | case 'F':
61 | return true;
62 | }
63 | return false;
64 | }
65 |
66 | public static boolean isOctalDigit(char c) {
67 | if (c < '0') {
68 | return false;
69 | }
70 | return c <= '7';
71 | }
72 |
73 | public static String toJavaLiteral(char c) {
74 | if (c == '\n') {
75 | return "'\\n'";
76 | }
77 | if (c == '\t') {
78 | return "'\\t'";
79 | }
80 | if (c == '\r') {
81 | return "'\\r'";
82 | }
83 | if (c < ' ' || c > 127) {
84 | return "'\\" + Integer.toOctalString(c) + "'";
85 | }
86 | return "'" + c + "'";
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/Function.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.lang;
22 |
23 | import java.util.concurrent.*;
24 |
25 | /**
26 | * Creates a function wrapper for a method that returns a value and may throw a checked exception.
27 | * This interface extends {@link Callable} so that {@code Function}s can be used with an {@link ExecutorService}.
28 | *
29 | *
30 | * @author Bernd Mathiske
31 | * @author Doug Simon
32 | */
33 | public interface Function extends Callable {
34 |
35 | /**
36 | * Computes a result, or throws an exception if unable to do so.
37 | *
38 | * @return computed result (which will be {@code null} if {@code Result_Type} is {@link Void})
39 | * @throws Exception if unable to compute a result
40 | */
41 | T call() throws Exception;
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/Longs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.lang;
22 |
23 | /**
24 | * Additional methods that one might want in java.lang.Long.
25 | *
26 | * @author Bernd Mathiske
27 | */
28 | public final class Longs {
29 |
30 | private Longs() {
31 | }
32 |
33 | public static final int SIZE = 8;
34 | public static final int WIDTH = 64;
35 |
36 | public static final long INT_MASK = 0xffffffffL;
37 |
38 | public static int compare(long greater, long lesser) {
39 | if (greater > lesser) {
40 | return 1;
41 | }
42 | if (greater == lesser) {
43 | return 0;
44 | }
45 | return -1;
46 | }
47 |
48 | public static int numberOfEffectiveSignedBits(long signed) {
49 | if (signed >= 0) {
50 | return 65 - Long.numberOfLeadingZeros(signed);
51 | }
52 | return 65 - Long.numberOfLeadingZeros(~signed);
53 | }
54 |
55 | public static int numberOfEffectiveUnsignedBits(long unsigned) {
56 | return 64 - Long.numberOfLeadingZeros(unsigned);
57 | }
58 |
59 | public static byte getByte(long value, int index) {
60 | return (byte) ((value >> (index * 8)) & 0xffL);
61 | }
62 |
63 | public static String toPaddedHexString(long n, char pad) {
64 | final String s = Long.toHexString(n);
65 | return Strings.times(pad, 16 - s.length()) + s;
66 | }
67 |
68 | /**
69 | * Determines if a given number is zero or a power of two.
70 | */
71 | public static boolean isPowerOfTwoOrZero(long n) {
72 | return Long.lowestOneBit(n) == n;
73 | }
74 |
75 | public static final long K = 1024;
76 | public static final long M = K * K;
77 | public static final long G = M * K;
78 | public static final long T = G * K;
79 | public static final long P = T * K;
80 |
81 | /**
82 | * Converts a positive number to a string using unit suffixes to reduce the
83 | * number of digits to three or less using base 2 for sizes.
84 | *
85 | * @param number the number to convert to a string
86 | * @param onlyPowerOfTwo if {@code true}, then a unit suffix is only used if {@code number} is an exact power of 2
87 | */
88 | public static String toUnitsString(long number, boolean onlyPowerOfTwo) {
89 | if (number < 0) {
90 | throw new IllegalArgumentException(String.valueOf(number));
91 | }
92 | if (onlyPowerOfTwo && !isPowerOfTwoOrZero(number)) {
93 | return String.valueOf(number);
94 | }
95 | if (number >= P) {
96 | return number / P + "P";
97 | }
98 | if (number >= T) {
99 | return number / T + "T";
100 | }
101 | if (number >= G) {
102 | return number / G + "G";
103 | }
104 | if (number >= M) {
105 | return number / M + "M";
106 | }
107 | if (number >= K) {
108 | return number / K + "K";
109 | }
110 | return Long.toString(number);
111 | }
112 |
113 | /**
114 | * Parse a size specification nX, where X := {K, M, G, T, P, k, m, g, t, p}.
115 | *
116 | * @param value a string containing a long number that can be parsed by {@link Long#parseLong(String)} followed by
117 | * an optional scaling character
118 | * @return the scaled value
119 | * @throws NumberFormatException if {@code value} does not contain a parsable {@code long} or has an invalid scale
120 | * suffix
121 | */
122 | public static long parseScaledValue(String value) throws NumberFormatException {
123 | char lastChar = value.charAt(value.length() - 1);
124 | if (!Character.isDigit(lastChar)) {
125 | long result = Long.parseLong(value.substring(0, value.length() - 1));
126 | switch (lastChar) {
127 | case 'K':
128 | case 'k': {
129 | return result * Longs.K;
130 | }
131 | case 'M':
132 | case 'm': {
133 | return result * Longs.M;
134 | }
135 | case 'G':
136 | case 'g': {
137 | return result * Longs.G;
138 | }
139 | case 'T':
140 | case 't': {
141 | return result * Longs.T;
142 | }
143 | case 'P':
144 | case 'p': {
145 | return result * Longs.P;
146 | }
147 | default: {
148 | throw new NumberFormatException("Number with unknown scale suffix: " + value);
149 | }
150 | }
151 | }
152 | return Long.parseLong(value);
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/MutableInnerClassGlobal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.lang;
22 |
23 | /**
24 | * Globals to inner classes must be final, so we need to box them somehow
25 | * if we want them to have a mutable global.
26 | *
27 | * @author Bernd Mathiske
28 | */
29 | public class MutableInnerClassGlobal {
30 |
31 | private T value;
32 |
33 | public T value() {
34 | return value;
35 | }
36 |
37 | public MutableInnerClassGlobal() {
38 | }
39 |
40 | public MutableInnerClassGlobal(T value) {
41 | this.value = value;
42 | }
43 |
44 | public void setValue(T value) {
45 | this.value = value;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/Package.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.lang;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * @see MaxPackage
27 | *
28 | * @author Bernd Mathiske
29 | */
30 | public class Package extends BasePackage {
31 | public Package() {
32 | super();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/Procedure.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.lang;
22 |
23 | /**
24 | * @author Bernd Mathiske
25 | */
26 | public interface Procedure {
27 |
28 | void run(T argument);
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/Shorts.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.lang;
22 |
23 | import com.sun.max.util.*;
24 |
25 | /**
26 | * @author Bernd Mathiske
27 | */
28 | public final class Shorts {
29 |
30 | private Shorts() {
31 | }
32 |
33 | public static final int SIZE = 2;
34 | public static final int WIDTH = 16;
35 | public static final int MASK = 0xffff;
36 |
37 | public static final Range VALUE_RANGE = new Range(Short.MIN_VALUE, Short.MAX_VALUE);
38 | }
39 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/StaticFieldLiteral.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.lang;
22 |
23 | import java.lang.reflect.*;
24 |
25 | import com.sun.max.program.*;
26 |
27 | public interface StaticFieldLiteral {
28 |
29 | String literal();
30 |
31 | void setLiteral(String literal);
32 |
33 | Class literalClass();
34 |
35 | void setLiteralClass(Class literalClass);
36 |
37 | public static final class Static {
38 |
39 | private Static() {
40 | }
41 |
42 | public static void initialize(Class staticFieldLiteralClass) {
43 | for (Field field : staticFieldLiteralClass.getDeclaredFields()) {
44 | if ((field.getModifiers() & Modifier.STATIC) != 0 && StaticFieldLiteral.class.isAssignableFrom(field.getType())) {
45 | field.setAccessible(true);
46 | try {
47 | final StaticFieldLiteral staticFieldLiteral = (StaticFieldLiteral) field.get(staticFieldLiteralClass);
48 | staticFieldLiteral.setLiteral(field.getName());
49 | staticFieldLiteral.setLiteralClass(staticFieldLiteralClass);
50 | } catch (IllegalAccessException illegalAccessException) {
51 | ProgramError.unexpected("could not name literal of field: " + field);
52 | }
53 | }
54 | }
55 | }
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/StaticFieldName.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.lang;
22 |
23 | import java.lang.reflect.*;
24 | import java.util.*;
25 |
26 | import com.sun.max.program.*;
27 |
28 | public interface StaticFieldName {
29 |
30 | String name();
31 |
32 | void setName(String name);
33 |
34 | public interface StringFunction {
35 | String function(String string);
36 | }
37 |
38 | public interface Procedure {
39 | void procedure(StaticFieldName staticFieldName);
40 | }
41 |
42 | public static final class Static {
43 |
44 | private Static() {
45 | }
46 |
47 | public static List initialize(Class staticNameFieldClass, StringFunction stringFunction, Procedure procedure) {
48 | final List sequence = new LinkedList();
49 | for (Field field : staticNameFieldClass.getDeclaredFields()) {
50 | if ((field.getModifiers() & Modifier.STATIC) != 0 && StaticFieldName.class.isAssignableFrom(field.getType())) {
51 | field.setAccessible(true);
52 | try {
53 | final StaticFieldName value = (StaticFieldName) field.get(null);
54 | if (value.name() == null) {
55 | String name = field.getName();
56 | if (stringFunction != null) {
57 | name = stringFunction.function(name);
58 | }
59 | value.setName(name);
60 | }
61 | if (procedure != null) {
62 | procedure.procedure(value);
63 | }
64 | sequence.add(value);
65 | } catch (IllegalAccessException illegalAccessException) {
66 | ProgramError.unexpected("could not name value of field: " + field);
67 | }
68 | }
69 | }
70 | return sequence;
71 | }
72 |
73 | public static List initialize(Class staticNameFieldClass, StringFunction stringFunction) {
74 | return initialize(staticNameFieldClass, stringFunction, null);
75 | }
76 |
77 | public static List initialize(Class staticNameFieldClass, Procedure procedure) {
78 | return initialize(staticNameFieldClass, null, procedure);
79 | }
80 |
81 | public static List initialize(Class staticNameFieldClass) {
82 | return initialize(staticNameFieldClass, null, null);
83 | }
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/WordWidth.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.lang;
22 |
23 | import java.util.*;
24 |
25 | /**
26 | * A word width value describes how many bits there are in a machine word.
27 | *
28 | * @author Bernd Mathiske
29 | */
30 | public enum WordWidth {
31 |
32 | BITS_8(8, byte.class, Byte.MIN_VALUE, Byte.MAX_VALUE, 3),
33 | BITS_16(16, short.class, Short.MIN_VALUE, Short.MAX_VALUE, 4),
34 | BITS_32(32, int.class, Integer.MIN_VALUE, Integer.MAX_VALUE, 5),
35 | BITS_64(64, long.class, Long.MIN_VALUE, Long.MAX_VALUE, 6);
36 |
37 | public static final List VALUES = java.util.Arrays.asList(values());
38 |
39 | /**
40 | * Number of bits in a Word.
41 | * This must be a positive power of two.
42 | */
43 | public final int numberOfBits;
44 |
45 | /**
46 | * Log2 of the number of bits.
47 | */
48 | public final int log2numberOfBits;
49 |
50 | /**
51 | * Log2 of the number of bytes.
52 | */
53 | public final int log2numberOfBytes;
54 |
55 | /**
56 | * Number of bytes in a Word.
57 | * This must be a positive power of two.
58 | */
59 | public final int numberOfBytes;
60 |
61 | public final Class canonicalPrimitiveType;
62 | public final long min;
63 | public final long max;
64 |
65 | private WordWidth(int numberOfBits, Class canonicalPrimitiveType, long min, long max, int log2numberOfBits) {
66 | this.numberOfBits = numberOfBits;
67 | this.numberOfBytes = numberOfBits / 8;
68 | this.canonicalPrimitiveType = canonicalPrimitiveType;
69 | this.min = min;
70 | this.max = max;
71 | this.log2numberOfBits = log2numberOfBits;
72 | this.log2numberOfBytes = log2numberOfBits - 3;
73 | }
74 |
75 | public boolean lessThan(WordWidth other) {
76 | return numberOfBits < other.numberOfBits;
77 | }
78 |
79 | public boolean lessEqual(WordWidth other) {
80 | return numberOfBits <= other.numberOfBits;
81 | }
82 |
83 | public boolean greaterThan(WordWidth other) {
84 | return numberOfBits > other.numberOfBits;
85 | }
86 |
87 | public boolean greaterEqual(WordWidth other) {
88 | return numberOfBits >= other.numberOfBits;
89 | }
90 |
91 | @Override
92 | public String toString() {
93 | return Integer.toString(numberOfBits);
94 | }
95 |
96 | public static WordWidth fromInt(int wordWidth) {
97 | if (wordWidth <= 8) {
98 | return WordWidth.BITS_8;
99 | }
100 | if (wordWidth <= 16) {
101 | return WordWidth.BITS_16;
102 | }
103 | if (wordWidth <= 32) {
104 | return WordWidth.BITS_32;
105 | }
106 | return WordWidth.BITS_64;
107 | }
108 |
109 | /**
110 | * @return which word width is minimally required to represent all the non-one bits in the signed argument, and a sign bit
111 | */
112 | public static WordWidth signedEffective(int signed) {
113 | return fromInt(Ints.numberOfEffectiveSignedBits(signed));
114 | }
115 |
116 | /**
117 | * @return which word width is minimally required to represent all the non-zero bits in the unsigned argument
118 | */
119 | public static WordWidth unsignedEffective(int unsigned) {
120 | return fromInt(Ints.numberOfEffectiveUnsignedBits(unsigned));
121 | }
122 |
123 | /**
124 | * @return which word width is minimally required to represent all the non-one bits in the signed argument, and a sign bit
125 | */
126 | public static WordWidth signedEffective(long signed) {
127 | return fromInt(Longs.numberOfEffectiveSignedBits(signed));
128 | }
129 |
130 | /**
131 | * @return which word width is minimally required to represent all the non-zero bits in the unsigned argument
132 | */
133 | public static WordWidth unsignedEffective(long unsigned) {
134 | return fromInt(Longs.numberOfEffectiveUnsignedBits(unsigned));
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/lang/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | /**
22 | * Supplementing java.lang.
23 | *
24 | * @author Bernd Mathiske
25 | */
26 | package com.sun.max.lang;
27 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | /**
22 | * Project Maxine software
23 | *
24 | * The top level package contains classes that provide package info manipulation operations.
25 | *
26 | * @author Bernd Mathiske
27 | */
28 | package com.sun.max;
29 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/ClassSearch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program;
22 |
23 | import java.io.*;
24 | import java.util.*;
25 | import java.util.zip.*;
26 |
27 | import com.sun.max.lang.*;
28 |
29 | /**
30 | * Provides a facility for finding classes reachable on a given {@linkplain Classpath classpath}.
31 | *
32 | * @author Doug Simon
33 | */
34 | public class ClassSearch extends ClasspathTraversal {
35 |
36 | private final HashSet classes;
37 |
38 | public ClassSearch() {
39 | this(false);
40 | }
41 |
42 | /**
43 | * Creates a class search object.
44 | *
45 | * @param omitDuplicates if true, then each argument passed to {@link #visitClass(String)} is guaranteed to be unique.
46 | */
47 | public ClassSearch(boolean omitDuplicates) {
48 | if (omitDuplicates) {
49 | classes = new HashSet();
50 | } else {
51 | classes = null;
52 | }
53 | }
54 |
55 | /**
56 | * Handles a class file encountered during the traversal.
57 | *
58 | * @param className
59 | * the name of the class denoted by the class file
60 | * @return true if the traversal should continue, false if it should terminate
61 | */
62 | protected boolean visitClass(String className) {
63 | return true;
64 | }
65 |
66 | /**
67 | * Handles a class file encountered during the traversal. Unless this object was initialized to omit duplicates,
68 | * this method may be called more than once for the same class as class files are not guaranteed to be unique in a
69 | * classpath.
70 | *
71 | * @param isArchiveEntry true if the class is in a .zip or .jar file, false if it is a file in a directory
72 | * @param className the name of the class denoted by the class file
73 | * @return true if the traversal should continue, false if it should terminate
74 | */
75 | protected boolean visitClass(boolean isArchiveEntry, String className) {
76 | if (classes != null) {
77 | if (classes.contains(className)) {
78 | return true;
79 | }
80 | classes.add(className);
81 | }
82 | return visitClass(className);
83 | }
84 |
85 | protected boolean visit(boolean isArchiveEntry, String dottifiedResource) {
86 | if (dottifiedResource.endsWith(".class")) {
87 | final String className = Strings.chopSuffix(dottifiedResource, ".class");
88 | return visitClass(isArchiveEntry, className);
89 | }
90 | return true;
91 | }
92 |
93 | @Override
94 | protected boolean visitArchiveEntry(ZipFile archive, ZipEntry resource) {
95 | return visit(true, resource.getName().replace('/', '.'));
96 | }
97 |
98 | @Override
99 | protected boolean visitFile(File parent, String resource) {
100 | return visit(false, resource.replace(File.separatorChar, '.'));
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/ClasspathFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program;
22 |
23 | import com.sun.max.program.Classpath.*;
24 |
25 | /**
26 | * Encapulates the contents of a file loaded from an {@linkplain Entry entry} on a {@linkplain Classpath classpath}.
27 | *
28 | * @author Doug Simon
29 | */
30 | public final class ClasspathFile {
31 |
32 | /**
33 | * The bytes of the file represented by this object.
34 | */
35 | public final byte[] contents;
36 |
37 | /**
38 | * The classpath entry from which the file represented by this object was read.
39 | */
40 | public final Entry classpathEntry;
41 |
42 | /**
43 | * Creates an object encapsulating the bytes of a file read via a classpath entry.
44 | *
45 | * @param contents the bytes of the file that was read
46 | * @param classpathEntry the entry from which the file was read
47 | */
48 | public ClasspathFile(byte[] contents, Entry classpathEntry) {
49 | this.classpathEntry = classpathEntry;
50 | this.contents = contents;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/ClasspathTraversal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program;
22 |
23 | import java.io.*;
24 | import java.util.*;
25 | import java.util.zip.*;
26 |
27 | import com.sun.max.io.*;
28 | import com.sun.max.program.Classpath.*;
29 |
30 | /**
31 | * Provides a facility for processing all the resources reachable on a given {@linkplain Classpath classpath}.
32 | *
33 | * @author Doug Simon
34 | */
35 | public class ClasspathTraversal {
36 |
37 | /**
38 | * Handles a standard file resource encountered during the traversal.
39 | *
40 | * @param parent the classpath directory entry under which the resource is located
41 | * @param resource the path of the resource relative to {@code parent}. The
42 | * {@linkplain File#separatorChar platform specific} character is used as the path separator in this
43 | * value.
44 | * @return true if the traversal should continue, false if it should terminate
45 | */
46 | protected boolean visitFile(File parent, String resource) {
47 | return true;
48 | }
49 |
50 | /**
51 | * Handles an archive entry resource encountered during the traversal.
52 | *
53 | * @param archive the classpath .zip or .jar entry in which the resource is located
54 | * @param resource the archive entry holding the resource
55 | * @return true if the traversal should continue, false if it should terminate
56 | */
57 | protected boolean visitArchiveEntry(ZipFile archive, ZipEntry resource) {
58 | return true;
59 | }
60 |
61 | /**
62 | * Traverses all the resources reachable on a given classpath.
63 | *
64 | * @param classpath the classpath to search
65 | */
66 | public void run(final Classpath classpath) {
67 | run(classpath, null);
68 | }
69 |
70 | /**
71 | * Traverses all the resources reachable on a given classpath.
72 | *
73 | * @param classpath the classpath to search
74 | * @param resourcePrefixFilter if non-null, then only resources whose name begins with this value are traversed. The
75 | * '/' character must be used in this value as the path separator regardless of the
76 | * {@linkplain File#separatorChar default} for the underlying platform.
77 | */
78 | public void run(final Classpath classpath, String resourcePrefixFilter) {
79 | for (final Entry entry : classpath.entries()) {
80 | if (entry.isDirectory()) {
81 | final String prefix = entry.path() + File.separator;
82 | final File startFile;
83 | if (resourcePrefixFilter == null) {
84 | startFile = entry.file();
85 | } else {
86 | if (File.separatorChar != '/') {
87 | startFile = new File(entry.file(), resourcePrefixFilter.replace('/', File.separatorChar));
88 | } else {
89 | startFile = new File(entry.file(), resourcePrefixFilter);
90 | }
91 | }
92 |
93 | final FileTraversal fileTraversal = new FileTraversal() {
94 | @Override
95 | protected void visitFile(File file) {
96 | final String path = file.getPath();
97 | assert path.startsWith(prefix);
98 | final String resource = path.substring(prefix.length());
99 | if (!ClasspathTraversal.this.visitFile(entry.file(), resource)) {
100 | stop();
101 | }
102 | }
103 | };
104 | fileTraversal.run(startFile);
105 | if (fileTraversal.wasStopped()) {
106 | return;
107 | }
108 | } else if (entry.isArchive()) {
109 | final ZipFile zipFile = entry.zipFile();
110 | if (zipFile != null) {
111 | for (final Enumeration extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();) {
112 | final ZipEntry zipEntry = e.nextElement();
113 | if (resourcePrefixFilter == null || zipEntry.getName().startsWith(resourcePrefixFilter)) {
114 | if (!visitArchiveEntry(zipFile, zipEntry)) {
115 | return;
116 | }
117 | }
118 | }
119 | }
120 | }
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/Package.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * @see MaxPackage
27 | *
28 | * @author Bernd Mathiske
29 | */
30 | public class Package extends BasePackage {
31 | public Package() {
32 | super();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/ProgramWarning.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program;
22 |
23 | /**
24 | * A collection of static methods for reporting a warning when an unexpected, non-fatal condition is encountered.
25 | *
26 | * @author Bernd Mathiske
27 | * @author Doug Simon
28 | */
29 | public final class ProgramWarning {
30 |
31 | /**
32 | * Implemented by a client that can {@linkplain ProgramWarning#setHandler(Handler) register}
33 | * itself to handle program warnings instead of having them printed to {@link System#err}.
34 | */
35 | public static interface Handler {
36 |
37 | /**
38 | * Handles display a given warning message.
39 | *
40 | * @param message a warning message
41 | */
42 | void handle(String message);
43 | }
44 |
45 | /**
46 | * Registers a handler to which warnings are redirected. Any previously registered handler
47 | * is overwritten and discarded.
48 | *
49 | * @param h if non-null, this object's {@link Handler#handle(String)} method is messaged instead of
50 | * printing the warning to {@link System#err} a ProgramError.
51 | */
52 | public static void setHandler(Handler h) {
53 | handler = h;
54 | }
55 |
56 | private static Handler handler;
57 |
58 | private ProgramWarning() {
59 | }
60 |
61 | /**
62 | * Prints a given warning message.
63 | *
64 | * @param warning the warning message to print
65 | */
66 | public static void message(String warning) {
67 | if (handler != null) {
68 | handler.handle(warning);
69 | } else {
70 | System.err.println("WARNING: " + warning);
71 | }
72 | }
73 |
74 | /**
75 | * Checks a given condition and if it's {@code false}, the appropriate warning message is printed.
76 | *
77 | * @param condition a condition to test
78 | * @param message the warning message to be printed if {@code condition == false}
79 | */
80 | public static void check(boolean condition, String warning) {
81 | if (!condition) {
82 | message(warning);
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/option/FieldOption.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program.option;
22 |
23 | import com.sun.max.*;
24 | import com.sun.max.program.ProgramError;
25 |
26 | import java.lang.reflect.Field;
27 |
28 | /**
29 | * This class implements a command line option that stores its value in a field
30 | * via reflection.
31 | *
32 | * @author Ben L. Titzer
33 | */
34 | public class FieldOption extends Option {
35 |
36 | protected final Object object;
37 | protected final Field field;
38 | protected T nullValue;
39 |
40 | public FieldOption(String name, Object object, Field field, T defaultValue, Type type, String help) {
41 | super(name, defaultValue, type, help);
42 | this.object = object;
43 | this.field = field;
44 | this.nullValue = defaultValue;
45 | }
46 |
47 | /**
48 | * Gets the value of this option. This implementation stores the field's value in a reflected field
49 | * and access requires a reflective access.
50 | * @return the value of this option
51 | */
52 | @Override
53 | public T getValue() {
54 | try {
55 | return Utils.cast(field.get(object));
56 | } catch (IllegalAccessException e) {
57 | throw ProgramError.unexpected(e);
58 | }
59 | }
60 |
61 | /**
62 | * Sets the value of this option. This implementation stores the field's value in a reflected field
63 | * and thus setting the value requires a reflective access.
64 | * @param value the value to set the new value to
65 | */
66 | @Override
67 | public void setValue(T value) {
68 | try {
69 | if (value == null) {
70 | field.set(object, nullValue);
71 | } else {
72 | field.set(object, value);
73 | }
74 | } catch (Exception e) {
75 | throw ProgramError.unexpected("Error updating the value of " + field, e);
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/option/MaxPackageOptionType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program.option;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * The {@code MaxPackageOptionType} class.
27 | * Created Nov 20, 2007
28 | *
29 | * @author Ben L. Titzer
30 | */
31 | public class MaxPackageOptionType extends Option.Type {
32 | public final MaxPackage superPackage;
33 | public final Class classType;
34 |
35 | public MaxPackageOptionType(MaxPackage superPackage, Class classType) {
36 | super(MaxPackage.class, "vm-package");
37 | this.superPackage = superPackage;
38 | this.classType = classType;
39 | }
40 | @Override
41 | public MaxPackage parseValue(String string) {
42 | final String fullName = superPackage.name() + "." + string;
43 | if (string != null && string.length() > 0) {
44 | MaxPackage result = MaxPackage.fromName(fullName);
45 | if (result == null) {
46 | result = MaxPackage.fromName(string);
47 | }
48 | if (result == null) {
49 | throw new Option.Error("MaxPackage not found: " + string + " (or " + fullName + ")");
50 | }
51 | return result;
52 | }
53 | return null;
54 | }
55 |
56 | @Override
57 | public String getValueFormat() {
58 | return "";
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/option/Option.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program.option;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * The {@code Option} class represents a command-line or other configuration
27 | * option with a particular name, type, and description.
28 | *
29 | * @author Ben L. Titzer
30 | */
31 | public class Option implements Cloneable {
32 |
33 | /**
34 | * The {@code Option.Type} class represents a type for an option. This class
35 | * implements method for parsing and unparsing values from strings.
36 | */
37 | public abstract static class Type {
38 | protected final String typeName;
39 | public final Class type;
40 |
41 | protected Type(Class type, String typeName) {
42 | this.typeName = typeName;
43 | this.type = type;
44 | }
45 |
46 | public String getTypeName() {
47 | return typeName;
48 | }
49 |
50 | public String unparseValue(T value) {
51 | return String.valueOf(value);
52 | }
53 |
54 | public abstract T parseValue(String string) throws Option.Error;
55 |
56 | public abstract String getValueFormat();
57 |
58 | public Option cast(Option option) {
59 | return Utils.cast(option);
60 | }
61 | }
62 |
63 | public static class Error extends java.lang.Error {
64 |
65 | public Error(String message) {
66 | super(message);
67 | }
68 | }
69 |
70 | protected final String name;
71 | protected T defaultValue;
72 | protected final Type type;
73 | protected final String help;
74 | protected T value;
75 |
76 | /**
77 | * The constructor for the {@code Option} class creates constructs a new
78 | * option with the specified parameters.
79 | *
80 | * @param name the name of the option as a string
81 | * @param defaultValue the default value of the option
82 | * @param type the type of the option, which is used for parsing and unparsing values
83 | * @param help a help description which is usually used to generate a formatted
84 | * help output
85 | */
86 | public Option(String name, T defaultValue, Type type, String help) {
87 | this.defaultValue = defaultValue;
88 | this.name = name;
89 | this.type = type;
90 | this.help = help;
91 | value = null;
92 | }
93 |
94 | /**
95 | * The {@code getName()} method returns the name of this option as a string.
96 | *
97 | * @return the name of this option
98 | */
99 | public String getName() {
100 | return name;
101 | }
102 |
103 | /**
104 | * Sets the default value for this option,
105 | * which is the value that the option retains if no assignment is made.
106 | *
107 | * @param val the default value of the option
108 | */
109 | public void setDefaultValue(T val) {
110 | defaultValue = val;
111 | }
112 |
113 | /**
114 | * The {@code getDefaultValue()} method returns the default value for this option,
115 | * which is the value that the option retains if no assignment is made.
116 | *
117 | * @return the default value of the option
118 | */
119 | public T getDefaultValue() {
120 | return defaultValue;
121 | }
122 |
123 | /**
124 | * The {@code getValue()} method retrieves the current value of this option.
125 | *
126 | * @return the current value of this option
127 | */
128 | public T getValue() {
129 | return !assigned ? defaultValue : value;
130 | }
131 |
132 | private boolean assigned;
133 |
134 | /**
135 | * The {@code setValue()) method sets the value of this option.
136 | *
137 | * @param value the new value to this option
138 | */
139 | public void setValue(T value) {
140 | assigned = true;
141 | this.value = value;
142 | }
143 |
144 | /**
145 | * The {@code setValue()} method sets the value of this option, given a string value.
146 | * The type of this option is used to determine how to parse the string into a value
147 | * of the appropriate type. Thus this method may potentially throw runtime exceptions
148 | * if parsing fails.
149 | *
150 | * @param string the new value of this option as a string
151 | */
152 | public void setString(String string) {
153 | setValue(type.parseValue(string));
154 | }
155 |
156 | /**
157 | * The {@code getType()} method returns the type of this option.
158 | * @return the type of this option.
159 | */
160 | public Type getType() {
161 | return type;
162 | }
163 |
164 | /**
165 | * The {@code getString()} method retrieves the value of this option as a string.
166 | * The type of this option is used to determine how to unparse the value into a string.
167 | *
168 | * @return the value of this option as a string
169 | */
170 | public String getString() {
171 | return type.unparseValue(getValue());
172 | }
173 |
174 | public String getHelp() {
175 | return help;
176 | }
177 |
178 | @Override
179 | public String toString() {
180 | return getName();
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/option/OptionSettings.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program.option;
22 |
23 | import java.lang.annotation.Retention;
24 | import java.lang.annotation.RetentionPolicy;
25 |
26 | /**
27 | * An annotation that can be applied to a static field to set its name as option and its help text.
28 | *
29 | * @author Ben L. Titzer
30 | */
31 | @Retention(RetentionPolicy.RUNTIME)
32 | public @interface OptionSettings {
33 |
34 | /**
35 | * The name of this option, if different from the name of the field.
36 | * @return the name of this option
37 | */
38 | String name() default "";
39 |
40 | /**
41 | * The help text of this option.
42 | * @return the help text
43 | */
44 | String help() default "";
45 | }
46 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/option/Package.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program.option;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * @see MaxPackage
27 | *
28 | * @author Bernd Mathiske
29 | */
30 | public class Package extends BasePackage {
31 | public Package() {
32 | super();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/option/gui/Package.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.program.option.gui;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * This package is not included in the bootstrap as it would drag in most of Swing.
27 | *
28 | * @author Doug Simon
29 | */
30 | public class Package extends MaxPackage {
31 | public Package() {
32 | super();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/option/gui/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | /**
22 | * GUI for getting command line options.
23 | *
24 | * @author Doug Simon
25 | */
26 | package com.sun.max.program.option.gui;
27 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/option/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | /**
22 | * Command line option parsing and side effect management.
23 | *
24 | * @author Bernd Mathiske
25 | */
26 | package com.sun.max.program.option;
27 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/program/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | /**
22 | * Utilities for any kind of Java program.
23 | *
24 | * @author Bernd Mathiske
25 | */
26 | package com.sun.max.program;
27 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/tele/interpreter/ExecutionFrame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.tele.interpreter;
22 |
23 | import java.util.*;
24 |
25 | import com.sun.max.vm.actor.holder.*;
26 | import com.sun.max.vm.actor.member.*;
27 | import com.sun.max.vm.classfile.*;
28 | import com.sun.max.vm.classfile.constant.*;
29 | import com.sun.max.vm.value.*;
30 |
31 | /**
32 | * Instances of this class represent individual execution frame entries on a given ExecutionThread's execution stack.
33 | *
34 | * @author Athul Acharya
35 | */
36 | class ExecutionFrame {
37 |
38 | private final ClassMethodActor method;
39 | private int currentOpcodePosition;
40 | private int currentBytePosition;
41 | private final Value[] locals;
42 | private final Stack operands;
43 | private final ExecutionFrame callersFrame;
44 | private final byte[] code;
45 | private final int depth;
46 |
47 | public ExecutionFrame(ExecutionFrame callersFrame, ClassMethodActor method) {
48 | this.method = method;
49 | this.locals = new Value[method.codeAttribute().maxLocals];
50 | this.operands = new Stack();
51 | this.callersFrame = callersFrame;
52 | this.code = method.codeAttribute().code();
53 | this.depth = callersFrame == null ? 1 : callersFrame.depth + 1;
54 | }
55 |
56 | /**
57 | * Computes the number of frames on the call stack up to and including this frame.
58 | */
59 | public int depth() {
60 | return depth;
61 | }
62 |
63 | public ExecutionFrame callersFrame() {
64 | return callersFrame;
65 | }
66 |
67 | public void setLocal(int index, Value value) {
68 | locals[index] = value;
69 | }
70 |
71 | public int readOpcode() {
72 | currentOpcodePosition = currentBytePosition;
73 | return readByte() & 0xff;
74 | }
75 |
76 | public byte readByte() {
77 | try {
78 | return code[currentBytePosition++];
79 | } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
80 | throw new VerifyError("Ran off end of code");
81 | }
82 | }
83 |
84 | public short readShort() {
85 | final int high = readByte();
86 | final int low = readByte() & 0xff;
87 | return (short) ((high << 8) | low);
88 | }
89 |
90 | public int readInt() {
91 | final int b3 = readByte() << 24;
92 | final int b2 = (readByte() & 0xff) << 16;
93 | final int b1 = (readByte() & 0xff) << 8;
94 | final int b0 = readByte() & 0xff;
95 | return b3 | b2 | b1 | b0;
96 | }
97 |
98 | public void skipBytes(int n) {
99 | currentBytePosition += n;
100 | }
101 |
102 | public void alignInstructionPosition() {
103 | final int remainder = currentBytePosition % 4;
104 | if (remainder != 0) {
105 | currentBytePosition += 4 - remainder;
106 | }
107 | }
108 |
109 | public void jump(int offset) {
110 | currentBytePosition = currentOpcodePosition + offset;
111 | }
112 |
113 | public int currentOpcodePosition() {
114 | return currentOpcodePosition;
115 | }
116 |
117 | public int currentBytePosition() {
118 | return currentBytePosition;
119 | }
120 |
121 | public void setBytecodePosition(int bcp) {
122 | currentBytePosition = bcp;
123 | }
124 |
125 | public byte[] code() {
126 | return code;
127 | }
128 |
129 | public Value getLocal(int index) {
130 | return locals[index];
131 | }
132 |
133 | public Stack stack() {
134 | return operands;
135 | }
136 |
137 | public ConstantPool constantPool() {
138 | return method.codeAttribute().constantPool;
139 | }
140 |
141 | public ClassMethodActor method() {
142 | return method;
143 | }
144 |
145 | @Override
146 | public String toString() {
147 | return method.format("%H.%n(%p) @ " + currentBytePosition);
148 | }
149 |
150 | /**
151 | * Handles an exception at the current execution point in this frame by updating the {@linkplain #setBytecodePosition(int)
152 | * instruction pointer} to the matching exception handler in this frame. If no matching exception handler is found
153 | * for the current execution point and the given exception type, then the instruction pointer in this frame is left
154 | * unmodified.
155 | *
156 | * The current execution point is derived from the value of {@link ExecutionFrame#currentBytePosition()} which is now at the first
157 | * byte passed the instruction currently being executed. That is, an instruction is completely decoded before any
158 | * exceptions are thrown while executing it.
159 | *
160 | * @param throwableClassActor the type of the exception being thrown
161 | * @return {@code true} if an exception handler was found, {@code false} otherwise
162 | */
163 | public boolean handleException(ClassActor throwableClassActor) {
164 | final int bcp = currentOpcodePosition;
165 | final ExceptionHandlerEntry[] handlers = method().codeAttribute().exceptionHandlerTable();
166 | for (ExceptionHandlerEntry handler : handlers) {
167 | if (bcp >= handler.startPosition() && bcp < handler.endPosition()) {
168 | if (handler.catchTypeIndex() == 0) {
169 | currentBytePosition = handler.handlerPosition();
170 | return true;
171 | }
172 | final ClassActor catchType = constantPool().classAt(handler.catchTypeIndex()).resolve(constantPool(), handler.catchTypeIndex());
173 | if (catchType.isAssignableFrom(throwableClassActor)) {
174 | currentBytePosition = handler.handlerPosition();
175 | return true;
176 | }
177 | }
178 | }
179 | return false;
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/tele/interpreter/ExecutionThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.tele.interpreter;
22 |
23 | import java.io.*;
24 |
25 | import com.sun.max.vm.actor.holder.*;
26 | import com.sun.max.vm.actor.member.*;
27 |
28 | /**
29 | * Instances of this class contain the execution state of a single thread in the system.
30 | * NOTE: currently there _is_ only one thread. Please ignore the man behind the curtain.
31 | *
32 | * @author Athul Acharya
33 | */
34 | class ExecutionThread {
35 |
36 | /**
37 | * The maximum frame depth for a thread.
38 | */
39 | public static final int STACK_SIZE = 1000;
40 |
41 | private ExecutionFrame frame;
42 | //private int _prio;
43 | //private ThreadType _threadType;
44 |
45 | public ExecutionThread(int prio, ThreadType threadType) {
46 | //_prio = prio;
47 | //_threadType = threadType;
48 | frame = null;
49 | }
50 |
51 | public ExecutionFrame pushFrame(ClassMethodActor method) {
52 | this.frame = new ExecutionFrame(frame, method);
53 | if (frame.depth() > STACK_SIZE) {
54 | throw new StackOverflowError();
55 | }
56 | return frame;
57 | }
58 |
59 | public ExecutionFrame popFrame() {
60 | frame = frame.callersFrame();
61 | return frame;
62 | }
63 |
64 | public ExecutionFrame frame() {
65 | return frame;
66 | }
67 |
68 | public static enum ThreadType {
69 | NORMAL_THREAD,
70 | VM_THREAD,
71 | }
72 |
73 | /**
74 | * Handles an exception at the current execution point in this thread by updating the call stack and instruction
75 | * pointer to a matching exception handler in this thread's current call stack. If no matching exception handler is
76 | * found for the current execution point and the given exception type, then the call stack and instruction pointer
77 | * in this thread are left unmodified.
78 | *
79 | * @param throwableClassActor
80 | * @return {@code true} if an exception handler was found, {@code false} otherwise
81 | */
82 | public boolean handleException(ClassActor throwableClassActor) {
83 | ExecutionFrame frame = this.frame;
84 | while (frame != null) {
85 | if (frame.handleException(throwableClassActor)) {
86 | this.frame = frame;
87 | return true;
88 | }
89 |
90 | frame = frame.callersFrame();
91 | }
92 | return false;
93 | }
94 |
95 | public void printStackTrace(PrintStream printStream, TeleInterpreterException executionException) {
96 | ExecutionFrame frame = this.frame;
97 | printStream.println(executionException.getMessage());
98 | while (frame != null) {
99 | printStream.println("\tat " + frame.method().toStackTraceElement(frame.currentOpcodePosition()));
100 | frame = frame.callersFrame();
101 | }
102 | if (executionException.getCause() != null) {
103 | printStream.print("Caused by: ");
104 | executionException.getCause().printStackTrace(printStream);
105 | }
106 | }
107 |
108 | @Override
109 | public String toString() {
110 | final StringBuilder sb = new StringBuilder(getClass().getSimpleName());
111 | ExecutionFrame frame = this.frame;
112 | while (frame != null) {
113 | sb.append(String.format("%n%s [bci:%d]", frame.method().toStackTraceElement(frame.currentOpcodePosition())));
114 | frame = frame.callersFrame();
115 | }
116 | return sb.toString();
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/tele/interpreter/Package.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.tele.interpreter;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * @author Athul Acharya
27 | */
28 | public class Package extends MaxPackage {
29 |
30 | public Package() {
31 | super();
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/tele/interpreter/TeleInterpreterException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.tele.interpreter;
22 |
23 | import java.lang.reflect.*;
24 |
25 | import com.sun.max.vm.value.*;
26 |
27 | /**
28 | * An exception thrown while executing the {@linkplain TeleInterpreter interpreter}.
29 | *
30 | * Instances of this exception type are constructed in the context of the interpreter's {@linkplain Machine machine}
31 | * state which is used to construct a stack trace of the interpreter's call stack at the time of the exception.
32 | *
33 | * @author Doug Simon
34 | */
35 | public class TeleInterpreterException extends InvocationTargetException {
36 |
37 | private final ReferenceValue throwableReference;
38 |
39 | public TeleInterpreterException(Throwable throwable, Machine machine) {
40 | super(throwable, throwable.getMessage());
41 | throwableReference = ReferenceValue.from(throwable);
42 | initStackTrace(machine);
43 | }
44 |
45 | public ReferenceValue throwableReference() {
46 | return throwableReference;
47 | }
48 |
49 | public Class throwableType() {
50 | return throwableReference.getClassActor().toJava();
51 | }
52 |
53 | private void initStackTrace(Machine machine) {
54 | ExecutionFrame frame = machine.currentThread().frame();
55 | if (frame == null) {
56 | setStackTrace(new StackTraceElement[0]);
57 | } else {
58 | int i = 0;
59 | final int depth = frame.depth();
60 | final StackTraceElement[] stackTrace = new StackTraceElement[depth];
61 | while (frame != null) {
62 | stackTrace[i++] = frame.method().toStackTraceElement(frame.currentOpcodePosition());
63 | frame = frame.callersFrame();
64 | }
65 | setStackTrace(stackTrace);
66 | }
67 | }
68 |
69 | /**
70 | * Returns the value of calling {@link #toString()} on the {@link #getCause() wrapped} exception.
71 | */
72 | @Override
73 | public String toString() {
74 | return getCause().toString();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/tele/interpreter/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | /**
22 | * An interpreter for running queries on remote objects in the tele VM.
23 | *
24 | * Derived from the JavaInJava interpreter by Antero Taivalsaari.
25 | * See Sun Labs tech report TR-98-64:
26 | * http://research.sun.com/techrep/1998/abstract-64.html
27 | *
28 | * @author Athul Acharya
29 | */
30 | package com.sun.max.tele.interpreter;
31 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/util/ArrayValueHistory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.util;
22 |
23 | import java.util.*;
24 |
25 | import com.sun.max.program.*;
26 |
27 | /**
28 | * An array-based recording of the history of a value, with
29 | * time expressed as the number of generations back from the current generation (0).
30 | *
31 | * @author Michael Van De Vanter
32 | */
33 | public class ArrayValueHistory {
34 |
35 | private final ArrayDeque generations;
36 | private final int limit;
37 | private int age = -1;
38 |
39 | public ArrayValueHistory(int limit) {
40 | this.generations = new ArrayDeque();
41 | this.limit = limit;
42 | }
43 |
44 | public ArrayValueHistory() {
45 | this (Integer.MAX_VALUE);
46 | }
47 |
48 | /**
49 | * Adds a new value, which becomes the current generation.
50 | * The generation of all previously recorded values increases by 1.
51 | */
52 | public void add(E newValue) {
53 | if (generations.size() > 0) {
54 | if (newValue.equals(generations.getFirst())) {
55 | if (age >= 0) {
56 | age++;
57 | }
58 | } else {
59 | age = 0;
60 | }
61 | }
62 | generations.addFirst(newValue);
63 | if (generations.size() > limit) {
64 | generations.removeLast();
65 | }
66 | }
67 |
68 | /**
69 | * @return the "current" value (at generation 0).
70 | * Error if no values have been recorded.
71 | */
72 | public E get() {
73 | if (generations.size() > 0) {
74 | return generations.getFirst();
75 | }
76 | ProgramError.unexpected("empty history");
77 | return null;
78 | }
79 |
80 | /**
81 | * @return The value at a specified generation.
82 | * Error if generation does not exist.
83 | */
84 | public E get(int generation) {
85 | final Iterator iterator = generations.iterator();
86 | int index = 0;
87 | while (iterator.hasNext()) {
88 | if (index == generation) {
89 | return iterator.next();
90 | }
91 | index++;
92 | }
93 | ProgramError.unexpected("exceeded history");
94 | return null;
95 | }
96 |
97 | /**
98 | * @return the age, in generations, of the current value, since recording began.
99 | * 0 if different from immediate predecessor; -1 if no different value ever recorded
100 | * Comparison uses {@linkplain Object#equals(Object) equals}.
101 | */
102 | public int getAge() {
103 | return age;
104 | }
105 |
106 | /**
107 | * @return the maximum number of generations that can be recorded.
108 | */
109 | public int getLimit() {
110 | return limit;
111 | }
112 |
113 | /**
114 | * @return the number of generations recorded; initially 0.
115 | */
116 | public int getSize() {
117 | return generations.size();
118 | }
119 |
120 | /**
121 | * @return iteration of the values recorded in the history, starting with the current
122 | * generation and proceeding backward in time.
123 | */
124 | public Iterator values() {
125 | return generations.iterator();
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/util/Deferrable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.util;
22 |
23 | import java.util.*;
24 |
25 | /**
26 | * Deferred Runnables.
27 | *
28 | * Creating a Deferrable either causes immediate execution of its 'run()' method
29 | * or queues it for deferred execution later on when 'runAll()' is called.
30 | *
31 | * @author Bernd Mathiske
32 | */
33 | public abstract class Deferrable implements Runnable {
34 |
35 | public Deferrable(Queue queue) {
36 | queue.handle(this);
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return super.toString();
42 | }
43 |
44 | public static final class Queue {
45 |
46 | private List deferrables;
47 |
48 | private Queue() {
49 | }
50 |
51 | synchronized void handle(Deferrable deferrable) {
52 | if (deferrables != null) {
53 | deferrables.add(deferrable);
54 | } else {
55 | deferrable.run();
56 | }
57 | }
58 |
59 | public synchronized void deferAll() {
60 | deferrables = new LinkedList();
61 | }
62 |
63 | public synchronized void runAll() {
64 | while (deferrables != null) {
65 | final List oldDeferrables = this.deferrables;
66 | this.deferrables = new LinkedList();
67 | for (Deferrable deferrable : oldDeferrables) {
68 | deferrable.run();
69 | }
70 | if (oldDeferrables.isEmpty()) {
71 | this.deferrables = null;
72 | }
73 | }
74 | }
75 | }
76 |
77 | public static Queue createRunning() {
78 | return new Queue();
79 | }
80 |
81 | public static Queue createDeferred() {
82 | final Queue queue = new Queue();
83 | queue.deferAll();
84 | return queue;
85 | }
86 |
87 | public abstract static class Block implements Runnable {
88 | public Block(Queue queue) {
89 | queue.deferAll();
90 | run();
91 | queue.runAll();
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/util/Enumerable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.util;
22 |
23 | /**
24 | * Java enums are insufficient in that their ordinals have to be successive.
25 | * An Enumerable has an additional arbitrary int "value",
26 | * which may incur gaps between ordinal-successive Enumerables.
27 | *
28 | * An Enumerator can be called upon to provide the respective Enumerable matching a given value.
29 | *
33 | *
34 | * @see Enumerator
35 | *
36 | * @author Bernd Mathiske
37 | */
38 | public interface Enumerable & Enumerable> extends Symbol {
39 |
40 | // We are merely declaring this method to lock in the same parameter type for the corresponding enumerator,
41 | // not for any actual use
42 | Enumerator enumerator();
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/util/Enumerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.util;
22 |
23 | import java.util.*;
24 |
25 | import com.sun.max.*;
26 |
27 | /**
28 | * @see Enumerable
29 | *
30 | * @author Bernd Mathiske
31 | */
32 | public class Enumerator & Enumerable>
33 | implements Symbolizer {
34 |
35 | private final Class type;
36 | private final E[] ordinalMap;
37 | private final E[] valueMap;
38 | private final int lowestValue;
39 |
40 | public Enumerator(Class type) {
41 | this.type = type;
42 | ordinalMap = type.getEnumConstants();
43 |
44 | int lowValue = 0;
45 | int highestValue = ordinalMap.length - 1;
46 | boolean valuesAreSameAsOrdinals = true;
47 | for (E e : ordinalMap) {
48 | final int value = e.value();
49 | if (value != e.ordinal()) {
50 | valuesAreSameAsOrdinals = false;
51 | }
52 | if (value < lowValue) {
53 | lowValue = value;
54 | } else if (value > highestValue) {
55 | highestValue = value;
56 | }
57 | }
58 |
59 | if (valuesAreSameAsOrdinals) {
60 | this.lowestValue = 0;
61 | valueMap = ordinalMap;
62 | } else {
63 | final int valueMapLength = (highestValue - lowValue) + 1;
64 | final Class arrayType = null;
65 | this.lowestValue = lowValue;
66 | valueMap = Utils.cast(arrayType, new Enum[valueMapLength]);
67 | for (E e : ordinalMap) {
68 | final int value = e.value();
69 | // The enumerable with the lowest ordinal is stored in the value map:
70 | if (valueMap[value] == null) {
71 | valueMap[value] = e;
72 | }
73 | }
74 | }
75 | }
76 |
77 | public Class type() {
78 | return type;
79 | }
80 |
81 | public int numberOfValues() {
82 | return ordinalMap.length;
83 | }
84 |
85 | /**
86 | * Adds all the enumerable constants in this enumerator to a given set.
87 | *
88 | * @param set
89 | * the set to which the enumerable constants are to be added
90 | */
91 | public void addAll(Set set) {
92 | for (E e : this) {
93 | set.add(e);
94 | }
95 | }
96 |
97 | public int size() {
98 | return ordinalMap.length;
99 | }
100 |
101 | public Iterator iterator() {
102 | return Arrays.asList(ordinalMap).iterator();
103 | }
104 |
105 | /**
106 | * Gets the enumerable constant denoted by a given ordinal. Note that this differs from {@link #fromValue(int)} in
107 | * that the latter retrieves an enumerable constant matching a given {@linkplain Enumerable#value() value}. An
108 | * enumerable's value is not necessarily the same as its ordinal.
109 | *
110 | * @throws IndexOutOfBoundsException
111 | * if {@code 0 < ordinal || ordinal >= length()}
112 | */
113 | public E get(int ordinal) throws IndexOutOfBoundsException {
114 | return ordinalMap[ordinal];
115 | }
116 |
117 | /**
118 | * Gets the enumerable constant matching a given value. That is, this method gets an enumerable from this enumerator
119 | * whose {@linkplain Enumerable#value() value} is equal to {@code value}. Note that the given value may not match
120 | * any enumerable in this enumerator in which case null is returned. Additionally, there may be more than one
121 | * enumerable with a matching value in which case the matching enumerable with the lowest
122 | * {@linkplain Enum#ordinal() ordinal} is returned.
123 | */
124 | public E fromValue(int value) {
125 | final int index = value - lowestValue;
126 | if (index >= 0 && index < valueMap.length) {
127 | return valueMap[index];
128 | }
129 | return null;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/util/ListSymbolizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.util;
22 |
23 | import java.util.*;
24 |
25 | import com.sun.max.program.*;
26 |
27 | /**
28 | * @author Bernd Mathiske
29 | */
30 | final class ListSymbolizer implements Symbolizer {
31 |
32 | private final Class symbolType;
33 | private final List symbols;
34 |
35 | ListSymbolizer(Class symbolType, List symbols) {
36 | if (symbolType.getName().startsWith("com.sun.max.asm") && Symbolizer.Static.hasPackageExternalAccessibleConstructors(symbolType)) {
37 | // This test ensures that values passed for symbolic parameters of methods in the
38 | // generated assemblers are guaranteed to be legal (assuming client code does not
39 | // inject its own classes into the package where the symbol classes are defined).
40 | ProgramError.unexpected("type of assembler symbol can have values constructed outside of defining package: " + symbolType);
41 | }
42 | this.symbolType = symbolType;
43 | this.symbols = symbols;
44 | ProgramError.check(!symbols.isEmpty());
45 | }
46 |
47 | public Class type() {
48 | return symbolType;
49 | }
50 |
51 | public int numberOfValues() {
52 | return symbols.size();
53 | }
54 |
55 | public S fromValue(int value) {
56 | for (S symbol : symbols) {
57 | if (symbol.value() == value) {
58 | return symbol;
59 | }
60 | }
61 | return null;
62 | }
63 |
64 | public Iterator iterator() {
65 | return symbols.iterator();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/util/Package.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.util;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * @see MaxPackage
27 | *
28 | * @author Bernd Mathiske
29 | */
30 | public class Package extends BasePackage {
31 | public Package() {
32 | super();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/JavaInJava/src/com/sun/max/util/Predicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
3 | *
4 | * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
5 | * that is described in this document. In particular, and without limitation, these intellectual property
6 | * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
7 | * more additional patents or pending patent applications in the U.S. and in other countries.
8 | *
9 | * U.S. Government Rights - Commercial software. Government users are subject to the Sun
10 | * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
11 | * supplements.
12 | *
13 | * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
14 | * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
15 | * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
16 | * U.S. and other countries.
17 | *
18 | * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
19 | * Company, Ltd.
20 | */
21 | package com.sun.max.util;
22 |
23 | import com.sun.max.*;
24 |
25 | /**
26 | * @author Bernd Mathiske
27 | */
28 | public interface Predicate {
29 |
30 | boolean evaluate(T object);
31 |
32 | public static final class Static {
33 | private Static() {
34 | }
35 |
36 | private static Predicate