Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a121539

Browse filesBrowse files
author
hborders
committed
Added com.sun.max.lang package from Maxine VM.
1 parent 5fc9d80 commit a121539
Copy full SHA for a121539

3 files changed

+283Lines changed: 283 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+111Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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.io.*;
24+
25+
import com.sun.max.program.*;
26+
import com.sun.max.unsafe.*;
27+
import com.sun.max.vm.compiler.builtin.*;
28+
import com.sun.max.vm.value.*;
29+
30+
public class DataModel {
31+
32+
public final WordWidth wordWidth;
33+
public final Endianness endianness;
34+
public final int cacheAlignment;
35+
36+
public DataModel(WordWidth wordWidth, Endianness endianness, int cacheAlignment) {
37+
this.wordWidth = wordWidth;
38+
this.endianness = endianness;
39+
this.cacheAlignment = cacheAlignment;
40+
}
41+
42+
@Override
43+
public boolean equals(Object other) {
44+
if (!(other instanceof DataModel)) {
45+
return false;
46+
}
47+
final DataModel dataModel = (DataModel) other;
48+
return wordWidth.equals(dataModel.wordWidth) && endianness.equals(dataModel.endianness) && cacheAlignment == dataModel.cacheAlignment;
49+
}
50+
51+
public byte[] toBytes(byte value) {
52+
return endianness.toBytes(value);
53+
}
54+
55+
public byte[] toBytes(boolean value) {
56+
final byte[] result = new byte[1];
57+
result[0] = value ? (byte) 1 : (byte) 0;
58+
return result;
59+
}
60+
61+
public byte[] toBytes(short value) {
62+
return endianness.toBytes(value);
63+
}
64+
65+
public byte[] toBytes(char value) {
66+
final short shortValue = UnsafeCast.asShort(value);
67+
return endianness.toBytes(shortValue);
68+
}
69+
70+
public byte[] toBytes(int value) {
71+
return endianness.toBytes(value);
72+
}
73+
74+
public byte[] toBytes(float value) {
75+
final int intValue = SpecialBuiltin.floatToInt(value);
76+
return endianness.toBytes(intValue);
77+
}
78+
79+
public byte[] toBytes(long value) {
80+
return endianness.toBytes(value);
81+
}
82+
83+
public byte[] toBytes(double value) {
84+
final long longValue = SpecialBuiltin.doubleToLong(value);
85+
return endianness.toBytes(longValue);
86+
}
87+
88+
public byte[] toBytes(Word value) {
89+
switch (wordWidth) {
90+
case BITS_64:
91+
return toBytes(value.asOffset().toLong());
92+
case BITS_32:
93+
return toBytes((int) value.asOffset().toLong());
94+
case BITS_16:
95+
return toBytes((short) value.asOffset().toLong());
96+
case BITS_8:
97+
return toBytes((byte) value.asOffset().toLong());
98+
}
99+
ProgramError.unknownCase();
100+
return null;
101+
}
102+
103+
public void write(OutputStream stream, Value value) throws IOException {
104+
stream.write(value.toBytes(this));
105+
}
106+
107+
@Override
108+
public String toString() {
109+
return wordWidth + "-bit, " + endianness + " endian, " + cacheAlignment + "-byte aligned cache";
110+
}
111+
}
Collapse file
+99Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 static com.sun.max.unsafe.WithoutAccessCheck.*;
24+
25+
import java.lang.reflect.*;
26+
27+
import com.sun.max.*;
28+
import com.sun.max.program.*;
29+
30+
/**
31+
* Basic generic utilities for objects.
32+
*
33+
* @author Bernd Mathiske
34+
* @author Doug Simon
35+
*/
36+
public final class Objects {
37+
38+
private Objects() {
39+
}
40+
41+
/**
42+
* Compares two given objects for equality using {@link Object#equals(Object)}.
43+
*
44+
* @return true if both {@code o1} and {@code o2} are {@code null} || {@code o1.equals(o2)}
45+
*/
46+
public static boolean equal(Object o1, Object o2) {
47+
return o1 == null ? o2 == null : o1.equals(o2);
48+
}
49+
50+
/**
51+
* Copies the values of the instance fields in one object to another object.
52+
*
53+
* @param fromObject the object from which the field values are to be copied
54+
* @param toObject the object to which the field values are to be copied
55+
*/
56+
public static void copy(Object fromObject, Object toObject) {
57+
assert fromObject.getClass() == toObject.getClass();
58+
Class c = fromObject.getClass();
59+
while (c != null) {
60+
for (Field field : c.getDeclaredFields()) {
61+
if ((field.getModifiers() & Modifier.STATIC) == 0) {
62+
field.setAccessible(true);
63+
try {
64+
final Object value = field.get(fromObject);
65+
field.set(toObject, value);
66+
} catch (IllegalArgumentException illegalArgumentException) {
67+
// This should never occur
68+
throw ProgramError.unexpected(illegalArgumentException);
69+
} catch (IllegalAccessException illegalAccessException) {
70+
// This should never occur
71+
throw ProgramError.unexpected(illegalAccessException);
72+
}
73+
}
74+
}
75+
c = c.getSuperclass();
76+
}
77+
}
78+
79+
/**
80+
* Creates a new instance of a given class without calling any constructors. This call also ensures that {@code javaClass}
81+
* has been initialized.
82+
*
83+
* @param javaClass the class to construct an instance of
84+
* @return an uninitialized of {@code javaClass}
85+
* @throws InstantiationException if the instantiation fails for any of the reasons described
86+
* {@linkplain InstantiationException here}
87+
*/
88+
public static Object allocateInstance(Class<?> javaClass) throws InstantiationException {
89+
unsafe.ensureClassInitialized(javaClass);
90+
return unsafe.allocateInstance(javaClass);
91+
}
92+
93+
public static <T> T allocateObject(Class<T> javaClass) throws InstantiationException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
94+
final Constructor constructor = javaClass.getDeclaredConstructor();
95+
constructor.setAccessible(true);
96+
final Object object = constructor.newInstance();
97+
return Utils.cast(javaClass, object);
98+
}
99+
}
Collapse file
+73Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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.annotate.*;
24+
import com.sun.max.unsafe.*;
25+
26+
/**
27+
* A collection of static methods for doing unsigned arithmetic on Java primitive types
28+
* where the semantics of the arithmetics operations differ from the signed version.
29+
* In addition to providing unsigned arithmetic semantics for the programmer,
30+
* these methods also expose different optimization possibilities to the compiler as
31+
* well as allowing for them to be implemented as compiler builtins.
32+
*
33+
* @author Doug Simon
34+
*/
35+
public class Unsigned {
36+
37+
/**
38+
* Performs unsigned integer division.
39+
*/
40+
@INLINE
41+
@UNSAFE
42+
public static int idiv(int dividend, int divisor) {
43+
return Address.fromUnsignedInt(dividend).dividedBy(divisor).toInt();
44+
}
45+
46+
/**
47+
* Performs unsigned long division.
48+
*/
49+
@INLINE
50+
@UNSAFE
51+
public static long ldiv(long dividend, long divisor) {
52+
return Address.fromLong(dividend).dividedBy(Address.fromLong(divisor)).toLong();
53+
}
54+
55+
/**
56+
* Performs unsigned integer modulus.
57+
*/
58+
@INLINE
59+
@UNSAFE
60+
public static int irem(int dividend, int divisor) {
61+
return Address.fromUnsignedInt(dividend).remainder(divisor);
62+
}
63+
64+
/**
65+
* Performs unsigned long modulus.
66+
*/
67+
@INLINE
68+
@UNSAFE
69+
public static long lrem(long dividend, long divisor) {
70+
return Address.fromLong(dividend).remainder(Address.fromLong(divisor)).toLong();
71+
}
72+
73+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.