Skip to content

Commit 55afaad

Browse files
author
hborders
committed
Added package com.sun.max.unsafe from Maxine VM.
1 parent 7517f77 commit 55afaad

22 files changed

Lines changed: 5379 additions & 0 deletions

‎JavaInJava/src/com/sun/max/unsafe/Accessor.java‎

Lines changed: 534 additions & 0 deletions
Large diffs are not rendered by default.

‎JavaInJava/src/com/sun/max/unsafe/Address.java‎

Lines changed: 493 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.unsafe;
22+
23+
import com.sun.max.annotate.*;
24+
import com.sun.max.vm.*;
25+
26+
/**
27+
* Interface implemented by boxed versions of {@link Word} types.
28+
* These boxed implementations are used when executing in {@linkplain MaxineVM#isHosted() hosted} mode.
29+
*
30+
* A boxed type must be in the same package as its corresponding unboxed type and
31+
* its name must be composed by added the prefix "Boxed" to the name of the unboxed type.
32+
* This invariant enables the complete set of boxed types to be derived from the known
33+
* set of unboxed types.
34+
*
35+
* @author Bernd Mathiske
36+
* @author Doug Simon
37+
*/
38+
@HOSTED_ONLY
39+
public interface Boxed {
40+
41+
/**
42+
* Gets the boxed value as a {@code long}.
43+
*/
44+
long value();
45+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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.unsafe;
22+
23+
import java.math.*;
24+
25+
import com.sun.max.annotate.*;
26+
27+
/**
28+
* Boxed version of Address.
29+
*
30+
* @see Address
31+
*
32+
* @author Bernd Mathiske
33+
*/
34+
@HOSTED_ONLY
35+
public final class BoxedAddress extends Address implements Boxed {
36+
37+
private long nativeWord;
38+
39+
public static final BoxedAddress ZERO = new BoxedAddress(0);
40+
public static final BoxedAddress MAX = new BoxedAddress(-1L);
41+
42+
private static final class Cache {
43+
private Cache() {
44+
}
45+
46+
static final int HIGHEST_VALUE = 1000;
47+
48+
static final BoxedAddress[] cache = new BoxedAddress[HIGHEST_VALUE + 1];
49+
50+
static {
51+
for (int i = 0; i < cache.length; i++) {
52+
cache[i] = new BoxedAddress(i);
53+
}
54+
}
55+
}
56+
57+
public static BoxedAddress from(long value) {
58+
if (value == 0) {
59+
return ZERO;
60+
}
61+
if (value >= 0 && value <= Cache.HIGHEST_VALUE) {
62+
return Cache.cache[(int) value];
63+
}
64+
if (value == -1L) {
65+
return MAX;
66+
}
67+
return new BoxedAddress(value);
68+
}
69+
70+
public static BoxedAddress from(int value) {
71+
return from(value & BoxedWord.INT_MASK);
72+
}
73+
74+
private BoxedAddress(long value) {
75+
if (Word.width() == 64) {
76+
nativeWord = value;
77+
} else {
78+
nativeWord = value & BoxedWord.INT_MASK;
79+
}
80+
}
81+
82+
public long value() {
83+
return nativeWord;
84+
}
85+
86+
private static BigInteger bi(long unsigned) {
87+
if (unsigned < 0) {
88+
long signBit = 0x8000000000000000L;
89+
long low63Bits = unsigned & ~signBit;
90+
return BigInteger.valueOf(low63Bits).setBit(63);
91+
}
92+
return BigInteger.valueOf(unsigned);
93+
}
94+
95+
96+
private static long unsignedDivide(long dividend, long divisor) {
97+
if (dividend >= 0 && divisor >= 0) {
98+
return dividend / divisor;
99+
}
100+
return bi(dividend).divide(bi(divisor)).longValue();
101+
}
102+
103+
@Override
104+
public Address dividedByAddress(Address divisor) {
105+
final BoxedAddress box = (BoxedAddress) divisor.asAddress();
106+
if (box.nativeWord == 0L) {
107+
throw new ArithmeticException();
108+
}
109+
return new BoxedAddress(unsignedDivide(nativeWord, box.nativeWord));
110+
}
111+
112+
@Override
113+
public Address dividedByInt(int divisor) {
114+
if (divisor == 0) {
115+
throw new ArithmeticException();
116+
}
117+
return new BoxedAddress(unsignedDivide(nativeWord, divisor & BoxedWord.INT_MASK));
118+
}
119+
120+
private static long unsignedRemainder(long dividend, long divisor) {
121+
if (dividend >= 0 && divisor >= 0) {
122+
return dividend % divisor;
123+
}
124+
return bi(dividend).remainder(bi(divisor)).longValue();
125+
}
126+
127+
@Override
128+
public Address remainderByAddress(Address divisor) {
129+
final BoxedAddress box = (BoxedAddress) divisor.asAddress();
130+
if (box.nativeWord == 0L) {
131+
throw new ArithmeticException();
132+
}
133+
return new BoxedAddress(unsignedRemainder(nativeWord, box.nativeWord));
134+
}
135+
136+
@Override
137+
public int remainderByInt(int divisor) {
138+
if (divisor == 0) {
139+
throw new ArithmeticException();
140+
}
141+
return (int) unsignedRemainder(nativeWord, divisor & BoxedWord.INT_MASK);
142+
}
143+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.unsafe;
22+
23+
import com.sun.max.annotate.*;
24+
25+
/**
26+
* Boxed version of Offset.
27+
*
28+
* @author Bernd Mathiske
29+
*/
30+
@HOSTED_ONLY
31+
public final class BoxedOffset extends Offset implements Boxed {
32+
33+
private long nativeWord;
34+
35+
public static final BoxedOffset ZERO = new BoxedOffset(0);
36+
37+
private static final class Cache {
38+
private Cache() {
39+
}
40+
41+
static final int LOWEST_VALUE = -100;
42+
static final int HIGHEST_VALUE = 1000;
43+
44+
static final BoxedOffset[] cache = new BoxedOffset[(HIGHEST_VALUE - LOWEST_VALUE) + 1];
45+
46+
static {
47+
for (int i = 0; i < cache.length; i++) {
48+
cache[i] = new BoxedOffset(i + LOWEST_VALUE);
49+
}
50+
}
51+
}
52+
53+
public static BoxedOffset from(long value) {
54+
if (value == 0) {
55+
return ZERO;
56+
}
57+
if (value >= Cache.LOWEST_VALUE && value <= Cache.HIGHEST_VALUE) {
58+
return Cache.cache[(int) value - Cache.LOWEST_VALUE];
59+
}
60+
return new BoxedOffset(value);
61+
}
62+
63+
private BoxedOffset(long value) {
64+
nativeWord = value;
65+
}
66+
67+
public long value() {
68+
return nativeWord;
69+
}
70+
}

0 commit comments

Comments
 (0)