diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f838cb3..0000000 --- a/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -target -.idea -out -classes -gh-pages -*.iml -.classpath -.project -.settings diff --git a/JavaDoc/allclasses-frame.html b/JavaDoc/allclasses-frame.html new file mode 100644 index 0000000..cda163b --- /dev/null +++ b/JavaDoc/allclasses-frame.html @@ -0,0 +1,39 @@ + + + + + +All Classes + + + + + +

All Classes

+
+ +
+ + diff --git a/JavaDoc/allclasses-noframe.html b/JavaDoc/allclasses-noframe.html new file mode 100644 index 0000000..06c50d2 --- /dev/null +++ b/JavaDoc/allclasses-noframe.html @@ -0,0 +1,39 @@ + + + + + +All Classes + + + + + +

All Classes

+
+ +
+ + diff --git a/JavaDoc/bench/ObjectLayoutBench.BasicArray.html b/JavaDoc/bench/ObjectLayoutBench.BasicArray.html new file mode 100644 index 0000000..0ca686e --- /dev/null +++ b/JavaDoc/bench/ObjectLayoutBench.BasicArray.html @@ -0,0 +1,300 @@ + + + + + +ObjectLayoutBench.BasicArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
bench
+

Class ObjectLayoutBench.BasicArray

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/bench/ObjectLayoutBench.Element.html b/JavaDoc/bench/ObjectLayoutBench.Element.html new file mode 100644 index 0000000..b578979 --- /dev/null +++ b/JavaDoc/bench/ObjectLayoutBench.Element.html @@ -0,0 +1,265 @@ + + + + + +ObjectLayoutBench.Element + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
bench
+

Class ObjectLayoutBench.Element

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/bench/ObjectLayoutBench.ElementBase.html b/JavaDoc/bench/ObjectLayoutBench.ElementBase.html new file mode 100644 index 0000000..26f7818 --- /dev/null +++ b/JavaDoc/bench/ObjectLayoutBench.ElementBase.html @@ -0,0 +1,330 @@ + + + + + +ObjectLayoutBench.ElementBase + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
bench
+

Class ObjectLayoutBench.ElementBase

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/bench/ObjectLayoutBench.GenericArray.html b/JavaDoc/bench/ObjectLayoutBench.GenericArray.html new file mode 100644 index 0000000..98fbbd4 --- /dev/null +++ b/JavaDoc/bench/ObjectLayoutBench.GenericArray.html @@ -0,0 +1,302 @@ + + + + + +ObjectLayoutBench.GenericArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
bench
+

Class ObjectLayoutBench.GenericArray<E>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/bench/ObjectLayoutBench.RandomizedBasicArray.html b/JavaDoc/bench/ObjectLayoutBench.RandomizedBasicArray.html new file mode 100644 index 0000000..f51d6d2 --- /dev/null +++ b/JavaDoc/bench/ObjectLayoutBench.RandomizedBasicArray.html @@ -0,0 +1,288 @@ + + + + + +ObjectLayoutBench.RandomizedBasicArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
bench
+

Class ObjectLayoutBench.RandomizedBasicArray

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/bench/ObjectLayoutBench.html b/JavaDoc/bench/ObjectLayoutBench.html new file mode 100644 index 0000000..b806fc8 --- /dev/null +++ b/JavaDoc/bench/ObjectLayoutBench.html @@ -0,0 +1,514 @@ + + + + + +ObjectLayoutBench + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
bench
+

Class ObjectLayoutBench

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/bench/SAHashMapBench.Element.html b/JavaDoc/bench/SAHashMapBench.Element.html new file mode 100644 index 0000000..1d9e389 --- /dev/null +++ b/JavaDoc/bench/SAHashMapBench.Element.html @@ -0,0 +1,277 @@ + + + + + +SAHashMapBench.Element + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
bench
+

Class SAHashMapBench.Element

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/bench/SAHashMapBench.ElementBase.html b/JavaDoc/bench/SAHashMapBench.ElementBase.html new file mode 100644 index 0000000..3f798ed --- /dev/null +++ b/JavaDoc/bench/SAHashMapBench.ElementBase.html @@ -0,0 +1,408 @@ + + + + + +SAHashMapBench.ElementBase + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
bench
+

Class SAHashMapBench.ElementBase

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/bench/SAHashMapBench.html b/JavaDoc/bench/SAHashMapBench.html new file mode 100644 index 0000000..a9ba226 --- /dev/null +++ b/JavaDoc/bench/SAHashMapBench.html @@ -0,0 +1,489 @@ + + + + + +SAHashMapBench + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
bench
+

Class SAHashMapBench

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/bench/package-frame.html b/JavaDoc/bench/package-frame.html new file mode 100644 index 0000000..a1039b5 --- /dev/null +++ b/JavaDoc/bench/package-frame.html @@ -0,0 +1,28 @@ + + + + + +bench + + + + + +

bench

+
+

Classes

+ +
+ + diff --git a/JavaDoc/bench/package-summary.html b/JavaDoc/bench/package-summary.html new file mode 100644 index 0000000..5a6cb84 --- /dev/null +++ b/JavaDoc/bench/package-summary.html @@ -0,0 +1,172 @@ + + + + + +bench + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Package bench

+
+
+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/bench/package-tree.html b/JavaDoc/bench/package-tree.html new file mode 100644 index 0000000..a700f4f --- /dev/null +++ b/JavaDoc/bench/package-tree.html @@ -0,0 +1,149 @@ + + + + + +bench Class Hierarchy + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Hierarchy For Package bench

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/constant-values.html b/JavaDoc/constant-values.html new file mode 100644 index 0000000..ac30d91 --- /dev/null +++ b/JavaDoc/constant-values.html @@ -0,0 +1,149 @@ + + + + + +Constant Field Values + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Constant Field Values

+

Contents

+ +
+
+ + +

org.ObjectLayout.*

+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/deprecated-list.html b/JavaDoc/deprecated-list.html new file mode 100644 index 0000000..0718318 --- /dev/null +++ b/JavaDoc/deprecated-list.html @@ -0,0 +1,120 @@ + + + + + +Deprecated List + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Deprecated API

+

Contents

+
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/help-doc.html b/JavaDoc/help-doc.html new file mode 100644 index 0000000..fa3684c --- /dev/null +++ b/JavaDoc/help-doc.html @@ -0,0 +1,217 @@ + + + + + +API Help + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

How This API Document Is Organized

+
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
+
+
+ +This help file applies to API documentation generated using the standard doclet.
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-1.html b/JavaDoc/index-files/index-1.html new file mode 100644 index 0000000..3a51990 --- /dev/null +++ b/JavaDoc/index-files/index-1.html @@ -0,0 +1,175 @@ + + + + + +A-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

A

+
+
AbstractPrimitiveArray - Class in org.ObjectLayout
+
+
A abstract base class for subclassable primitive and reference arrays.
+
+
arrayCtorAndArgs(CtorAndArgs<S>) - Method in class org.ObjectLayout.PrimitiveArrayBuilder
+
+
Set the CtorAndArgs to be used in constructing arrays.
+
+
arrayCtorAndArgs(Constructor<S>, Object...) - Method in class org.ObjectLayout.PrimitiveArrayBuilder
+
+
Set the Constructor and construction arguments to be used in constructing arrays.
+
+
arrayCtorAndArgs(CtorAndArgs<S>) - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Set the CtorAndArgs to be used in constructing arrays.
+
+
arrayCtorAndArgs(Constructor<S>, Object...) - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Set the Constructor and construction arguments to be used in constructing arrays.
+
+
asArray() - Method in class org.ObjectLayout.PrimitiveByteArray
+
+
Get a reference to a byte[] that represents the contents of this array.
+
+
asArray() - Method in class org.ObjectLayout.PrimitiveCharArray
+
+
Get a reference to a char[] that represents the contents of this array.
+
+
asArray() - Method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Get a reference to a double[] that represents the contents of this array.
+
+
asArray() - Method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Get a reference to a float[] that represents the contents of this array.
+
+
asArray() - Method in class org.ObjectLayout.PrimitiveIntArray
+
+
Get a reference to a int[] that represents the contents of this array.
+
+
asArray() - Method in class org.ObjectLayout.PrimitiveLongArray
+
+
Get a reference to a long[] that represents the contents of this array.
+
+
asArray() - Method in class org.ObjectLayout.PrimitiveShortArray
+
+
Get a reference to a short[] that represents the contents of this array.
+
+
asArray() - Method in class org.ObjectLayout.ReferenceArray
+
+
Get a reference to a T[] that represents the contents of this array.
+
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-10.html b/JavaDoc/index-files/index-10.html new file mode 100644 index 0000000..89d44e0 --- /dev/null +++ b/JavaDoc/index-files/index-10.html @@ -0,0 +1,226 @@ + + + + + +P-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

P

+
+
PrimitiveArrayBuilder<S extends AbstractPrimitiveArray> - Class in org.ObjectLayout
+
+
A builder used for instantiating a AbstractPrimitiveArray<T>
+
+
PrimitiveArrayBuilder(Class<S>, long) - Constructor for class org.ObjectLayout.PrimitiveArrayBuilder
+
+
Constructs a new PrimitiveArrayBuilder object for creating arrays of + type S with the given length.
+
+
PrimitiveArrayModel<S extends AbstractPrimitiveArray> - Class in org.ObjectLayout
+
+
A model that describes the structure of a PrimitiveArray
+
+
PrimitiveArrayModel(Class<S>, long) - Constructor for class org.ObjectLayout.PrimitiveArrayModel
+
+
Create a model of a PrimitiveArray instance
+
+
PrimitiveByteArray - Class in org.ObjectLayout
+
+
A subclassable array of bytes.
+
+
PrimitiveByteArray() - Constructor for class org.ObjectLayout.PrimitiveByteArray
+
+
Default constructor
+
+
PrimitiveByteArray(PrimitiveByteArray) - Constructor for class org.ObjectLayout.PrimitiveByteArray
+
+
Copying constructor
+
+
PrimitiveCharArray - Class in org.ObjectLayout
+
+
A subclassable array of chars.
+
+
PrimitiveCharArray() - Constructor for class org.ObjectLayout.PrimitiveCharArray
+
+
Default constructor
+
+
PrimitiveCharArray(PrimitiveCharArray) - Constructor for class org.ObjectLayout.PrimitiveCharArray
+
+
Copying constructor
+
+
PrimitiveDoubleArray - Class in org.ObjectLayout
+
+
A subclassable array of doubles.
+
+
PrimitiveDoubleArray() - Constructor for class org.ObjectLayout.PrimitiveDoubleArray
+
+
Default constructor
+
+
PrimitiveDoubleArray(PrimitiveDoubleArray) - Constructor for class org.ObjectLayout.PrimitiveDoubleArray
+
+
Copying constructor
+
+
PrimitiveFloatArray - Class in org.ObjectLayout
+
+
A subclassable array of floats.
+
+
PrimitiveFloatArray() - Constructor for class org.ObjectLayout.PrimitiveFloatArray
+
+
Default constructor
+
+
PrimitiveFloatArray(PrimitiveFloatArray) - Constructor for class org.ObjectLayout.PrimitiveFloatArray
+
+
Copying constructor
+
+
PrimitiveIntArray - Class in org.ObjectLayout
+
+
A subclassable array of ints.
+
+
PrimitiveIntArray() - Constructor for class org.ObjectLayout.PrimitiveIntArray
+
+
Default constructor
+
+
PrimitiveIntArray(PrimitiveIntArray) - Constructor for class org.ObjectLayout.PrimitiveIntArray
+
+
Copying constructor
+
+
PrimitiveLongArray - Class in org.ObjectLayout
+
+
A subclassable array of longs.
+
+
PrimitiveLongArray() - Constructor for class org.ObjectLayout.PrimitiveLongArray
+
+
Default constructor
+
+
PrimitiveLongArray(PrimitiveLongArray) - Constructor for class org.ObjectLayout.PrimitiveLongArray
+
+
Copying constructor
+
+
PrimitiveShortArray - Class in org.ObjectLayout
+
+
A subclassable array of shorts.
+
+
PrimitiveShortArray() - Constructor for class org.ObjectLayout.PrimitiveShortArray
+
+
Default constructor
+
+
PrimitiveShortArray(PrimitiveShortArray) - Constructor for class org.ObjectLayout.PrimitiveShortArray
+
+
Copying constructor
+
+
process(Set<? extends TypeElement>, RoundEnvironment) - Method in class org.ObjectLayout.IntrinsicProcessor
+
 
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-11.html b/JavaDoc/index-files/index-11.html new file mode 100644 index 0000000..e83b1d8 --- /dev/null +++ b/JavaDoc/index-files/index-11.html @@ -0,0 +1,151 @@ + + + + + +R-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

R

+
+
ReferenceArray<T> - Class in org.ObjectLayout
+
+
A subclassable array of object references.
+
+
ReferenceArray() - Constructor for class org.ObjectLayout.ReferenceArray
+
+
Default constructor
+
+
ReferenceArray(ReferenceArray<T>) - Constructor for class org.ObjectLayout.ReferenceArray
+
+
Copy constructor
+
+
remove() - Method in class org.ObjectLayout.StructuredArray.ElementIterator
+
+
Remove operation is not supported on StructuredArrays.
+
+
reset() - Method in class org.ObjectLayout.StructuredArray.ElementIterator
+
+
Reset to the beginning of the collection enabling reuse of the iterator.
+
+
resolve() - Method in class org.ObjectLayout.PrimitiveArrayBuilder
+
+
Resolve any not-yet-resolved constructor information needed by this builder.
+
+
resolve() - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Resolve any not-yet-resolved constructor information needed by this builder.
+
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-12.html b/JavaDoc/index-files/index-12.html new file mode 100644 index 0000000..ea58ee2 --- /dev/null +++ b/JavaDoc/index-files/index-12.html @@ -0,0 +1,278 @@ + + + + + +S-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

S

+
+
set(int, byte) - Method in class org.ObjectLayout.PrimitiveByteArray
+
+
set the value of an element in the array.
+
+
set(long, byte) - Method in class org.ObjectLayout.PrimitiveByteArray
+
+
set the value of an element in the array.
+
+
set(int, char) - Method in class org.ObjectLayout.PrimitiveCharArray
+
+
set the value of an element in the array.
+
+
set(long, char) - Method in class org.ObjectLayout.PrimitiveCharArray
+
+
set the value of an element in the array.
+
+
set(int, double) - Method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
set the value of an element in the array.
+
+
set(long, double) - Method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
set the value of an element in the array.
+
+
set(int, float) - Method in class org.ObjectLayout.PrimitiveFloatArray
+
+
set the value of an element in the array.
+
+
set(long, float) - Method in class org.ObjectLayout.PrimitiveFloatArray
+
+
set the value of an element in the array.
+
+
set(int, int) - Method in class org.ObjectLayout.PrimitiveIntArray
+
+
set the value of an element in the array.
+
+
set(long, int) - Method in class org.ObjectLayout.PrimitiveIntArray
+
+
set the value of an element in the array.
+
+
set(int, long) - Method in class org.ObjectLayout.PrimitiveLongArray
+
+
set the value of an element in the array.
+
+
set(long, long) - Method in class org.ObjectLayout.PrimitiveLongArray
+
+
set the value of an element in the array.
+
+
set(int, short) - Method in class org.ObjectLayout.PrimitiveShortArray
+
+
set the value of an element in the array.
+
+
set(long, short) - Method in class org.ObjectLayout.PrimitiveShortArray
+
+
set the value of an element in the array.
+
+
set(int, T) - Method in class org.ObjectLayout.ReferenceArray
+
+
set the value of an element in the array.
+
+
set(long, T) - Method in class org.ObjectLayout.ReferenceArray
+
+
set the value of an element in the array.
+
+
setArgs(Object...) - Method in class org.ObjectLayout.CtorAndArgs
+
+
Set the constructor arguments to be indicated in this CtorAndArgs.
+
+
setConstructor(Constructor<T>) - Method in class org.ObjectLayout.CtorAndArgs
+
+
Set the constructor to be indicated in this CtorAndArgs.
+
+
setContextCookie(Object) - Method in class org.ObjectLayout.CtorAndArgs
+
+
Set the value of the opaque contextCookie object
+
+
shallowCopy(S, long, S, long, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Shallow copy a region of element object contents from one array to the other.
+
+
shallowCopy(S, long, S, long, long, boolean) - Static method in class org.ObjectLayout.StructuredArray
+
+
Shallow copy a region of element object contents from one array to the other.
+
+
StructuredArray<T> - Class in org.ObjectLayout
+
+
An array of non-replaceable objects.
+
+
StructuredArray.ElementIterator - Class in org.ObjectLayout
+
+
Specialised Iterator with the ability to be StructuredArray.ElementIterator.reset() enabling reuse.
+
+
StructuredArrayBuilder<S extends StructuredArray<T>,T> - Class in org.ObjectLayout
+
+
A builder used for instantiating a StructuredArray<T>
+
+
StructuredArrayBuilder(Class<S>, Class<T>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating arrays of type S with + elements of type T, and the given length.
+
+
StructuredArrayBuilder(MethodHandles.Lookup, Class<S>, Class<T>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating arrays of type S with + elements of type T, and the given length.
+
+
StructuredArrayBuilder(StructuredArrayModel<S, T>) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating arrays of the given array model.
+
+
StructuredArrayBuilder(MethodHandles.Lookup, StructuredArrayModel<S, T>) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating arrays of the given array model.
+
+
StructuredArrayBuilder(Class<S>, StructuredArrayBuilder<A, E>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating an array of type S with + elements of type T, and the given length.
+
+
StructuredArrayBuilder(MethodHandles.Lookup, Class<S>, StructuredArrayBuilder<A, E>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating an array of type S with + elements of type T, and the given length.
+
+
StructuredArrayBuilder(Class<S>, PrimitiveArrayBuilder<A>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating an array of type S with + elements of type T, and the given length.
+
+
StructuredArrayBuilder(MethodHandles.Lookup, Class<S>, PrimitiveArrayBuilder<A>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating an array of type S with + elements of type T, and the given length.
+
+
StructuredArrayModel<S extends StructuredArray<T>,T> - Class in org.ObjectLayout
+
+
A model that describes the structure of a StructuredArray
+
+
StructuredArrayModel(long) - Constructor for class org.ObjectLayout.StructuredArrayModel
+
+
Create a model of a StructuredArray instance with terminal (non StructuredArray) elements, + deriving the array class and element class from the generic class parameters
+
+
StructuredArrayModel(Class<S>, Class<T>, long) - Constructor for class org.ObjectLayout.StructuredArrayModel
+
+
Create a model of a StructuredArray instance with terminal (non StructuredArray) elements
+
+
StructuredArrayModel(Class<S>, StructuredArrayModel<A2, T2>, long) - Constructor for class org.ObjectLayout.StructuredArrayModel
+
+
Create a model of a StructuredArray instance with elements that are themselves StructuredArrays
+
+
StructuredArrayModel(Class<S>, PrimitiveArrayModel<A2>, long) - Constructor for class org.ObjectLayout.StructuredArrayModel
+
+
Create a model of a StructuredArray instance with elements that are themselves subclassable PrimitiveArrays
+
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-13.html b/JavaDoc/index-files/index-13.html new file mode 100644 index 0000000..818eb88 --- /dev/null +++ b/JavaDoc/index-files/index-13.html @@ -0,0 +1,170 @@ + + + + + +O-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E F G H I K L M N O P R S T U V  + + +

O

+
+
ObjectLayoutBench - Class in bench
+
 
+
ObjectLayoutBench() - Constructor for class bench.ObjectLayoutBench
+
 
+
ObjectLayoutBench.BasicArray - Class in bench
+
 
+
ObjectLayoutBench.Element - Class in bench
+
 
+
ObjectLayoutBench.ElementBase - Class in bench
+
 
+
ObjectLayoutBench.GenericArray<E> - Class in bench
+
 
+
ObjectLayoutBench.RandomizedBasicArray - Class in bench
+
 
+
Octagon - Class in org.ObjectLayout.examples
+
+
A simple org.ObjectLayout.examples.Octagon class example with an intrinsic StructuredArray of Points.
+
+
Octagon() - Constructor for class org.ObjectLayout.examples.Octagon
+
 
+
Octagon(String) - Constructor for class org.ObjectLayout.examples.Octagon
+
 
+
Octagon(Octagon) - Constructor for class org.ObjectLayout.examples.Octagon
+
 
+
Octagon(String, long, long, long) - Constructor for class org.ObjectLayout.examples.Octagon
+
+
Build an perfect octagon with center at (centerX, centerY), and first point + at (centerX + radius, centerY)
+
+
Octagons - Class in org.ObjectLayout.examples
+
 
+
Octagons() - Constructor for class org.ObjectLayout.examples.Octagons
+
 
+
Octagons(Octagons) - Constructor for class org.ObjectLayout.examples.Octagons
+
 
+
orderType(SimpleOrder.OrderType) - Method in class org.ObjectLayout.examples.MassOrder.Builder
+
 
+
org.ObjectLayout - package org.ObjectLayout
+
+
ObjectLayout: An optimised memory layout package.
+
+
org.ObjectLayout.examples - package org.ObjectLayout.examples
+
 
+
org.ObjectLayout.examples.util - package org.ObjectLayout.examples.util
+
 
+
+A B C E F G H I K L M N O P R S T U V 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-14.html b/JavaDoc/index-files/index-14.html new file mode 100644 index 0000000..fcec365 --- /dev/null +++ b/JavaDoc/index-files/index-14.html @@ -0,0 +1,258 @@ + + + + + +P-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E F G H I K L M N O P R S T U V  + + +

P

+
+
Point - Class in org.ObjectLayout.examples
+
+
A simple x,y point class to be used as an element in various other examples.
+
+
Point() - Constructor for class org.ObjectLayout.examples.Point
+
 
+
Point(long, long) - Constructor for class org.ObjectLayout.examples.Point
+
 
+
Point(Point) - Constructor for class org.ObjectLayout.examples.Point
+
 
+
PointArray - Class in org.ObjectLayout.examples
+
 
+
PointArray(PointArray) - Constructor for class org.ObjectLayout.examples.PointArray
+
 
+
PointArray() - Constructor for class org.ObjectLayout.examples.PointArray
+
 
+
PrimitiveArrayBuilder<S extends AbstractPrimitiveArray> - Class in org.ObjectLayout
+
+
A builder used for instantiating a AbstractPrimitiveArray<T>
+
+
PrimitiveArrayBuilder(Class<S>, long) - Constructor for class org.ObjectLayout.PrimitiveArrayBuilder
+
+
Constructs a new PrimitiveArrayBuilder object for creating arrays of + type S with the given length.
+
+
PrimitiveArrayModel<S extends AbstractPrimitiveArray> - Class in org.ObjectLayout
+
+
A model that describes the structure of a PrimitiveArray
+
+
PrimitiveArrayModel(Class<S>, long) - Constructor for class org.ObjectLayout.PrimitiveArrayModel
+
+
Create a model of a PrimitiveArray instance
+
+
PrimitiveByteArray - Class in org.ObjectLayout
+
+
A subclassable array of bytes.
+
+
PrimitiveByteArray() - Constructor for class org.ObjectLayout.PrimitiveByteArray
+
+
Default constructor
+
+
PrimitiveByteArray(PrimitiveByteArray) - Constructor for class org.ObjectLayout.PrimitiveByteArray
+
+
Copying constructor
+
+
PrimitiveCharArray - Class in org.ObjectLayout
+
+
A subclassable array of chars.
+
+
PrimitiveCharArray() - Constructor for class org.ObjectLayout.PrimitiveCharArray
+
+
Default constructor
+
+
PrimitiveCharArray(PrimitiveCharArray) - Constructor for class org.ObjectLayout.PrimitiveCharArray
+
+
Copying constructor
+
+
PrimitiveDoubleArray - Class in org.ObjectLayout
+
+
A subclassable array of doubles.
+
+
PrimitiveDoubleArray() - Constructor for class org.ObjectLayout.PrimitiveDoubleArray
+
+
Default constructor
+
+
PrimitiveDoubleArray(PrimitiveDoubleArray) - Constructor for class org.ObjectLayout.PrimitiveDoubleArray
+
+
Copying constructor
+
+
PrimitiveFloatArray - Class in org.ObjectLayout
+
+
A subclassable array of floats.
+
+
PrimitiveFloatArray() - Constructor for class org.ObjectLayout.PrimitiveFloatArray
+
+
Default constructor
+
+
PrimitiveFloatArray(PrimitiveFloatArray) - Constructor for class org.ObjectLayout.PrimitiveFloatArray
+
+
Copying constructor
+
+
PrimitiveIntArray - Class in org.ObjectLayout
+
+
A subclassable array of ints.
+
+
PrimitiveIntArray() - Constructor for class org.ObjectLayout.PrimitiveIntArray
+
+
Default constructor
+
+
PrimitiveIntArray(PrimitiveIntArray) - Constructor for class org.ObjectLayout.PrimitiveIntArray
+
+
Copying constructor
+
+
PrimitiveLongArray - Class in org.ObjectLayout
+
+
A subclassable array of longs.
+
+
PrimitiveLongArray() - Constructor for class org.ObjectLayout.PrimitiveLongArray
+
+
Default constructor
+
+
PrimitiveLongArray(PrimitiveLongArray) - Constructor for class org.ObjectLayout.PrimitiveLongArray
+
+
Copying constructor
+
+
PrimitiveShortArray - Class in org.ObjectLayout
+
+
A subclassable array of shorts.
+
+
PrimitiveShortArray() - Constructor for class org.ObjectLayout.PrimitiveShortArray
+
+
Default constructor
+
+
PrimitiveShortArray(PrimitiveShortArray) - Constructor for class org.ObjectLayout.PrimitiveShortArray
+
+
Copying constructor
+
+
process(Set<? extends TypeElement>, RoundEnvironment) - Method in class org.ObjectLayout.IntrinsicProcessor
+
 
+
put(K, V) - Method in class org.ObjectLayout.examples.BPlusTree
+
 
+
put(K, V) - Method in class org.ObjectLayout.examples.util.SAAbstractMap
+
put(K, V) - Method in class org.ObjectLayout.examples.util.SAHashMap
+
+
Associates the specified value with the specified key in this map.
+
+
putAll(Map<? extends K, ? extends V>) - Method in class org.ObjectLayout.examples.util.SAAbstractMap
+
putAll(Map<? extends K, ? extends V>) - Method in class org.ObjectLayout.examples.util.SAHashMap
+
+
Copies all of the mappings from the specified map to this map.
+
+
putIfAbsent(K, V) - Method in class org.ObjectLayout.examples.util.SAHashMap
+
 
+
+A B C E F G H I K L M N O P R S T U V 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-15.html b/JavaDoc/index-files/index-15.html new file mode 100644 index 0000000..b62b631 --- /dev/null +++ b/JavaDoc/index-files/index-15.html @@ -0,0 +1,182 @@ + + + + + +R-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E F G H I K L M N O P R S T U V  + + +

R

+
+
RandomArrayWalk - Variable in class bench.ObjectLayoutBench
+
 
+
RandomArrayWalk - Variable in class bench.SAHashMapBench
+
 
+
RandomizedBasicArray(int, int[]) - Constructor for class bench.ObjectLayoutBench.RandomizedBasicArray
+
 
+
randomizedBasicArrayDataDependentLoop() - Method in class bench.ObjectLayoutBench
+
 
+
randomizedBasicArrayLoop() - Method in class bench.ObjectLayoutBench
+
 
+
ReferenceArray<T> - Class in org.ObjectLayout
+
+
A subclassable array of object references.
+
+
ReferenceArray() - Constructor for class org.ObjectLayout.ReferenceArray
+
+
Default constructor
+
+
ReferenceArray(ReferenceArray<T>) - Constructor for class org.ObjectLayout.ReferenceArray
+
+
Copy constructor
+
+
remove() - Method in class org.ObjectLayout.examples.BPlusTree.BPlusTreeIterator
+
 
+
remove(Object) - Method in class org.ObjectLayout.examples.BPlusTree
+
 
+
remove(Object) - Method in class org.ObjectLayout.examples.util.SAAbstractMap
+
remove(Object) - Method in class org.ObjectLayout.examples.util.SAHashMap
+
+
Removes the mapping for the specified key from this map if present.
+
+
remove(Object, Object) - Method in class org.ObjectLayout.examples.util.SAHashMap
+
 
+
remove() - Method in class org.ObjectLayout.StructuredArray.ElementIterator
+
+
Remove operation is not supported on StructuredArrays.
+
+
replace(K, V, V) - Method in class org.ObjectLayout.examples.util.SAHashMap
+
 
+
replace(K, V) - Method in class org.ObjectLayout.examples.util.SAHashMap
+
 
+
replaceAll(BiFunction<? super K, ? super V, ? extends V>) - Method in class org.ObjectLayout.examples.util.SAHashMap
+
 
+
reset() - Method in class org.ObjectLayout.examples.MassOrder.Builder
+
 
+
reset() - Method in class org.ObjectLayout.StructuredArray.ElementIterator
+
+
Reset to the beginning of the collection enabling reuse of the iterator.
+
+
resolve() - Method in class org.ObjectLayout.PrimitiveArrayBuilder
+
+
Resolve any not-yet-resolved constructor information needed by this builder.
+
+
resolve() - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Resolve any not-yet-resolved constructor information needed by this builder.
+
+
+A B C E F G H I K L M N O P R S T U V 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-16.html b/JavaDoc/index-files/index-16.html new file mode 100644 index 0000000..7a90a11 --- /dev/null +++ b/JavaDoc/index-files/index-16.html @@ -0,0 +1,420 @@ + + + + + +S-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E F G H I K L M N O P R S T U V  + + +

S

+
+
SAAbstractMap<K,V> - Class in org.ObjectLayout.examples.util
+
+
This class provides a skeletal implementation of the Map + interface, to minimize the effort required to implement this interface.
+
+
SAAbstractMap.SimpleEntry<K,V> - Class in org.ObjectLayout.examples.util
+
+
An Entry maintaining a key and a value.
+
+
SAAbstractMap.SimpleImmutableEntry<K,V> - Class in org.ObjectLayout.examples.util
+
+
An Entry maintaining an immutable key and value.
+
+
SAHashMap<K,V> - Class in org.ObjectLayout.examples.util
+
+
Hash table based implementation of the Map interface.
+
+
SAHashMap(int, float) - Constructor for class org.ObjectLayout.examples.util.SAHashMap
+
+
Constructs an empty HashMap with the specified initial + capacity and load factor.
+
+
SAHashMap(int) - Constructor for class org.ObjectLayout.examples.util.SAHashMap
+
+
Constructs an empty HashMap with the specified initial + capacity and the default load factor (0.75).
+
+
SAHashMap() - Constructor for class org.ObjectLayout.examples.util.SAHashMap
+
+
Constructs an empty HashMap with the default initial capacity + (16) and the default load factor (0.75).
+
+
SAHashMap(Map<? extends K, ? extends V>) - Constructor for class org.ObjectLayout.examples.util.SAHashMap
+
+
Constructs a new HashMap with the same mappings as the + specified Map.
+
+
SAHashMapBench - Class in bench
+
 
+
SAHashMapBench() - Constructor for class bench.SAHashMapBench
+
 
+
SAHashMapBench.Element - Class in bench
+
 
+
SAHashMapBench.ElementBase - Class in bench
+
 
+
saMap - Variable in class bench.SAHashMapBench
+
 
+
saMapDataDependentLoop() - Method in class bench.SAHashMapBench
+
 
+
saMapLoop() - Method in class bench.SAHashMapBench
+
 
+
set(long, long) - Method in class org.ObjectLayout.examples.Point
+
 
+
set(int, byte) - Method in class org.ObjectLayout.PrimitiveByteArray
+
+
set the value of an element in the array.
+
+
set(long, byte) - Method in class org.ObjectLayout.PrimitiveByteArray
+
+
set the value of an element in the array.
+
+
set(int, char) - Method in class org.ObjectLayout.PrimitiveCharArray
+
+
set the value of an element in the array.
+
+
set(long, char) - Method in class org.ObjectLayout.PrimitiveCharArray
+
+
set the value of an element in the array.
+
+
set(int, double) - Method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
set the value of an element in the array.
+
+
set(long, double) - Method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
set the value of an element in the array.
+
+
set(int, float) - Method in class org.ObjectLayout.PrimitiveFloatArray
+
+
set the value of an element in the array.
+
+
set(long, float) - Method in class org.ObjectLayout.PrimitiveFloatArray
+
+
set the value of an element in the array.
+
+
set(int, int) - Method in class org.ObjectLayout.PrimitiveIntArray
+
+
set the value of an element in the array.
+
+
set(long, int) - Method in class org.ObjectLayout.PrimitiveIntArray
+
+
set the value of an element in the array.
+
+
set(int, long) - Method in class org.ObjectLayout.PrimitiveLongArray
+
+
set the value of an element in the array.
+
+
set(long, long) - Method in class org.ObjectLayout.PrimitiveLongArray
+
+
set the value of an element in the array.
+
+
set(int, short) - Method in class org.ObjectLayout.PrimitiveShortArray
+
+
set the value of an element in the array.
+
+
set(long, short) - Method in class org.ObjectLayout.PrimitiveShortArray
+
+
set the value of an element in the array.
+
+
set(int, T) - Method in class org.ObjectLayout.ReferenceArray
+
+
set the value of an element in the array.
+
+
set(long, T) - Method in class org.ObjectLayout.ReferenceArray
+
+
set the value of an element in the array.
+
+
setArgs(Object...) - Method in class org.ObjectLayout.CtorAndArgs
+
+
Set the constructor arguments to be indicated in this CtorAndArgs.
+
+
setConstructor(Constructor<T>) - Method in class org.ObjectLayout.CtorAndArgs
+
+
Set the constructor to be indicated in this CtorAndArgs.
+
+
setContextCookie(Object) - Method in class org.ObjectLayout.CtorAndArgs
+
+
Set the value of the opaque contextCookie object
+
+
setIndex(long) - Method in class bench.ObjectLayoutBench.ElementBase
+
 
+
setIndex(long) - Method in class bench.SAHashMapBench.ElementBase
+
 
+
setNextIndex(int) - Method in class bench.ObjectLayoutBench.ElementBase
+
 
+
setNextIndex(int) - Method in class bench.SAHashMapBench.ElementBase
+
 
+
setup() - Method in class bench.ObjectLayoutBench
+
 
+
setup() - Method in class bench.SAHashMapBench
+
 
+
setValue(V) - Method in class org.ObjectLayout.examples.util.SAAbstractMap.SimpleEntry
+
+
Replaces the value corresponding to this entry with the specified + value.
+
+
setValue(V) - Method in class org.ObjectLayout.examples.util.SAAbstractMap.SimpleImmutableEntry
+
+
Replaces the value corresponding to this entry with the specified + value (optional operation).
+
+
setX(long) - Method in class org.ObjectLayout.examples.Point
+
 
+
setY(long) - Method in class org.ObjectLayout.examples.Point
+
 
+
shallowCopy(ReferenceArray<T>, long, ReferenceArray<T>, long, long) - Static method in class org.ObjectLayout.examples.BPlusTree
+
 
+
shallowCopy(S, long, S, long, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Shallow copy a region of element object contents from one array to the other.
+
+
shallowCopy(S, long, S, long, long, boolean) - Static method in class org.ObjectLayout.StructuredArray
+
+
Shallow copy a region of element object contents from one array to the other.
+
+
shuffledNextIndexes - Variable in class bench.SAHashMapBench
+
 
+
simple_math(long, int) - Static method in class bench.SAHashMapBench.ElementBase
+
 
+
SimpleEntry(K, V) - Constructor for class org.ObjectLayout.examples.util.SAAbstractMap.SimpleEntry
+
+
Creates an entry representing a mapping from the specified + key to the specified value.
+
+
SimpleEntry(Map.Entry<? extends K, ? extends V>) - Constructor for class org.ObjectLayout.examples.util.SAAbstractMap.SimpleEntry
+
+
Creates an entry representing the same mapping as the + specified entry.
+
+
SimpleImmutableEntry(K, V) - Constructor for class org.ObjectLayout.examples.util.SAAbstractMap.SimpleImmutableEntry
+
+
Creates an entry representing a mapping from the specified + key to the specified value.
+
+
SimpleImmutableEntry(Map.Entry<? extends K, ? extends V>) - Constructor for class org.ObjectLayout.examples.util.SAAbstractMap.SimpleImmutableEntry
+
+
Creates an entry representing the same mapping as the + specified entry.
+
+
SimpleLine - Class in org.ObjectLayout.examples
+
+
A simple org.ObjectLayout.examples.Line class example with two intrinsic org.ObjectLayout.examples.Point end point objects.
+
+
SimpleLine() - Constructor for class org.ObjectLayout.examples.SimpleLine
+
 
+
SimpleLine(long, long, long, long) - Constructor for class org.ObjectLayout.examples.SimpleLine
+
 
+
SimpleLine(SimpleLine) - Constructor for class org.ObjectLayout.examples.SimpleLine
+
 
+
SimpleOrder - Class in org.ObjectLayout.examples
+
 
+
SimpleOrder(MassOrder.Builder, SimpleOrder.Side, long, long) - Constructor for class org.ObjectLayout.examples.SimpleOrder
+
 
+
SimpleOrder.OrderType - Enum in org.ObjectLayout.examples
+
 
+
SimpleOrder.Side - Enum in org.ObjectLayout.examples
+
 
+
size() - Method in class org.ObjectLayout.examples.BPlusTree
+
 
+
size() - Method in class org.ObjectLayout.examples.util.SAAbstractMap
+
size() - Method in class org.ObjectLayout.examples.util.SAHashMap
+
+
Returns the number of key-value mappings in this map.
+
+
StructuredArray<T> - Class in org.ObjectLayout
+
+
An array of non-replaceable objects.
+
+
StructuredArray.ElementIterator - Class in org.ObjectLayout
+
+
Specialised Iterator with the ability to be StructuredArray.ElementIterator.reset() enabling reuse.
+
+
StructuredArrayBuilder<S extends StructuredArray<T>,T> - Class in org.ObjectLayout
+
+
A builder used for instantiating a StructuredArray<T>
+
+
StructuredArrayBuilder(Class<S>, Class<T>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating arrays of type S with + elements of type T, and the given length.
+
+
StructuredArrayBuilder(MethodHandles.Lookup, Class<S>, Class<T>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating arrays of type S with + elements of type T, and the given length.
+
+
StructuredArrayBuilder(StructuredArrayModel<S, T>) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating arrays of the given array model.
+
+
StructuredArrayBuilder(MethodHandles.Lookup, StructuredArrayModel<S, T>) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating arrays of the given array model.
+
+
StructuredArrayBuilder(Class<S>, StructuredArrayBuilder<A, E>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating an array of type S with + elements of type T, and the given length.
+
+
StructuredArrayBuilder(MethodHandles.Lookup, Class<S>, StructuredArrayBuilder<A, E>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating an array of type S with + elements of type T, and the given length.
+
+
StructuredArrayBuilder(Class<S>, PrimitiveArrayBuilder<A>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating an array of type S with + elements of type T, and the given length.
+
+
StructuredArrayBuilder(MethodHandles.Lookup, Class<S>, PrimitiveArrayBuilder<A>, long) - Constructor for class org.ObjectLayout.StructuredArrayBuilder
+
+
Constructs a new StructuredArrayBuilder object for creating an array of type S with + elements of type T, and the given length.
+
+
structuredArrayDataDependentLoop() - Method in class bench.ObjectLayoutBench
+
 
+
structuredArrayLoop() - Method in class bench.ObjectLayoutBench
+
 
+
StructuredArrayModel<S extends StructuredArray<T>,T> - Class in org.ObjectLayout
+
+
A model that describes the structure of a StructuredArray
+
+
StructuredArrayModel(long) - Constructor for class org.ObjectLayout.StructuredArrayModel
+
+
Create a model of a StructuredArray instance with terminal (non StructuredArray) elements, + deriving the array class and element class from the generic class parameters
+
+
StructuredArrayModel(Class<S>, Class<T>, long) - Constructor for class org.ObjectLayout.StructuredArrayModel
+
+
Create a model of a StructuredArray instance with terminal (non StructuredArray) elements
+
+
StructuredArrayModel(Class<S>, StructuredArrayModel<A2, T2>, long) - Constructor for class org.ObjectLayout.StructuredArrayModel
+
+
Create a model of a StructuredArray instance with elements that are themselves StructuredArrays
+
+
StructuredArrayModel(Class<S>, PrimitiveArrayModel<A2>, long) - Constructor for class org.ObjectLayout.StructuredArrayModel
+
+
Create a model of a StructuredArray instance with elements that are themselves subclassable PrimitiveArrays
+
+
StructuredArrayOfAtomicLong - Class in org.ObjectLayout.examples
+
+
A simple, minimalistic example of a non-generic subclass of StructuredArray<AtomicLong>.
+
+
StructuredArrayOfAtomicLong() - Constructor for class org.ObjectLayout.examples.StructuredArrayOfAtomicLong
+
 
+
+A B C E F G H I K L M N O P R S T U V 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-17.html b/JavaDoc/index-files/index-17.html new file mode 100644 index 0000000..43c0a7b --- /dev/null +++ b/JavaDoc/index-files/index-17.html @@ -0,0 +1,153 @@ + + + + + +T-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E F G H I K L M N O P R S T U V  + + +

T

+
+
toString() - Method in class bench.SAHashMapBench.ElementBase
+
 
+
toString() - Method in class org.ObjectLayout.examples.BPlusTree
+
 
+
toString() - Method in class org.ObjectLayout.examples.MassOrder
+
 
+
toString() - Method in class org.ObjectLayout.examples.SimpleOrder
+
 
+
toString() - Method in class org.ObjectLayout.examples.util.SAAbstractMap.SimpleEntry
+
+
Returns a String representation of this map entry.
+
+
toString() - Method in class org.ObjectLayout.examples.util.SAAbstractMap.SimpleImmutableEntry
+
+
Returns a String representation of this map entry.
+
+
toString() - Method in class org.ObjectLayout.examples.util.SAAbstractMap
+
+
Returns a string representation of this map.
+
+
TwoDimPointMatrix - Class in org.ObjectLayout.examples
+
+
A Matrix arranged as a height long array of columns (logically indexed as [x][y])
+
+
TwoDimPointMatrix() - Constructor for class org.ObjectLayout.examples.TwoDimPointMatrix
+
 
+
TwoDimPointMatrix(TwoDimPointMatrix) - Constructor for class org.ObjectLayout.examples.TwoDimPointMatrix
+
 
+
+A B C E F G H I K L M N O P R S T U V 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-18.html b/JavaDoc/index-files/index-18.html new file mode 100644 index 0000000..cbe50a2 --- /dev/null +++ b/JavaDoc/index-files/index-18.html @@ -0,0 +1,129 @@ + + + + + +U-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E F G H I K L M N O P R S T U V  + + +

U

+
+
updateCancelled(long) - Method in class org.ObjectLayout.examples.SimpleOrder
+
 
+
updateFill(long) - Method in class org.ObjectLayout.examples.SimpleOrder
+
 
+
+A B C E F G H I K L M N O P R S T U V 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-19.html b/JavaDoc/index-files/index-19.html new file mode 100644 index 0000000..c0d683e --- /dev/null +++ b/JavaDoc/index-files/index-19.html @@ -0,0 +1,148 @@ + + + + + +V-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E F G H I K L M N O P R S T U V  + + +

V

+
+
valueOf(String) - Static method in enum org.ObjectLayout.examples.SimpleOrder.OrderType
+
+
Returns the enum constant of this type with the specified name.
+
+
valueOf(String) - Static method in enum org.ObjectLayout.examples.SimpleOrder.Side
+
+
Returns the enum constant of this type with the specified name.
+
+
values() - Static method in enum org.ObjectLayout.examples.SimpleOrder.OrderType
+
+
Returns an array containing the constants of this enum type, in +the order they are declared.
+
+
values() - Static method in enum org.ObjectLayout.examples.SimpleOrder.Side
+
+
Returns an array containing the constants of this enum type, in +the order they are declared.
+
+
values() - Method in class org.ObjectLayout.examples.util.SAAbstractMap
+
values() - Method in class org.ObjectLayout.examples.util.SAHashMap
+
+
Returns a Collection view of the values contained in this map.
+
+
+A B C E F G H I K L M N O P R S T U V 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-2.html b/JavaDoc/index-files/index-2.html new file mode 100644 index 0000000..bc1989e --- /dev/null +++ b/JavaDoc/index-files/index-2.html @@ -0,0 +1,131 @@ + + + + + +B-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

B

+
+
build() - Method in class org.ObjectLayout.PrimitiveArrayBuilder
+
+
Build a AbstractPrimitiveArray according to the information captured in this builder
+
+
build() - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Build a StructuredArray according to the information captured in this builder
+
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-3.html b/JavaDoc/index-files/index-3.html new file mode 100644 index 0000000..fd8df46 --- /dev/null +++ b/JavaDoc/index-files/index-3.html @@ -0,0 +1,291 @@ + + + + + +C-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

C

+
+
ConstructionContext<T> - Class in org.ObjectLayout
+
+
The construction context for object instantiated within a StructuredArray
+
+
ConstructionContext(Object) - Constructor for class org.ObjectLayout.ConstructionContext
+
 
+
constructWithin(MethodHandles.Lookup, String, Object) - Static method in class org.ObjectLayout.IntrinsicObjects
+
+
Construct an intrinsic object at the given field within the containing object, using a default constructor.
+
+
constructWithin(MethodHandles.Lookup, String, Object, Constructor<T>, Object...) - Static method in class org.ObjectLayout.IntrinsicObjects
+
+
Construct an intrinsic object at the given field within the containing object, using the given + constructor and arguments.
+
+
constructWithin(MethodHandles.Lookup, String, Object, CtorAndArgs<T>) - Static method in class org.ObjectLayout.IntrinsicObjects
+
+
Construct an intrinsic object at the given field within the containing object, using the + constructor and arguments supplied in the given objectCtorAndArgs argument.
+
+
constructWithin(MethodHandles.Lookup, String, Object, StructuredArrayBuilder) - Static method in class org.ObjectLayout.IntrinsicObjects
+
+
Construct an intrinsic object at the given field within the containing object, using the + supplied StructuredArrayBuilder.
+
+
constructWithin(MethodHandles.Lookup, String, Object, PrimitiveArrayBuilder) - Static method in class org.ObjectLayout.IntrinsicObjects
+
+
Construct an intrinsic object at the given field within the containing object, using the + supplied PrimitiveArrayBuilder.
+
+
contextCookie(Object) - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Set the (opaque) contextCookie object associated with this builder.
+
+
copyInstance(A) - Static method in class org.ObjectLayout.PrimitiveByteArray
+
+
Create a new <A extends PrimitiveByteArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(MethodHandles.Lookup, A) - Static method in class org.ObjectLayout.PrimitiveByteArray
+
+
Create a new <A extends PrimitiveByteArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(A) - Static method in class org.ObjectLayout.PrimitiveCharArray
+
+
Create a new <A extends PrimitiveCharArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(MethodHandles.Lookup, A) - Static method in class org.ObjectLayout.PrimitiveCharArray
+
+
Create a new <A extends PrimitiveCharArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(A) - Static method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Create a new <A extends PrimitiveDoubleArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(MethodHandles.Lookup, A) - Static method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Create a new <A extends PrimitiveDoubleArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(A) - Static method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Create a new <A extends PrimitiveFloatArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(MethodHandles.Lookup, A) - Static method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Create a new <A extends PrimitiveFloatArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(A) - Static method in class org.ObjectLayout.PrimitiveIntArray
+
+
Create a new <A extends PrimitiveIntArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(MethodHandles.Lookup, A) - Static method in class org.ObjectLayout.PrimitiveIntArray
+
+
Create a new <A extends PrimitiveIntArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(A) - Static method in class org.ObjectLayout.PrimitiveLongArray
+
+
Create a new <A extends PrimitiveLongArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(MethodHandles.Lookup, A) - Static method in class org.ObjectLayout.PrimitiveLongArray
+
+
Create a new <A extends PrimitiveLongArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(A) - Static method in class org.ObjectLayout.PrimitiveShortArray
+
+
Create a new <A extends PrimitiveShortArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(MethodHandles.Lookup, A) - Static method in class org.ObjectLayout.PrimitiveShortArray
+
+
Create a new <A extends PrimitiveShortArray> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(A) - Static method in class org.ObjectLayout.ReferenceArray
+
+
Create a new <A extends ReferenceArray<T>> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(MethodHandles.Lookup, A) - Static method in class org.ObjectLayout.ReferenceArray
+
+
Create a new <A extends ReferenceArray<T>> instance, using a copy constructor to + replicate the contents of the given source array
+
+
copyInstance(S) - Static method in class org.ObjectLayout.StructuredArray
+
+
Copy a given array of elements to a newly created array.
+
+
copyInstance(MethodHandles.Lookup, S) - Static method in class org.ObjectLayout.StructuredArray
+
+
Copy a given array of elements to a newly created array.
+
+
copyInstance(S, long, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Copy a range from an array of elements to a newly created array.
+
+
copyInstance(MethodHandles.Lookup, S, long, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Copy a range from an array of elements to a newly created array.
+
+
copyInstance(S, long[], long[]) - Static method in class org.ObjectLayout.StructuredArray
+
+
Copy a range from an array of elements to a newly created array.
+
+
copyInstance(MethodHandles.Lookup, S, long[], long[]) - Static method in class org.ObjectLayout.StructuredArray
+
+
Copy a range from an array of elements to a newly created array.
+
+
CtorAndArgs<T> - Class in org.ObjectLayout
+
+
Captures a specific constructor and arguments to be passed to it.
+
+
CtorAndArgs(Constructor<T>, Object...) - Constructor for class org.ObjectLayout.CtorAndArgs
+
+
Create a CtorAndArgs instance.
+
+
CtorAndArgs(Class<T>, Class[], Object...) - Constructor for class org.ObjectLayout.CtorAndArgs
+
+
Create a CtorAndArgs instance for the given instanceClass, with a constructor + identified by the constructorArgTypes, and using the args provides.
+
+
CtorAndArgs(MethodHandles.Lookup, Class<T>, Class[], Object...) - Constructor for class org.ObjectLayout.CtorAndArgs
+
+
Create a CtorAndArgs instance for the given instanceClass, with a constructor + identified by the constructorArgTypes, and using the args provides.
+
+
CtorAndArgs(Class<T>) - Constructor for class org.ObjectLayout.CtorAndArgs
+
+
Create a CtorAndArgs instance for the given instanceClass, using the default constructor (and no args)
+
+
CtorAndArgs(MethodHandles.Lookup, Class<T>) - Constructor for class org.ObjectLayout.CtorAndArgs
+
+
Create a CtorAndArgs instance for the given instanceClass, using the default constructor (and no args)
+
+
CtorAndArgsProvider<T> - Interface in org.ObjectLayout
+
+
A functional interface for providing a constructor and arguments given a construction context (index, etc.).
+
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-4.html b/JavaDoc/index-files/index-4.html new file mode 100644 index 0000000..e1bab3e --- /dev/null +++ b/JavaDoc/index-files/index-4.html @@ -0,0 +1,148 @@ + + + + + +E-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

E

+
+
elementCtorAndArgs(CtorAndArgs<T>) - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Set the CtorAndArgs to be used for all elements in the array.
+
+
elementCtorAndArgs(Constructor<T>, Object...) - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Set the Constructor and construction arguments to be used for all elements in the array.
+
+
elementCtorAndArgsProvider(CtorAndArgsProvider<T>) - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Set the CtorAndArgsProvider used for determining the constructor and construction + arguments used for each element in the array.
+
+
ElementIterator() - Constructor for class org.ObjectLayout.StructuredArray.ElementIterator
+
 
+
ElementIterator(long, long) - Constructor for class org.ObjectLayout.StructuredArray.ElementIterator
+
 
+
equals(Object) - Method in class org.ObjectLayout.PrimitiveArrayModel
+
+
Determine if this model is equal to another object.
+
+
equals(Object) - Method in class org.ObjectLayout.StructuredArrayModel
+
+
Determine if this model is equal to another object.
+
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-5.html b/JavaDoc/index-files/index-5.html new file mode 100644 index 0000000..1fa9418 --- /dev/null +++ b/JavaDoc/index-files/index-5.html @@ -0,0 +1,339 @@ + + + + + +G-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

G

+
+
get(int) - Method in class org.ObjectLayout.PrimitiveByteArray
+
+
Get the value of an element in the array.
+
+
get(long) - Method in class org.ObjectLayout.PrimitiveByteArray
+
+
Get the value of an element in the array.
+
+
get(int) - Method in class org.ObjectLayout.PrimitiveCharArray
+
+
Get the value of an element in the array.
+
+
get(long) - Method in class org.ObjectLayout.PrimitiveCharArray
+
+
Get the value of an element in the array.
+
+
get(int) - Method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Get the value of an element in the array.
+
+
get(long) - Method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Get the value of an element in the array.
+
+
get(int) - Method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Get the value of an element in the array.
+
+
get(long) - Method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Get the value of an element in the array.
+
+
get(int) - Method in class org.ObjectLayout.PrimitiveIntArray
+
+
Get the value of an element in the array.
+
+
get(long) - Method in class org.ObjectLayout.PrimitiveIntArray
+
+
Get the value of an element in the array.
+
+
get(int) - Method in class org.ObjectLayout.PrimitiveLongArray
+
+
Get the value of an element in the array.
+
+
get(long) - Method in class org.ObjectLayout.PrimitiveLongArray
+
+
Get the value of an element in the array.
+
+
get(int) - Method in class org.ObjectLayout.PrimitiveShortArray
+
+
Get the value of an element in the array.
+
+
get(long) - Method in class org.ObjectLayout.PrimitiveShortArray
+
+
Get the value of an element in the array.
+
+
get(int) - Method in class org.ObjectLayout.ReferenceArray
+
+
Get the value of an element in the array.
+
+
get(long) - Method in class org.ObjectLayout.ReferenceArray
+
+
Get the value of an element in the array.
+
+
get(long) - Method in class org.ObjectLayout.StructuredArray
+
+
Get a reference to an element in a single dimensional array, using a long index.
+
+
get(int) - Method in class org.ObjectLayout.StructuredArray
+
+
Get a reference to an element in a single dimensional array, using an int index.
+
+
getArgs() - Method in class org.ObjectLayout.CtorAndArgs
+
 
+
getArray() - Method in class org.ObjectLayout.ConstructionContext
+
+
Get the immediately containing StructuredArray.
+
+
getArrayClass() - Method in class org.ObjectLayout.PrimitiveArrayModel
+
+
Get the class of the PrimitiveArray modeled by this model
+
+
getArrayClass() - Method in class org.ObjectLayout.StructuredArrayModel
+
+
Get the class of the StructuredArray modeled by this model
+
+
getArrayCtorAndArgs() - Method in class org.ObjectLayout.PrimitiveArrayBuilder
+
+
Get the CtorAndArgs describing the constructor and arguments used to instantiate arrays with + this builder.
+
+
getArrayCtorAndArgs() - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Get the CtorAndArgs describing the constructor and arguments used to instantiate arrays with + this builder.
+
+
getArrayModel() - Method in class org.ObjectLayout.PrimitiveArrayBuilder
+
+
Get the PrimitiveArrayModel that describes the arrays built by this builder
+
+
getArrayModel() - Method in class org.ObjectLayout.StructuredArray
+
+
Get the array model
+
+
getArrayModel() - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Get the StructuredArrayModel that describes the arrays built by this builder
+
+
getConstructor() - Method in class org.ObjectLayout.CtorAndArgs
+
 
+
getContainingContext() - Method in class org.ObjectLayout.ConstructionContext
+
+
Get the containing context.
+
+
getContextCookie() - Method in class org.ObjectLayout.ConstructionContext
+
+
Get the construction context cookie object.The construction context cookie of the outermost + array is taken from the (optionally supplied) StructuredArrayBuilder used in instantiating + the array (via StructuredArrayBuilder.getContextCookie()).
+
+
getContextCookie() - Method in class org.ObjectLayout.CtorAndArgs
+
+
Get the value of the opaque contextCookie object
+
+
getContextCookie() - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Get the (opaque) contextCookie object associated with this builder.
+
+
getCursor() - Method in class org.ObjectLayout.StructuredArray.ElementIterator
+
 
+
getElementClass() - Method in class org.ObjectLayout.StructuredArray
+
+
Get the Class of elements stored in the array.
+
+
getElementClass() - Method in class org.ObjectLayout.StructuredArrayModel
+
+
Get the class of the elements in the StructuredArray modeled by the model
+
+
getElementCtorAndArgsProvider() - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Get the CtorAndArgsProvider which provides the constructor and arguments used to construct + individual elements of arrays instantiated with this builder.
+
+
getForContext(ConstructionContext<T>) - Method in interface org.ObjectLayout.CtorAndArgsProvider
+
+
Get a CtorAndArgs instance to be used in constructing a given element index in + a StructuredArray
+
+
getIndex() - Method in class org.ObjectLayout.ConstructionContext
+
+
Get the index (of the element being constructed) in the immediately containing StructuredArray.
+
+
getLength() - Method in class org.ObjectLayout.PrimitiveArrayModel
+
+
Get the length of the PrimitiveArray modeled by the model
+
+
getLength() - Method in class org.ObjectLayout.PrimitiveByteArray
+
+
Get the length of the array
+
+
getLength() - Method in class org.ObjectLayout.PrimitiveCharArray
+
+
Get the length of the array
+
+
getLength() - Method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Get the length of the array
+
+
getLength() - Method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Get the length of the array
+
+
getLength() - Method in class org.ObjectLayout.PrimitiveIntArray
+
+
Get the length of the array
+
+
getLength() - Method in class org.ObjectLayout.PrimitiveLongArray
+
+
Get the length of the array
+
+
getLength() - Method in class org.ObjectLayout.PrimitiveShortArray
+
+
Get the length of the array
+
+
getLength() - Method in class org.ObjectLayout.ReferenceArray
+
+
Get the length of the array
+
+
getLength() - Method in class org.ObjectLayout.StructuredArray
+
+
Get the length (number of elements) of the array.
+
+
getLength() - Method in class org.ObjectLayout.StructuredArrayModel
+
+
Get the length of the StructuredArray modeled by the model
+
+
getPrimitiveSubArrayBuilder() - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Get the StructuredArrayBuilder for the elements of the arrays built by + this builder.
+
+
getPrimitiveSubArrayModel() - Method in class org.ObjectLayout.StructuredArrayModel
+
+
Get the model describing the structure of the elements of the array being modeled
+
+
getStructuredSubArrayBuilder() - Method in class org.ObjectLayout.StructuredArrayBuilder
+
+
Get the StructuredArrayBuilder for the elements of the arrays built by + this builder.
+
+
getStructuredSubArrayModel() - Method in class org.ObjectLayout.StructuredArrayModel
+
+
Get the model describing the structure of the elements of the array being modeled
+
+
getSupportedSourceVersion() - Method in class org.ObjectLayout.IntrinsicProcessor
+
 
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-6.html b/JavaDoc/index-files/index-6.html new file mode 100644 index 0000000..c706f4f --- /dev/null +++ b/JavaDoc/index-files/index-6.html @@ -0,0 +1,124 @@ + + + + + +H-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

H

+
+
hasNext() - Method in class org.ObjectLayout.StructuredArray.ElementIterator
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-7.html b/JavaDoc/index-files/index-7.html new file mode 100644 index 0000000..5177fd8 --- /dev/null +++ b/JavaDoc/index-files/index-7.html @@ -0,0 +1,145 @@ + + + + + +I-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

I

+
+
Intrinsic - Annotation Type in org.ObjectLayout
+
+
The @Intrisic annotation defines a declared object field to be + intrinsic to the class it is declared in.
+
+
Intrinsic.NO_DECLARED_CLASS - Class in org.ObjectLayout
+
+
A no-op class used to indicate no value set for the Intrinsic.elementClass() element.
+
+
IntrinsicObjects - Class in org.ObjectLayout
+
+
Intrinsic objects (declared with the @Intrisic annotation) may have + their layout within the containing object instance optimized by JDK implementations, such that access + to their content is faster, and avoids certain de-referencing steps.
+
+
IntrinsicProcessor - Class in org.ObjectLayout
+
+
A javac annotation processor for the @Intrinsic annotation.
+
+
IntrinsicProcessor() - Constructor for class org.ObjectLayout.IntrinsicProcessor
+
 
+
iterator() - Method in class org.ObjectLayout.StructuredArray
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-8.html b/JavaDoc/index-files/index-8.html new file mode 100644 index 0000000..f4c8c50 --- /dev/null +++ b/JavaDoc/index-files/index-8.html @@ -0,0 +1,373 @@ + + + + + +N-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

N

+
+
newInstance(long) - Static method in class org.ObjectLayout.PrimitiveByteArray
+
+
Create a new instance of PrimitiveByteArray with a given length.
+
+
newInstance(Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveByteArray
+
+
Create a new instance of <A extends PrimitiveByteArray> with a given length.
+
+
newInstance(MethodHandles.Lookup, Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveByteArray
+
+
Create a new instance of <A extends PrimitiveByteArray> with a given length.
+
+
newInstance(CtorAndArgs<A>, long) - Static method in class org.ObjectLayout.PrimitiveByteArray
+
+
Create a new instance of <A extends PrimitiveByteArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long, Constructor<A>, Object...) - Static method in class org.ObjectLayout.PrimitiveByteArray
+
+
Create a new instance of <A extends PrimitiveByteArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long) - Static method in class org.ObjectLayout.PrimitiveCharArray
+
+
Create a new instance of PrimitiveCharArray with a given length.
+
+
newInstance(Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveCharArray
+
+
Create a new instance of <A extends PrimitiveCharArray> with a given length.
+
+
newInstance(MethodHandles.Lookup, Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveCharArray
+
+
Create a new instance of <A extends PrimitiveCharArray> with a given length.
+
+
newInstance(CtorAndArgs<A>, long) - Static method in class org.ObjectLayout.PrimitiveCharArray
+
+
Create a new instance of <A extends PrimitiveCharArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long, Constructor<A>, Object...) - Static method in class org.ObjectLayout.PrimitiveCharArray
+
+
Create a new instance of <A extends PrimitiveCharArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long) - Static method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Create a new instance of PrimitiveDoubleArray with a given length.
+
+
newInstance(Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Create a new instance of <A extends PrimitiveDoubleArray> with a given length.
+
+
newInstance(MethodHandles.Lookup, Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Create a new instance of <A extends PrimitiveDoubleArray> with a given length.
+
+
newInstance(CtorAndArgs<A>, long) - Static method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Create a new instance of <A extends PrimitiveDoubleArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long, Constructor<A>, Object...) - Static method in class org.ObjectLayout.PrimitiveDoubleArray
+
+
Create a new instance of <A extends PrimitiveDoubleArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long) - Static method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Create a new instance of PrimitiveFloatArray with a given length.
+
+
newInstance(Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Create a new instance of <A extends PrimitiveFloatArray> with a given length.
+
+
newInstance(MethodHandles.Lookup, Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Create a new instance of <A extends PrimitiveFloatArray> with a given length.
+
+
newInstance(CtorAndArgs<A>, long) - Static method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Create a new instance of <A extends PrimitiveFloatArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long, Constructor<A>, Object...) - Static method in class org.ObjectLayout.PrimitiveFloatArray
+
+
Create a new instance of <A extends PrimitiveFloatArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long) - Static method in class org.ObjectLayout.PrimitiveIntArray
+
+
Create a new instance of PrimitiveIntArray with a given length.
+
+
newInstance(Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveIntArray
+
+
Create a new instance of <A extends PrimitiveIntArray> with a given length.
+
+
newInstance(MethodHandles.Lookup, Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveIntArray
+
+
Create a new instance of <A extends PrimitiveIntArray> with a given length.
+
+
newInstance(CtorAndArgs<A>, long) - Static method in class org.ObjectLayout.PrimitiveIntArray
+
+
Create a new instance of <A extends PrimitiveIntArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long, Constructor<A>, Object...) - Static method in class org.ObjectLayout.PrimitiveIntArray
+
+
Create a new instance of <A extends PrimitiveIntArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long) - Static method in class org.ObjectLayout.PrimitiveLongArray
+
+
Create a new instance of PrimitiveLongArray with a given length.
+
+
newInstance(Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveLongArray
+
+
Create a new instance of <A extends PrimitiveLongArray> with a given length.
+
+
newInstance(MethodHandles.Lookup, Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveLongArray
+
+
Create a new instance of <A extends PrimitiveLongArray> with a given length.
+
+
newInstance(CtorAndArgs<A>, long) - Static method in class org.ObjectLayout.PrimitiveLongArray
+
+
Create a new instance of <A extends PrimitiveLongArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long, Constructor<A>, Object...) - Static method in class org.ObjectLayout.PrimitiveLongArray
+
+
Create a new instance of <A extends PrimitiveLongArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long) - Static method in class org.ObjectLayout.PrimitiveShortArray
+
+
Create a new instance of PrimitiveShortArray with a given length.
+
+
newInstance(Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveShortArray
+
+
Create a new instance of <A extends PrimitiveShortArray> with a given length.
+
+
newInstance(MethodHandles.Lookup, Class<A>, long) - Static method in class org.ObjectLayout.PrimitiveShortArray
+
+
Create a new instance of <A extends PrimitiveShortArray> with a given length.
+
+
newInstance(CtorAndArgs<A>, long) - Static method in class org.ObjectLayout.PrimitiveShortArray
+
+
Create a new instance of <A extends PrimitiveShortArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long, Constructor<A>, Object...) - Static method in class org.ObjectLayout.PrimitiveShortArray
+
+
Create a new instance of <A extends PrimitiveShortArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long) - Static method in class org.ObjectLayout.ReferenceArray
+
+
Create a new instance of ReferenceArray<T> with a given length.
+
+
newInstance(Class<A>, long) - Static method in class org.ObjectLayout.ReferenceArray
+
+
Create a new instance of <A extends ReferenceArray<T>> with a given length.
+
+
newInstance(MethodHandles.Lookup, Class<A>, long) - Static method in class org.ObjectLayout.ReferenceArray
+
+
Create a new instance of <A extends ReferenceArray<T>> with a given length.
+
+
newInstance(CtorAndArgs<A>, long) - Static method in class org.ObjectLayout.ReferenceArray
+
+
Create a new instance of <A extends ReferenceArray> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(long, Constructor<A>, Object...) - Static method in class org.ObjectLayout.ReferenceArray
+
+
Create a new instance of <A extends ReferenceArray<T>> with a given length, + array constructor, and array constructor arguments.
+
+
newInstance(Class<T>, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an array of length elements, each containing an element object of + type elementClass.
+
+
newInstance(MethodHandles.Lookup, Class<T>, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an array of length elements, each containing an element object of + type elementClass.
+
+
newInstance(Class<S>, Class<T>, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an arrayClass array of length elements of + type elementClass.
+
+
newInstance(MethodHandles.Lookup, Class<S>, Class<T>, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an arrayClass array of length elements of + type elementClass.
+
+
newInstance(CtorAndArgs<S>, Class<T>, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length + elements of type elementClass.
+
+
newInstance(MethodHandles.Lookup, CtorAndArgs<S>, Class<T>, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length + elements of type elementClass.
+
+
newInstance(CtorAndArgs<S>, CtorAndArgs<T>, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length + elements of type elementClass.
+
+
newInstance(Class<T>, CtorAndArgsProvider<T>, long) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an array of length elements of type elementClass.
+
+
newInstance(Class<S>, Class<T>, long, CtorAndArgsProvider<T>) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an arrayClass array of length elements, each containing an element object of + type elementClass.
+
+
newInstance(MethodHandles.Lookup, Class<S>, Class<T>, long, CtorAndArgsProvider<T>) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an arrayClass array of length elements, each containing an element object of + type elementClass.
+
+
newInstance(CtorAndArgs<S>, Class<T>, long, CtorAndArgsProvider<T>) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length + elements of type elementClass.
+
+
newInstance(Class<S>, Class<T>, Collection<T>) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create a <S extends StructuredArray<T>> array instance with elements copied from a source + collection.
+
+
newInstance(MethodHandles.Lookup, Class<S>, Class<T>, Collection<T>) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create a <S extends StructuredArray<T>> array instance with elements copied from a source + collection.
+
+
newInstance(StructuredArrayBuilder<S, T>) - Static method in class org.ObjectLayout.StructuredArray
+
+
Create a <S extends StructuredArray<T>> array instance according to the details provided in the + arrayBuilder.
+
+
next() - Method in class org.ObjectLayout.StructuredArray.ElementIterator
+
NO_DECLARED_CLASS() - Constructor for class org.ObjectLayout.Intrinsic.NO_DECLARED_CLASS
+
 
+
NO_LENGTH - Static variable in annotation type org.ObjectLayout.Intrinsic
+
 
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index-files/index-9.html b/JavaDoc/index-files/index-9.html new file mode 100644 index 0000000..bdb5762 --- /dev/null +++ b/JavaDoc/index-files/index-9.html @@ -0,0 +1,127 @@ + + + + + +O-Index + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
A B C E G H I N O P R S  + + +

O

+
+
org.ObjectLayout - package org.ObjectLayout
+
+
ObjectLayout: An optimised memory layout package.
+
+
+A B C E G H I N O P R S 
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/index.html b/JavaDoc/index.html new file mode 100644 index 0000000..57ff9d0 --- /dev/null +++ b/JavaDoc/index.html @@ -0,0 +1,71 @@ + + + + + +Generated Documentation (Untitled) + + + + + + +<noscript> +<div>JavaScript is disabled on your browser.</div> +</noscript> +<h2>Frame Alert</h2> +<p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="org/ObjectLayout/package-summary.html">Non-frame version</a>.</p> + + + diff --git a/JavaDoc/org/ObjectLayout/AbstractPrimitiveArray.html b/JavaDoc/org/ObjectLayout/AbstractPrimitiveArray.html new file mode 100644 index 0000000..d1e122b --- /dev/null +++ b/JavaDoc/org/ObjectLayout/AbstractPrimitiveArray.html @@ -0,0 +1,203 @@ + + + + + +AbstractPrimitiveArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class AbstractPrimitiveArray

+
+
+ +
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/ConstructionContext.html b/JavaDoc/org/ObjectLayout/ConstructionContext.html new file mode 100644 index 0000000..70bfbf9 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/ConstructionContext.html @@ -0,0 +1,344 @@ + + + + + +ConstructionContext + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class ConstructionContext<T>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/CtorAndArgs.html b/JavaDoc/org/ObjectLayout/CtorAndArgs.html new file mode 100644 index 0000000..3f88c35 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/CtorAndArgs.html @@ -0,0 +1,495 @@ + + + + + +CtorAndArgs + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class CtorAndArgs<T>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/CtorAndArgsProvider.html b/JavaDoc/org/ObjectLayout/CtorAndArgsProvider.html new file mode 100644 index 0000000..580e93d --- /dev/null +++ b/JavaDoc/org/ObjectLayout/CtorAndArgsProvider.html @@ -0,0 +1,237 @@ + + + + + +CtorAndArgsProvider + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Interface CtorAndArgsProvider<T>

+
+
+
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/Intrinsic.NO_DECLARED_CLASS.html b/JavaDoc/org/ObjectLayout/Intrinsic.NO_DECLARED_CLASS.html new file mode 100644 index 0000000..c041a2a --- /dev/null +++ b/JavaDoc/org/ObjectLayout/Intrinsic.NO_DECLARED_CLASS.html @@ -0,0 +1,238 @@ + + + + + +Intrinsic.NO_DECLARED_CLASS + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class Intrinsic.NO_DECLARED_CLASS

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/Intrinsic.html b/JavaDoc/org/ObjectLayout/Intrinsic.html new file mode 100644 index 0000000..c388f75 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/Intrinsic.html @@ -0,0 +1,321 @@ + + + + + +Intrinsic + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Annotation Type Intrinsic

+
+
+
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/IntrinsicObjects.html b/JavaDoc/org/ObjectLayout/IntrinsicObjects.html new file mode 100644 index 0000000..3a6a1ca --- /dev/null +++ b/JavaDoc/org/ObjectLayout/IntrinsicObjects.html @@ -0,0 +1,445 @@ + + + + + +IntrinsicObjects + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class IntrinsicObjects

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/IntrinsicProcessor.html b/JavaDoc/org/ObjectLayout/IntrinsicProcessor.html new file mode 100644 index 0000000..7140e3c --- /dev/null +++ b/JavaDoc/org/ObjectLayout/IntrinsicProcessor.html @@ -0,0 +1,313 @@ + + + + + +IntrinsicProcessor + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class IntrinsicProcessor

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/PrimitiveArrayBuilder.html b/JavaDoc/org/ObjectLayout/PrimitiveArrayBuilder.html new file mode 100644 index 0000000..0f5be3f --- /dev/null +++ b/JavaDoc/org/ObjectLayout/PrimitiveArrayBuilder.html @@ -0,0 +1,445 @@ + + + + + +PrimitiveArrayBuilder + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class PrimitiveArrayBuilder<S extends AbstractPrimitiveArray>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/PrimitiveArrayModel.html b/JavaDoc/org/ObjectLayout/PrimitiveArrayModel.html new file mode 100644 index 0000000..1793e1d --- /dev/null +++ b/JavaDoc/org/ObjectLayout/PrimitiveArrayModel.html @@ -0,0 +1,335 @@ + + + + + +PrimitiveArrayModel + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class PrimitiveArrayModel<S extends AbstractPrimitiveArray>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/PrimitiveByteArray.html b/JavaDoc/org/ObjectLayout/PrimitiveByteArray.html new file mode 100644 index 0000000..c72e762 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/PrimitiveByteArray.html @@ -0,0 +1,627 @@ + + + + + +PrimitiveByteArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class PrimitiveByteArray

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/PrimitiveCharArray.html b/JavaDoc/org/ObjectLayout/PrimitiveCharArray.html new file mode 100644 index 0000000..7106e82 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/PrimitiveCharArray.html @@ -0,0 +1,627 @@ + + + + + +PrimitiveCharArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class PrimitiveCharArray

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/PrimitiveDoubleArray.html b/JavaDoc/org/ObjectLayout/PrimitiveDoubleArray.html new file mode 100644 index 0000000..6375f66 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/PrimitiveDoubleArray.html @@ -0,0 +1,627 @@ + + + + + +PrimitiveDoubleArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class PrimitiveDoubleArray

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/PrimitiveFloatArray.html b/JavaDoc/org/ObjectLayout/PrimitiveFloatArray.html new file mode 100644 index 0000000..ce42a07 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/PrimitiveFloatArray.html @@ -0,0 +1,627 @@ + + + + + +PrimitiveFloatArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class PrimitiveFloatArray

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/PrimitiveIntArray.html b/JavaDoc/org/ObjectLayout/PrimitiveIntArray.html new file mode 100644 index 0000000..ffb7fa6 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/PrimitiveIntArray.html @@ -0,0 +1,627 @@ + + + + + +PrimitiveIntArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class PrimitiveIntArray

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/PrimitiveLongArray.html b/JavaDoc/org/ObjectLayout/PrimitiveLongArray.html new file mode 100644 index 0000000..6e2648f --- /dev/null +++ b/JavaDoc/org/ObjectLayout/PrimitiveLongArray.html @@ -0,0 +1,626 @@ + + + + + +PrimitiveLongArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class PrimitiveLongArray

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/PrimitiveShortArray.html b/JavaDoc/org/ObjectLayout/PrimitiveShortArray.html new file mode 100644 index 0000000..085f563 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/PrimitiveShortArray.html @@ -0,0 +1,627 @@ + + + + + +PrimitiveShortArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class PrimitiveShortArray

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/ReferenceArray.html b/JavaDoc/org/ObjectLayout/ReferenceArray.html new file mode 100644 index 0000000..41c4f6b --- /dev/null +++ b/JavaDoc/org/ObjectLayout/ReferenceArray.html @@ -0,0 +1,642 @@ + + + + + +ReferenceArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class ReferenceArray<T>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/StructuredArray.ElementIterator.html b/JavaDoc/org/ObjectLayout/StructuredArray.ElementIterator.html new file mode 100644 index 0000000..b14ad8a --- /dev/null +++ b/JavaDoc/org/ObjectLayout/StructuredArray.ElementIterator.html @@ -0,0 +1,370 @@ + + + + + +StructuredArray.ElementIterator + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class StructuredArray.ElementIterator

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/StructuredArray.html b/JavaDoc/org/ObjectLayout/StructuredArray.html new file mode 100644 index 0000000..be53005 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/StructuredArray.html @@ -0,0 +1,1193 @@ + + + + + +StructuredArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class StructuredArray<T>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/StructuredArrayBuilder.html b/JavaDoc/org/ObjectLayout/StructuredArrayBuilder.html new file mode 100644 index 0000000..91aeb27 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/StructuredArrayBuilder.html @@ -0,0 +1,907 @@ + + + + + +StructuredArrayBuilder + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class StructuredArrayBuilder<S extends StructuredArray<T>,T>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/StructuredArrayModel.html b/JavaDoc/org/ObjectLayout/StructuredArrayModel.html new file mode 100644 index 0000000..e9efa08 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/StructuredArrayModel.html @@ -0,0 +1,475 @@ + + + + + +StructuredArrayModel + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout
+

Class StructuredArrayModel<S extends StructuredArray<T>,T>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/BPlusTree.BPlusTreeIterator.html b/JavaDoc/org/ObjectLayout/examples/BPlusTree.BPlusTreeIterator.html new file mode 100644 index 0000000..b0d8c67 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/BPlusTree.BPlusTreeIterator.html @@ -0,0 +1,323 @@ + + + + + +BPlusTree.BPlusTreeIterator + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class BPlusTree.BPlusTreeIterator

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/BPlusTree.html b/JavaDoc/org/ObjectLayout/examples/BPlusTree.html new file mode 100644 index 0000000..ffef75c --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/BPlusTree.html @@ -0,0 +1,412 @@ + + + + + +BPlusTree + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class BPlusTree<K,V>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/Line.html b/JavaDoc/org/ObjectLayout/examples/Line.html new file mode 100644 index 0000000..1bc951f --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/Line.html @@ -0,0 +1,329 @@ + + + + + +Line + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class Line

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/MassOrder.Builder.html b/JavaDoc/org/ObjectLayout/examples/MassOrder.Builder.html new file mode 100644 index 0000000..51f0e7a --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/MassOrder.Builder.html @@ -0,0 +1,408 @@ + + + + + +MassOrder.Builder + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class MassOrder.Builder

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/MassOrder.html b/JavaDoc/org/ObjectLayout/examples/MassOrder.html new file mode 100644 index 0000000..2846bb4 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/MassOrder.html @@ -0,0 +1,431 @@ + + + + + +MassOrder + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class MassOrder

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/MassOrderExample.html b/JavaDoc/org/ObjectLayout/examples/MassOrderExample.html new file mode 100644 index 0000000..2602508 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/MassOrderExample.html @@ -0,0 +1,269 @@ + + + + + +MassOrderExample + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class MassOrderExample

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/Octagon.html b/JavaDoc/org/ObjectLayout/examples/Octagon.html new file mode 100644 index 0000000..78ac64a --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/Octagon.html @@ -0,0 +1,339 @@ + + + + + +Octagon + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class Octagon

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/Octagons.html b/JavaDoc/org/ObjectLayout/examples/Octagons.html new file mode 100644 index 0000000..d38ff76 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/Octagons.html @@ -0,0 +1,395 @@ + + + + + +Octagons + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class Octagons

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/Point.html b/JavaDoc/org/ObjectLayout/examples/Point.html new file mode 100644 index 0000000..3de3c38 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/Point.html @@ -0,0 +1,350 @@ + + + + + +Point + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class Point

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/PointArray.html b/JavaDoc/org/ObjectLayout/examples/PointArray.html new file mode 100644 index 0000000..2a15678 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/PointArray.html @@ -0,0 +1,351 @@ + + + + + +PointArray + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class PointArray

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/SimpleLine.html b/JavaDoc/org/ObjectLayout/examples/SimpleLine.html new file mode 100644 index 0000000..d82b20b --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/SimpleLine.html @@ -0,0 +1,314 @@ + + + + + +SimpleLine + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class SimpleLine

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/SimpleOrder.OrderType.html b/JavaDoc/org/ObjectLayout/examples/SimpleOrder.OrderType.html new file mode 100644 index 0000000..6b972d5 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/SimpleOrder.OrderType.html @@ -0,0 +1,343 @@ + + + + + +SimpleOrder.OrderType + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Enum SimpleOrder.OrderType

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/SimpleOrder.Side.html b/JavaDoc/org/ObjectLayout/examples/SimpleOrder.Side.html new file mode 100644 index 0000000..a3f33f5 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/SimpleOrder.Side.html @@ -0,0 +1,343 @@ + + + + + +SimpleOrder.Side + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Enum SimpleOrder.Side

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/SimpleOrder.html b/JavaDoc/org/ObjectLayout/examples/SimpleOrder.html new file mode 100644 index 0000000..e93ed2e --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/SimpleOrder.html @@ -0,0 +1,419 @@ + + + + + +SimpleOrder + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class SimpleOrder

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/StructuredArrayOfAtomicLong.html b/JavaDoc/org/ObjectLayout/examples/StructuredArrayOfAtomicLong.html new file mode 100644 index 0000000..550193c --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/StructuredArrayOfAtomicLong.html @@ -0,0 +1,333 @@ + + + + + +StructuredArrayOfAtomicLong + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class StructuredArrayOfAtomicLong

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/TwoDimPointMatrix.html b/JavaDoc/org/ObjectLayout/examples/TwoDimPointMatrix.html new file mode 100644 index 0000000..96bb0a6 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/TwoDimPointMatrix.html @@ -0,0 +1,373 @@ + + + + + +TwoDimPointMatrix + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples
+

Class TwoDimPointMatrix

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/package-frame.html b/JavaDoc/org/ObjectLayout/examples/package-frame.html new file mode 100644 index 0000000..e614e08 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/package-frame.html @@ -0,0 +1,37 @@ + + + + + +org.ObjectLayout.examples + + + + + +

org.ObjectLayout.examples

+
+

Classes

+ +

Enums

+ +
+ + diff --git a/JavaDoc/org/ObjectLayout/examples/package-summary.html b/JavaDoc/org/ObjectLayout/examples/package-summary.html new file mode 100644 index 0000000..9c2d9ff --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/package-summary.html @@ -0,0 +1,219 @@ + + + + + +org.ObjectLayout.examples + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Package org.ObjectLayout.examples

+
+
+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/package-tree.html b/JavaDoc/org/ObjectLayout/examples/package-tree.html new file mode 100644 index 0000000..d1d9e74 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/package-tree.html @@ -0,0 +1,165 @@ + + + + + +org.ObjectLayout.examples Class Hierarchy + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Hierarchy For Package org.ObjectLayout.examples

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +

Enum Hierarchy

+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/util/SAAbstractMap.SimpleEntry.html b/JavaDoc/org/ObjectLayout/examples/util/SAAbstractMap.SimpleEntry.html new file mode 100644 index 0000000..ec6ec77 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/util/SAAbstractMap.SimpleEntry.html @@ -0,0 +1,491 @@ + + + + + +SAAbstractMap.SimpleEntry + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples.util
+

Class SAAbstractMap.SimpleEntry<K,V>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/util/SAAbstractMap.SimpleImmutableEntry.html b/JavaDoc/org/ObjectLayout/examples/util/SAAbstractMap.SimpleImmutableEntry.html new file mode 100644 index 0000000..9040e78 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/util/SAAbstractMap.SimpleImmutableEntry.html @@ -0,0 +1,493 @@ + + + + + +SAAbstractMap.SimpleImmutableEntry + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples.util
+

Class SAAbstractMap.SimpleImmutableEntry<K,V>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/util/SAAbstractMap.html b/JavaDoc/org/ObjectLayout/examples/util/SAAbstractMap.html new file mode 100644 index 0000000..fc8d6d4 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/util/SAAbstractMap.html @@ -0,0 +1,638 @@ + + + + + +SAAbstractMap + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples.util
+

Class SAAbstractMap<K,V>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/util/SAHashMap.html b/JavaDoc/org/ObjectLayout/examples/util/SAHashMap.html new file mode 100644 index 0000000..2a3e7a5 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/util/SAHashMap.html @@ -0,0 +1,1090 @@ + + + + + +SAHashMap + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + + +
+
org.ObjectLayout.examples.util
+

Class SAHashMap<K,V>

+
+
+ +
+ +
+
+ +
+
+ +
+
+ + +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/util/package-frame.html b/JavaDoc/org/ObjectLayout/examples/util/package-frame.html new file mode 100644 index 0000000..7215366 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/util/package-frame.html @@ -0,0 +1,23 @@ + + + + + +org.ObjectLayout.examples.util + + + + + +

org.ObjectLayout.examples.util

+
+

Classes

+ +
+ + diff --git a/JavaDoc/org/ObjectLayout/examples/util/package-summary.html b/JavaDoc/org/ObjectLayout/examples/util/package-summary.html new file mode 100644 index 0000000..ec42b88 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/util/package-summary.html @@ -0,0 +1,161 @@ + + + + + +org.ObjectLayout.examples.util + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Package org.ObjectLayout.examples.util

+
+
+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/examples/util/package-tree.html b/JavaDoc/org/ObjectLayout/examples/util/package-tree.html new file mode 100644 index 0000000..30cea4b --- /dev/null +++ b/JavaDoc/org/ObjectLayout/examples/util/package-tree.html @@ -0,0 +1,141 @@ + + + + + +org.ObjectLayout.examples.util Class Hierarchy + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Hierarchy For Package org.ObjectLayout.examples.util

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/package-frame.html b/JavaDoc/org/ObjectLayout/package-frame.html new file mode 100644 index 0000000..0fe76eb --- /dev/null +++ b/JavaDoc/org/ObjectLayout/package-frame.html @@ -0,0 +1,46 @@ + + + + + +org.ObjectLayout + + + + + +

org.ObjectLayout

+
+

Interfaces

+ +

Classes

+ +

Annotation Types

+ +
+ + diff --git a/JavaDoc/org/ObjectLayout/package-summary.html b/JavaDoc/org/ObjectLayout/package-summary.html new file mode 100644 index 0000000..edbb392 --- /dev/null +++ b/JavaDoc/org/ObjectLayout/package-summary.html @@ -0,0 +1,344 @@ + + + + + +org.ObjectLayout + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Package org.ObjectLayout

+
+
ObjectLayout: An optimised memory layout package.
+
+

See: Description

+
+
+ + + + +

Package org.ObjectLayout Description

+

ObjectLayout: An optimised memory layout package.

+

+ The ObjectLayout package provides some key data structure classes designed with optimised memory layout + in mind. These classes are aimed at matching the natural speed benefits similar data structure + constructs enable in most C-style languages, while maintaining an idiomatic Java feel and a natural + fit with existing code and libraries. +

+ The package classes provide full functionality on all JVMs (of Java SE 5 or above) at reasonable layouts + and execution speeds. However, the classes are carefully designed with semantics that would allow an + optimised JVM to implement them with improved memory layout not directly expressible in Java. +

+ The StructuredArray class is a good example of this design pattern. + StructuredArray is carefully designed to allow a JVM to store it in memory with a layout similar to + an array of structs in C-like languages. When a JVM optimises StructuredArray in such a way, array + access benefits from both direct (as opposed to de-referenced) dead-reckoning index access, as well + as from fixed memory strides during streaming operations. +

+ The three commonly used C-style container layout forms that ObjectLayout seeks to enable in Java are: +

+

+ The speed benefits in these three forms of layout derive from two dominant benefits: +

    +
  1. 1. Dead reckoning: In all three forms, the address of the target data field accessed + through the containing object can be directly derived from the containing object reference + without a data-dependent load operation (no de-referencing or equivalent operation needed).
  2. +
  3. 2. Streaming: In the case of an array of structs, sequential access through multiple members + of the containing array result in predictable striding access in memory, enabling prefetch logic + (hardware assisted or otherwise) to compensate for much of the latency involved in cache misses.
  4. +
+

The matching ObjectLayout forms

+

+ StructuredArray provides an idiomatic Java collection form + with speed (and semantics) similar to an "array of structs" form, supporting any constructable + java Object as an array member. +

+ @Intrinsic provides an idiomatic Java means for declaring + member objects that are intrinsic to the instances of the class they are declared in. + @Intrinsic provides a "struct in struct" equivalent + relationship between Java objects, exposing the speed and layout benefits similar to the same + form in the C family languages. +

+ Sub-classable Primitive and Reference array classes (e.g. PrimitiveLongArray + and ReferenceArray) provide an idiomatic Java means of + declaring constructs with speed (and semantics) similar to "struct with array at the end". They do + so by supporting the subclassing of arrays of the various primitive and reference forms possible + in Java. StructuredArray similarly supports this capability (via + subclassing) for the equivalent of "struct with array of structs at the end".

+
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/org/ObjectLayout/package-tree.html b/JavaDoc/org/ObjectLayout/package-tree.html new file mode 100644 index 0000000..8b6c23c --- /dev/null +++ b/JavaDoc/org/ObjectLayout/package-tree.html @@ -0,0 +1,163 @@ + + + + + +org.ObjectLayout Class Hierarchy + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Hierarchy For Package org.ObjectLayout

+
+
+

Class Hierarchy

+ +

Interface Hierarchy

+ +

Annotation Type Hierarchy

+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/overview-frame.html b/JavaDoc/overview-frame.html new file mode 100644 index 0000000..30d0448 --- /dev/null +++ b/JavaDoc/overview-frame.html @@ -0,0 +1,24 @@ + + + + + +Overview List + + + + + +
All Classes
+
+

Packages

+ +
+

 

+ + diff --git a/JavaDoc/overview-summary.html b/JavaDoc/overview-summary.html new file mode 100644 index 0000000..4749cc7 --- /dev/null +++ b/JavaDoc/overview-summary.html @@ -0,0 +1,147 @@ + + + + + +Overview + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Packages 
PackageDescription
bench 
org.ObjectLayout +
ObjectLayout: An optimised memory layout package.
+
org.ObjectLayout.examples 
org.ObjectLayout.examples.util 
+
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/overview-tree.html b/JavaDoc/overview-tree.html new file mode 100644 index 0000000..a789cb6 --- /dev/null +++ b/JavaDoc/overview-tree.html @@ -0,0 +1,167 @@ + + + + + +Class Hierarchy + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Hierarchy For All Packages

+Package Hierarchies: + +
+
+

Class Hierarchy

+ +

Interface Hierarchy

+ +

Annotation Type Hierarchy

+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/package-list b/JavaDoc/package-list new file mode 100644 index 0000000..f5ba0e8 --- /dev/null +++ b/JavaDoc/package-list @@ -0,0 +1 @@ +org.ObjectLayout diff --git a/JavaDoc/script.js b/JavaDoc/script.js new file mode 100644 index 0000000..b346356 --- /dev/null +++ b/JavaDoc/script.js @@ -0,0 +1,30 @@ +function show(type) +{ + count = 0; + for (var key in methods) { + var row = document.getElementById(key); + if ((methods[key] & type) != 0) { + row.style.display = ''; + row.className = (count++ % 2) ? rowColor : altColor; + } + else + row.style.display = 'none'; + } + updateTabs(type); +} + +function updateTabs(type) +{ + for (var value in tabs) { + var sNode = document.getElementById(tabs[value][0]); + var spanNode = sNode.firstChild; + if (value == type) { + sNode.className = activeTableTab; + spanNode.innerHTML = tabs[value][1]; + } + else { + sNode.className = tableTab; + spanNode.innerHTML = "" + tabs[value][1] + ""; + } + } +} diff --git a/JavaDoc/serialized-form.html b/JavaDoc/serialized-form.html new file mode 100644 index 0000000..7b887de --- /dev/null +++ b/JavaDoc/serialized-form.html @@ -0,0 +1,240 @@ + + + + + +Serialized Form + + + + + + + + +
+ + +
Skip navigation links
+ + + + +
+ + +
+

Serialized Form

+
+
+ +
+ +
+ + +
Skip navigation links
+ + + + +
+ + + + diff --git a/JavaDoc/stylesheet.css b/JavaDoc/stylesheet.css new file mode 100644 index 0000000..cebb4fd --- /dev/null +++ b/JavaDoc/stylesheet.css @@ -0,0 +1,574 @@ +/* Javadoc style sheet */ +/* +Overall document style +*/ + +@import url('resources/fonts/dejavu.css'); + +body { + background-color:#ffffff; + color:#353833; + font-family:'DejaVu Sans', Arial, Helvetica, sans-serif; + font-size:14px; + margin:0; +} +a:link, a:visited { + text-decoration:none; + color:#4A6782; +} +a:hover, a:focus { + text-decoration:none; + color:#bb7a2a; +} +a:active { + text-decoration:none; + color:#4A6782; +} +a[name] { + color:#353833; +} +a[name]:hover { + text-decoration:none; + color:#353833; +} +pre { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; +} +h1 { + font-size:20px; +} +h2 { + font-size:18px; +} +h3 { + font-size:16px; + font-style:italic; +} +h4 { + font-size:13px; +} +h5 { + font-size:12px; +} +h6 { + font-size:11px; +} +ul { + list-style-type:disc; +} +code, tt { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; + margin-top:8px; + line-height:1.4em; +} +dt code { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + padding-top:4px; +} +table tr td dt code { + font-family:'DejaVu Sans Mono', monospace; + font-size:14px; + vertical-align:top; + padding-top:4px; +} +sup { + font-size:8px; +} +/* +Document title and Copyright styles +*/ +.clear { + clear:both; + height:0px; + overflow:hidden; +} +.aboutLanguage { + float:right; + padding:0px 21px; + font-size:11px; + z-index:200; + margin-top:-9px; +} +.legalCopy { + margin-left:.5em; +} +.bar a, .bar a:link, .bar a:visited, .bar a:active { + color:#FFFFFF; + text-decoration:none; +} +.bar a:hover, .bar a:focus { + color:#bb7a2a; +} +.tab { + background-color:#0066FF; + color:#ffffff; + padding:8px; + width:5em; + font-weight:bold; +} +/* +Navigation bar styles +*/ +.bar { + background-color:#4D7A97; + color:#FFFFFF; + padding:.8em .5em .4em .8em; + height:auto;/*height:1.8em;*/ + font-size:11px; + margin:0; +} +.topNav { + background-color:#4D7A97; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; + font-size:12px; +} +.bottomNav { + margin-top:10px; + background-color:#4D7A97; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; + font-size:12px; +} +.subNav { + background-color:#dee3e9; + float:left; + width:100%; + overflow:hidden; + font-size:12px; +} +.subNav div { + clear:left; + float:left; + padding:0 0 5px 6px; + text-transform:uppercase; +} +ul.navList, ul.subNavList { + float:left; + margin:0 25px 0 0; + padding:0; +} +ul.navList li{ + list-style:none; + float:left; + padding: 5px 6px; + text-transform:uppercase; +} +ul.subNavList li{ + list-style:none; + float:left; +} +.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited { + color:#FFFFFF; + text-decoration:none; + text-transform:uppercase; +} +.topNav a:hover, .bottomNav a:hover { + text-decoration:none; + color:#bb7a2a; + text-transform:uppercase; +} +.navBarCell1Rev { + background-color:#F8981D; + color:#253441; + margin: auto 5px; +} +.skipNav { + position:absolute; + top:auto; + left:-9999px; + overflow:hidden; +} +/* +Page header and footer styles +*/ +.header, .footer { + clear:both; + margin:0 20px; + padding:5px 0 0 0; +} +.indexHeader { + margin:10px; + position:relative; +} +.indexHeader span{ + margin-right:15px; +} +.indexHeader h1 { + font-size:13px; +} +.title { + color:#2c4557; + margin:10px 0; +} +.subTitle { + margin:5px 0 0 0; +} +.header ul { + margin:0 0 15px 0; + padding:0; +} +.footer ul { + margin:20px 0 5px 0; +} +.header ul li, .footer ul li { + list-style:none; + font-size:13px; +} +/* +Heading styles +*/ +div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 { + background-color:#dee3e9; + border:1px solid #d0d9e0; + margin:0 0 6px -8px; + padding:7px 5px; +} +ul.blockList ul.blockList ul.blockList li.blockList h3 { + background-color:#dee3e9; + border:1px solid #d0d9e0; + margin:0 0 6px -8px; + padding:7px 5px; +} +ul.blockList ul.blockList li.blockList h3 { + padding:0; + margin:15px 0; +} +ul.blockList li.blockList h2 { + padding:0px 0 20px 0; +} +/* +Page layout container styles +*/ +.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer { + clear:both; + padding:10px 20px; + position:relative; +} +.indexContainer { + margin:10px; + position:relative; + font-size:12px; +} +.indexContainer h2 { + font-size:13px; + padding:0 0 3px 0; +} +.indexContainer ul { + margin:0; + padding:0; +} +.indexContainer ul li { + list-style:none; + padding-top:2px; +} +.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt { + font-size:12px; + font-weight:bold; + margin:10px 0 0 0; + color:#4E4E4E; +} +.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { + margin:5px 0 10px 0px; + font-size:14px; + font-family:'DejaVu Sans Mono',monospace; +} +.serializedFormContainer dl.nameValue dt { + margin-left:1px; + font-size:1.1em; + display:inline; + font-weight:bold; +} +.serializedFormContainer dl.nameValue dd { + margin:0 0 0 1px; + font-size:1.1em; + display:inline; +} +/* +List styles +*/ +ul.horizontal li { + display:inline; + font-size:0.9em; +} +ul.inheritance { + margin:0; + padding:0; +} +ul.inheritance li { + display:inline; + list-style:none; +} +ul.inheritance li ul.inheritance { + margin-left:15px; + padding-left:15px; + padding-top:1px; +} +ul.blockList, ul.blockListLast { + margin:10px 0 10px 0; + padding:0; +} +ul.blockList li.blockList, ul.blockListLast li.blockList { + list-style:none; + margin-bottom:15px; + line-height:1.4; +} +ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList { + padding:0px 20px 5px 10px; + border:1px solid #ededed; + background-color:#f8f8f8; +} +ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList { + padding:0 0 5px 8px; + background-color:#ffffff; + border:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockList { + margin-left:0; + padding-left:0; + padding-bottom:15px; + border:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast { + list-style:none; + border-bottom:none; + padding-bottom:0; +} +table tr td dl, table tr td dl dt, table tr td dl dd { + margin-top:0; + margin-bottom:1px; +} +/* +Table styles +*/ +.overviewSummary, .memberSummary, .typeSummary, .useSummary, .constantsSummary, .deprecatedSummary { + width:100%; + border-left:1px solid #EEE; + border-right:1px solid #EEE; + border-bottom:1px solid #EEE; +} +.overviewSummary, .memberSummary { + padding:0px; +} +.overviewSummary caption, .memberSummary caption, .typeSummary caption, +.useSummary caption, .constantsSummary caption, .deprecatedSummary caption { + position:relative; + text-align:left; + background-repeat:no-repeat; + color:#253441; + font-weight:bold; + clear:none; + overflow:hidden; + padding:0px; + padding-top:10px; + padding-left:1px; + margin:0px; + white-space:pre; +} +.overviewSummary caption a:link, .memberSummary caption a:link, .typeSummary caption a:link, +.useSummary caption a:link, .constantsSummary caption a:link, .deprecatedSummary caption a:link, +.overviewSummary caption a:hover, .memberSummary caption a:hover, .typeSummary caption a:hover, +.useSummary caption a:hover, .constantsSummary caption a:hover, .deprecatedSummary caption a:hover, +.overviewSummary caption a:active, .memberSummary caption a:active, .typeSummary caption a:active, +.useSummary caption a:active, .constantsSummary caption a:active, .deprecatedSummary caption a:active, +.overviewSummary caption a:visited, .memberSummary caption a:visited, .typeSummary caption a:visited, +.useSummary caption a:visited, .constantsSummary caption a:visited, .deprecatedSummary caption a:visited { + color:#FFFFFF; +} +.overviewSummary caption span, .memberSummary caption span, .typeSummary caption span, +.useSummary caption span, .constantsSummary caption span, .deprecatedSummary caption span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + padding-bottom:7px; + display:inline-block; + float:left; + background-color:#F8981D; + border: none; + height:16px; +} +.memberSummary caption span.activeTableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#F8981D; + height:16px; +} +.memberSummary caption span.tableTab span { + white-space:nowrap; + padding-top:5px; + padding-left:12px; + padding-right:12px; + margin-right:3px; + display:inline-block; + float:left; + background-color:#4D7A97; + height:16px; +} +.memberSummary caption span.tableTab, .memberSummary caption span.activeTableTab { + padding-top:0px; + padding-left:0px; + padding-right:0px; + background-image:none; + float:none; + display:inline; +} +.overviewSummary .tabEnd, .memberSummary .tabEnd, .typeSummary .tabEnd, +.useSummary .tabEnd, .constantsSummary .tabEnd, .deprecatedSummary .tabEnd { + display:none; + width:5px; + position:relative; + float:left; + background-color:#F8981D; +} +.memberSummary .activeTableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + float:left; + background-color:#F8981D; +} +.memberSummary .tableTab .tabEnd { + display:none; + width:5px; + margin-right:3px; + position:relative; + background-color:#4D7A97; + float:left; + +} +.overviewSummary td, .memberSummary td, .typeSummary td, +.useSummary td, .constantsSummary td, .deprecatedSummary td { + text-align:left; + padding:0px 0px 12px 10px; + width:100%; +} +th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th, +td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{ + vertical-align:top; + padding-right:0px; + padding-top:8px; + padding-bottom:3px; +} +th.colFirst, th.colLast, th.colOne, .constantsSummary th { + background:#dee3e9; + text-align:left; + padding:8px 3px 3px 7px; +} +td.colFirst, th.colFirst { + white-space:nowrap; + font-size:13px; +} +td.colLast, th.colLast { + font-size:13px; +} +td.colOne, th.colOne { + font-size:13px; +} +.overviewSummary td.colFirst, .overviewSummary th.colFirst, +.overviewSummary td.colOne, .overviewSummary th.colOne, +.memberSummary td.colFirst, .memberSummary th.colFirst, +.memberSummary td.colOne, .memberSummary th.colOne, +.typeSummary td.colFirst{ + width:25%; + vertical-align:top; +} +td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { + font-weight:bold; +} +.tableSubHeadingColor { + background-color:#EEEEFF; +} +.altColor { + background-color:#FFFFFF; +} +.rowColor { + background-color:#EEEEEF; +} +/* +Content styles +*/ +.description pre { + margin-top:0; +} +.deprecatedContent { + margin:0; + padding:10px 0; +} +.docSummary { + padding:0; +} + +ul.blockList ul.blockList ul.blockList li.blockList h3 { + font-style:normal; +} + +div.block { + font-size:14px; + font-family:'DejaVu Serif', Georgia, "Times New Roman", Times, serif; +} + +td.colLast div { + padding-top:0px; +} + + +td.colLast a { + padding-bottom:3px; +} +/* +Formatting effect styles +*/ +.sourceLineNo { + color:green; + padding:0 30px 0 0; +} +h1.hidden { + visibility:hidden; + overflow:hidden; + font-size:10px; +} +.block { + display:block; + margin:3px 10px 2px 0px; + color:#474747; +} +.deprecatedLabel, .descfrmTypeLabel, .memberNameLabel, .memberNameLink, +.overrideSpecifyLabel, .packageHierarchyLabel, .paramLabel, .returnLabel, +.seeLabel, .simpleTagLabel, .throwsLabel, .typeNameLabel, .typeNameLink { + font-weight:bold; +} +.deprecationComment, .emphasizedPhrase, .interfaceName { + font-style:italic; +} + +div.block div.block span.deprecationComment, div.block div.block span.emphasizedPhrase, +div.block div.block span.interfaceName { + font-style:normal; +} + +div.contentContainer ul.blockList li.blockList h2{ + padding-bottom:0px; +} diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index d593d5b..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,13 +0,0 @@ -Please view the LICENSE or LICENSE.txt files in the individual project -directories for license details. - -Some of the directories sub-projects under this repository (e.g. -the main ObjectLayout project with the org.ObjectLayout source) -are both placed in the public domain and licensed under a BSD -2-clause license. - -However, since some of the examples in the ObjectLayout-examples -project were ported from OpenJDK 8, those examples carry the -related GPLv2+CPE OpenJDK license. See details in the LICENSE -files in the specific subdirectories under the ObjectLayout-examples -source tree. diff --git a/ObjectLayout-benchmarks/LICENSE.txt b/ObjectLayout-benchmarks/LICENSE.txt deleted file mode 100644 index 06f48d0..0000000 --- a/ObjectLayout-benchmarks/LICENSE.txt +++ /dev/null @@ -1,41 +0,0 @@ -The code in this directory was Written by Gil Tene -Martin Thompson, and Michael Barker and released to the public domain, -as explained at http://creativecommons.org/publicdomain/zero/1.0/ - -For users of this code who wish to consume it under the "BSD" license -rather than under the public domain or CC0 contribution text mentioned -above, the code found under this directory is *also* provided under the -following license (commonly referred to as the BSD 2-Clause License). This -license does not detract from the above stated release of the code into -the public domain, and simply represents an additional license granted by -the Author. - ------------------------------------------------------------------------------ -** Beginning of "BSD 2-Clause License" text. ** - - Copyright (c) 2012, 2013, 2014, 2015 Gil Tene - Copyright (c) 2014, 2014, 2015 Michael Barker - Copyright (c) 2012, 2013, 2014 Martin Thompson - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ObjectLayout-benchmarks/pom.xml b/ObjectLayout-benchmarks/pom.xml deleted file mode 100644 index 10042a3..0000000 --- a/ObjectLayout-benchmarks/pom.xml +++ /dev/null @@ -1,116 +0,0 @@ - - - 4.0.0 - - - org.objectlayout - ObjectLayout-parent - 1.0.5-SNAPSHOT - - - ObjectLayout-benchmarks - ObjectLayoutBenchmarks - jar - - - UTF-8 - - - - - junit - junit - 4.13.1 - test - - - org.openjdk.jmh - jmh-core - 1.10.5 - - - org.openjdk.jmh - jmh-generator-annprocess - 1.10.5 - - - org.objectlayout - ObjectLayout - ${project.version} - - - org.objectlayout - ObjectLayout-examples - ${project.version} - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.7 - - - add-test-source - generate-test-sources - - add-test-source - - - - src/examples/java - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.6 - 1.6 - UTF-8 - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12.4 - - -Xmx1g - false - - - - - org.apache.maven.plugins - maven-shade-plugin - 2.2 - - - package - - shade - - - true - benchmarks - - - org.openjdk.jmh.Main - - - - - - - - - - diff --git a/ObjectLayout-benchmarks/src/main/java/bench/ObjectLayoutBench.java b/ObjectLayout-benchmarks/src/main/java/bench/ObjectLayoutBench.java deleted file mode 100644 index 0fa1d70..0000000 --- a/ObjectLayout-benchmarks/src/main/java/bench/ObjectLayoutBench.java +++ /dev/null @@ -1,479 +0,0 @@ -package bench; - -import java.lang.reflect.Constructor; -import java.util.Random; -import java.util.concurrent.TimeUnit; - -import org.ObjectLayout.ConstructionContext; -import org.ObjectLayout.CtorAndArgs; -import org.ObjectLayout.CtorAndArgsProvider; -import org.ObjectLayout.StructuredArray; - -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Measurement; -import org.openjdk.jmh.annotations.Param; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.Warmup; -import org.openjdk.jmh.infra.Blackhole; - -/* - This benchmark creates a one-dimensional array of objects in the following ways: - - Structured array - - Encapsulated Java array - - Encapsulated Java array that references the corresponding elements of the previously created - structured array. This is to ensure that the memory access pattern will be the same as for - the structured array. - - Encapsulated Java array declared with the use of generics - - Encapsulated Java array declared with the use of generics that references the corresponding - elements of the previously created structured array. This is to ensure that the memory access - pattern will be the same as for the structured array. - - Encapsulated Java array with shuffled elements. This is to mimic the layout of elements in - arrays after many GC cycles when elements are referenced from multiple objects. In real life - application we are more likely to see partial re-order. - - For all these arrays this benchmark loops over all elements and does some operation. - The reported score is the number of operations per second, higher is better. - - There are several parameters to tune this benchmark. - - LengthPow2 - Log-Base-Two of the number of elements in each array - - RandomArrayWalk - When false, the main loop accesses elements in an array in the sequential - order. When true, elements are accessed in an order that is a random cyclic permutation - of the sequential order. - - Run all benchmarks: - $ java -jar target/benchmarks.jar - - Run selected benchmarks: - $ java -jar target/benchmarks.jar (regexp) - - Run the profiling (Linux only): - $ java -Djmh.perfasm.events=cycles,cache-misses -jar target/benchmarks.jar -f 1 -prof perfasm -*/ - -@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) -@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) -@Fork(5) -@State(Scope.Thread) - -public class ObjectLayoutBench { - @Param({"20"}) - public int LengthPow2; - - @Param({"false", "true"}) - public boolean RandomArrayWalk; - - private static final int shufflingSeed = 37; - private static final int randomizingSeed = 53; - - private int length; - private int lengthMask; - - private BasicArray basicArrayDifferentLayout; - private BasicArray basicArraySameLayout; - private GenericArray genericArrayDifferentLayout; - private GenericArray genericArraySameLayout; - private RandomizedBasicArray randomizedBasicArray; - private StructuredArray structuredArray; - - private int[] linearNextIndexes; - private int[] shuffledNextIndexes; - - private Blackhole blackhole = new Blackhole(); - - @Setup - public void setup() throws NoSuchMethodException { - length = 1 << LengthPow2; - lengthMask = length - 1; - - initNextIndexes(); - - final Object[] args = new Object[2]; - final CtorAndArgs ctorAndArgs = new CtorAndArgs( - Element.class.getConstructor(Element.constructorArgTypes_Long_IntArray), args); - CtorAndArgsProvider ctorAndArgsProvider = - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext(ConstructionContext context) - throws NoSuchMethodException { - args[0] = context.getIndex(); - args[1] = RandomArrayWalk ? shuffledNextIndexes : linearNextIndexes; - return ctorAndArgs; - } - }; - structuredArray = StructuredArray.newInstance(Element.class, ctorAndArgsProvider, length); - - basicArrayDifferentLayout = new BasicArray(length, - RandomArrayWalk ? shuffledNextIndexes : linearNextIndexes); - basicArraySameLayout = new BasicArray(structuredArray); - genericArrayDifferentLayout = new GenericArray( - Element.class.getConstructor(Element.constructorArgTypes_Long_IntArray), - length, RandomArrayWalk ? shuffledNextIndexes : linearNextIndexes); - genericArraySameLayout = new GenericArray(structuredArray); - randomizedBasicArray = new RandomizedBasicArray(length, - RandomArrayWalk ? shuffledNextIndexes : linearNextIndexes); - } - - private void initNextIndexes() { - linearNextIndexes = new int[length]; - for (int i = 0; i < length - 1; i++) { - linearNextIndexes[i] = i + 1; - } - linearNextIndexes[length - 1] = 0; - - shuffledNextIndexes = new int[length]; - int[] visitOrder = new int[length]; - Random generator = new Random(shufflingSeed); - for (int i = 0; i < length; i++) { - visitOrder[i] = i; - } - for (int i = length - 1; i > 0; i--) { - int j = generator.nextInt(i + 1); - int temp = visitOrder[i]; - visitOrder[i] = visitOrder[j]; - visitOrder[j] = temp; - } - for (int i = 0; i < length - 1; i++) { - shuffledNextIndexes[visitOrder[i]] = visitOrder[i + 1]; - } - shuffledNextIndexes[visitOrder[length - 1]] = visitOrder[0]; - } - - private static int getSequenceLength(Element[] a) { - int length = a.length; - boolean visited[] = new boolean[length]; - int index = 0; - int sequenceLength = 0; - for (int i = 0; i < length; i++) { - int prevIndex = index; - index = a[index].getNextIndex(); - if (visited[index]) { - break; - } - sequenceLength++; - visited[index] = true; - } - return sequenceLength; - } - - private static int getSequenceLength(StructuredArray sa) { - int length = (int) sa.getLength(); - boolean visited[] = new boolean[length]; - int index = 0; - int sequenceLength = 0; - for (int i = 0; i < length; i++) { - int prevIndex = index; - index = sa.get(index).getNextIndex(); - if (visited[index]) { - break; - } - sequenceLength++; - visited[index] = true; - } - return sequenceLength; - } - - // Benchmarks for basic arrays - - @Benchmark - public void basicArrayDifferentLayoutDataDependentLoop() { - long accumulator = 0; - int index = 0; - int length = basicArrayDifferentLayout.getLength(); - for (int i = 0; i < length; i++) { - int nextIndex = basicArrayDifferentLayout.get(index).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - index = nextIndex; - } - blackhole.consume(accumulator); - } - - @Benchmark - public void basicArrayDifferentLayoutLoop() { - long accumulator = 0; - int length = basicArrayDifferentLayout.getLength(); - for (int i = 0; i < length; i++) { - int nextIndex = basicArrayDifferentLayout.get(i).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - } - blackhole.consume(accumulator); - } - - @Benchmark - public void basicArraySameLayoutDataDependentLoop() { - long accumulator = 0; - int index = 0; - int length = basicArraySameLayout.getLength(); - for (int i = 0; i < length; i++) { - int nextIndex = basicArraySameLayout.get(index).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - index = nextIndex; - } - blackhole.consume(accumulator); - } - - @Benchmark - public void basicArraySameLayoutLoop() { - long accumulator = 0; - int length = basicArraySameLayout.getLength(); - for (int i = 0; i < length; i++) { - int nextIndex = basicArraySameLayout.get(i).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - } - blackhole.consume(accumulator); - } - - // Benchmarks for generic arrays - - @Benchmark - public void genericArrayDifferentLayoutDataDependentLoop() { - long accumulator = 0; - int index = 0; - int length = genericArrayDifferentLayout.getLength(); - for (int i = 0; i < length; i++) { - int nextIndex = genericArrayDifferentLayout.get(index).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - index = nextIndex; - } - blackhole.consume(accumulator); - } - - @Benchmark - public void genericArrayDifferentLayoutLoop() { - long accumulator = 0; - int length = genericArrayDifferentLayout.getLength(); - for (int i = 0; i < length; i++) { - int nextIndex = genericArrayDifferentLayout.get(i).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - } - blackhole.consume(accumulator); - } - - @Benchmark - public void genericArraySameLayoutDataDependentLoop() { - long accumulator = 0; - int index = 0; - int length = genericArraySameLayout.getLength(); - for (int i = 0; i < length; i++) { - int nextIndex = genericArraySameLayout.get(index).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - index = nextIndex; - } - blackhole.consume(accumulator); - } - - @Benchmark - public void genericArraySameLayoutLoop() { - long accumulator = 0; - int length = genericArraySameLayout.getLength(); - for (int i = 0; i < length; i++) { - int nextIndex = genericArraySameLayout.get(i).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - } - blackhole.consume(accumulator); - } - - // Benchmarks for randomized basic arrays - - @Benchmark - public void randomizedBasicArrayDataDependentLoop() { - long accumulator = 0; - int index = 0; - int length = randomizedBasicArray.getLength(); - for (int i = 0; i < length; i++) { - int nextIndex = randomizedBasicArray.get(index).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - index = nextIndex; - } - blackhole.consume(accumulator); - } - - @Benchmark - public void randomizedBasicArrayLoop() { - long accumulator = 0; - int length = randomizedBasicArray.getLength(); - for (int i = 0; i < length; i++) { - int nextIndex = randomizedBasicArray.get(i).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - } - blackhole.consume(accumulator); - } - - // Benchmarks for structured arrays - - @Benchmark - public void structuredArrayDataDependentLoop() { - long accumulator = 0; - int index = 0; - long length = structuredArray.getLength(); - for (long i = 0; i < length; i++) { - int nextIndex = structuredArray.get(index).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - index = nextIndex; - } - blackhole.consume(accumulator); - } - - @Benchmark - public void structuredArrayLoop() { - long accumulator = 0; - long length = structuredArray.getLength(); - for (long i = 0; i < length; i++) { - int nextIndex = structuredArray.get(i).getNextIndex(); - accumulator = doSimpleMath(accumulator, nextIndex); - } - blackhole.consume(accumulator); - } - - // End of benchmarks - - private static long doSimpleMath(long param1, int param2) { - return param1 ^ param2; - } - - public static class ElementBase { - private long index = -1; - private int nextIndex = -1; - - public ElementBase(long index, int[] nextIndexes) { - this.index = index; - this.nextIndex = nextIndexes[(int) index]; - } - - public ElementBase(ElementBase src) { - this.index = src.index; - this.nextIndex = src.nextIndex; - } - - public long getIndex() { - return index; - } - - public void setIndex(long index) { - this.index = index; - } - - public int getNextIndex() { - return nextIndex; - } - - public void setNextIndex(int nextIndex) { - this.nextIndex = nextIndex; - } - } - - public static class Element extends ElementBase { - static final Class[] constructorArgTypes_Long_IntArray = { long.class, int[].class }; - static final Class[] constructorArgTypes_Element = { Element.class }; - - // Padding elements to make sure that each element is greater than - // 2 x L1 D-Cache line - private long l0, l1, l2, l3, l4, l5, l6, l7; - private long l8, l9, l10, l11, l12, l13, l14, l15; - - public Element(long index, int[] nextIndexes) { - super(index, nextIndexes); - } - - public Element(Element src) { - super(src); - } - } - - public static class BasicArray { - private Element[] array; - - public BasicArray(int length, int[] nextIndexes) { - array = new Element[length]; - for (int i = 0; i < length; i++) { - array[i] = new Element(i, nextIndexes); - } - } - - public BasicArray(StructuredArray sa) { - int length = (int) sa.getLength(); - array = new Element[length]; - for (int i = 0; i < length; i++) { - array[i] = sa.get(i); - } - } - - public int getLength() { - return array.length; - } - - public Element get(int index) { - return array[index]; - } - } - - public static class GenericArray { - private E[] array; - - public GenericArray(Constructor constructor, int length, int[] nextIndexes) { - @SuppressWarnings("unchecked") - final E[] a = (E[]) new Object[length]; - array = a; - try { - for (int i = 0; i < length; i++) { - array[i] = constructor.newInstance(i, nextIndexes); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public GenericArray(StructuredArray sa) { - int length = (int) sa.getLength(); - @SuppressWarnings("unchecked") - final E[] a = (E[]) new Object[length]; - array = a; - for (int i = 0; i < length; i++) { - array[i] = sa.get(i); - } - } - - public int getLength() { - return array.length; - } - - public E get(int index) { - return array[index]; - } - } - - public static class RandomizedBasicArray { - private Element[] array; - - public RandomizedBasicArray(int length, int[] nextIndexes) { - array = new Element[length]; - for (int i = 0; i < length; i++) { - array[i] = new Element(i, nextIndexes); - } - - Random generator = new Random(randomizingSeed); - for (int i = length - 1; i > 0; i--) { - int j = generator.nextInt(i + 1); - Element temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } - - for (int i = 0; i < length; i++) { - array[i].setNextIndex(nextIndexes[i]); - } - } - - public int getLength() { - return array.length; - } - - public Element get(int index) { - return array[index]; - } - } -} diff --git a/ObjectLayout-benchmarks/src/main/java/bench/SAHashMapBench.java b/ObjectLayout-benchmarks/src/main/java/bench/SAHashMapBench.java deleted file mode 100644 index a129977..0000000 --- a/ObjectLayout-benchmarks/src/main/java/bench/SAHashMapBench.java +++ /dev/null @@ -1,279 +0,0 @@ -package bench; - -import org.ObjectLayout.ConstructionContext; -import org.ObjectLayout.CtorAndArgs; -import org.ObjectLayout.CtorAndArgsProvider; -import org.ObjectLayout.StructuredArray; -import org.openjdk.jmh.annotations.*; -import org.openjdk.jmh.infra.Blackhole; - -import java.util.HashMap; -import java.util.Random; -import java.util.concurrent.TimeUnit; -import org.ObjectLayout.examples.util.SAHashMap; - -/* - - This benchmark creates a 1-D array of structures in 5 different ways - - Java array of structs - - Java array declared with the use of generic - - Hava array with shuffled elements - to mimic layout of elements in arrays after many GC cycles - when elements are referenced from multiple objects. - In real life application we are more likely to see partial re-order - - Structured Arrray - - A subclass of Strructured Array - - For all 5 arrays this benchmark loops over all elements and does some operation. The reported score in number of - operation per second, higher is better. - - There are several parameters to tune this benchmark - - length - number of elements in each array - - SamaLayout - when true, Structured Array is created first, and then all java arrays are initialized by the references - to elements of Strcutured Array. This insures that memory access pattern is the same for all 5 benchmark loops and - the only diffrence to be observed is how JIT transforms the main benchmark loop in each case. When false, each of - the 5 arrays is created independently. - - RandomArrayWalk - when true, the main loop accesses elements in array is a random order, otherwise elements are read - sequentially. The main loop does this: for (...) { val = array.get(index).val ; index = val + 1;} - In a RandomArrayWalk case the val would always be a random number between 0 and length -1; otherwise - array.get(index).val == index - - Run all benchmarks: - $ java -jar target/benchmarks.jar - - Run selected benchmarks: - $ java -jar target/benchmarks.jar (regexp) - - Run the profiling (Linux only): - $ java -Djmh.perfasm.events=cycles,cache-misses -jar target/benchmarks.jar -f 1 -prof perfasm - */ -@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) -@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) -@Fork(5) -@State(Scope.Thread) - -public class SAHashMapBench { - -// Default value is 1048576 = 2 ^ 20 or ~ 1M - - @Param({"20"}) - public int lengthPow2; - public int length; // Will be initialized is setup() to 1 << lengthPow2; - public int lengthMask; // Will be initialized in setup() to length - 1; - - @Param({"false", "true"}) - public boolean RandomArrayWalk; - - StructuredArray structuredArray; - - public int[] linearNextIndexes; - public int[] shuffledNextIndexes; - public Integer[] integers; - - public SAHashMap saMap = new SAHashMap(); - public HashMap map = new HashMap(); - - private Blackhole blackhole = new Blackhole(); - - @Setup - public void setup() throws NoSuchMethodException { - length = 1 << lengthPow2; - lengthMask = length - 1; - - integers = new Integer[length]; - linearNextIndexes = new int[length]; - for (int i = 0; i < length; i++) { - integers[i] = new Integer(i); - linearNextIndexes[i] = (i + 1) & lengthMask; - } - shuffledNextIndexes = new int[length]; - shuffleNextIndexes(shuffledNextIndexes); - - final Object[] args = new Object[2]; - final CtorAndArgs ctorAndArgs = - new CtorAndArgs( - Element.class.getConstructor(Element.constructorArgTypes_Long_IntArray), args); - - if (Element.class.getConstructor(Element.constructorArgTypes_Long_IntArray) == null) { - System.out.println("Failed to get constructor"); - } - - final CtorAndArgsProvider ctorAndArgsProvider = - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - args[0] = context.getIndex(); - args[1] = RandomArrayWalk ? shuffledNextIndexes : linearNextIndexes; - return ctorAndArgs; - } - }; - - structuredArray = StructuredArray.newInstance(Element.class, ctorAndArgsProvider, length); - - // populate hashmaps: -// System.out.println(); - for (int i = 0; i < length; i++) { - saMap.put(i, structuredArray.get(i)); - map.put(i, structuredArray.get(i)); - // Verify: -// Element e; -// if ((e = saMap.get(i)) != structuredArray.get(i)) { -// System.out.println("saMap(" + i + ") == " + e + -// ", saMap.size() = " + saMap.size() + " (" + map.size() + ")"); -// } -// if ((e = map.get(i)) != structuredArray.get(i)) { -// System.out.println("map(" + i + ") == " + e); -// } - } - } - - static void shuffleNextIndexes(int[] array) { - int length = array.length; - int[] visitOrderArray = new int[length]; - Random generator = new Random(42); - for (int i = 0; i < length; i++) { - visitOrderArray[i] = i; - } - for (int i = length - 1; i >= 0; i--) { - int j = generator.nextInt(i + 1); - int temp = visitOrderArray[i]; - visitOrderArray[i] = visitOrderArray[j]; - visitOrderArray[j] = temp; - } - for (int i = 0; i < length - 1; i++) { - array[visitOrderArray[i]] = visitOrderArray[i + 1]; - } - array[visitOrderArray[length - 1]] = visitOrderArray[0]; - } - - @Benchmark - public void mapLoop() { - long accumulator = 0; - for (int i = 0 ; i < length; i++) { - int nextIndex = map.get(integers[i]).getNextIndex(); - accumulator = Element.simple_math(accumulator, nextIndex); - } - blackhole.consume(accumulator); - } - - @Benchmark - public void mapDataDependentLoop() { - long accumulator = 0; - int index = 0 ; - for (int i = 0 ; i < length; i++) { - int nextIndex = map.get(integers[index]).getNextIndex(); - accumulator = Element.simple_math(accumulator, nextIndex); - index = nextIndex; - } - blackhole.consume(accumulator); - } - - @Benchmark - public void saMapLoop() { - long accumulator = 0; - for (int i = 0 ; i < length; i++) { - int nextIndex = saMap.get(integers[i]).getNextIndex(); - accumulator = Element.simple_math(accumulator, nextIndex); - } - blackhole.consume(accumulator); - } - - @Benchmark - public void saMapDataDependentLoop() { - long accumulator = 0; - int index = 0 ; - for (int i = 0 ; i < length; i++) { - int nextIndex = saMap.get(integers[index]).getNextIndex(); - accumulator = Element.simple_math(accumulator, nextIndex); - index = nextIndex; - } - blackhole.consume(accumulator); - } - - public static class Element extends ElementBase { - static int[] intArray = new int[1]; - static final Class[] constructorArgTypes_Long_IntArray = {Long.TYPE, intArray.getClass()}; - static final Class[] constructorArgTypes_SA = {Element.class}; - - // padding elements - to make sure that each element is greater than 2x L1 D-cache line - private long l0,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15; - - public Element() { - } - - public Element(final long index, final int[] nextIndexes) { - super(index, nextIndexes); - } - - public Element(Element src) { - super(src); - } - } - - public static class ElementBase { - - private long index = -1; - private int nextIndex = Integer.MIN_VALUE; - - public ElementBase() { - } - - public ElementBase(final long index, final int[] nextIndexes) { - this.index = index; - this.nextIndex = nextIndexes[(int)index]; - } - - public ElementBase(ElementBase src) { - this.index = src.index; - this.nextIndex = src.nextIndex; - } - - public long getIndex() { - return index; - } - - public void setIndex(final long index) { - this.index = index; - } - - public int getNextIndex() { - return nextIndex; - } - - public void setNextIndex(final int nextIndex) { - this.nextIndex = nextIndex; - } - - @Override - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final ElementBase that = (ElementBase)o; - - return index == that.index && nextIndex == that.nextIndex; - } - - @Override - public int hashCode() { - int result = (int)(index ^ (index >>> 32)); - result = 31 * result + (int)(nextIndex ^ (nextIndex >>> 32)); - return result; - } - - @Override - public String toString() { - return "MockStructure{" + - "index=" + index + - ", nextIndex=" + nextIndex + - '}'; - } - - public static long simple_math(long param1, int param2) { - return param1 ^ param2; - } - } -} \ No newline at end of file diff --git a/ObjectLayout-examples/LICENSE.txt b/ObjectLayout-examples/LICENSE.txt deleted file mode 100644 index 5e28661..0000000 --- a/ObjectLayout-examples/LICENSE.txt +++ /dev/null @@ -1,2 +0,0 @@ -Please view the LICENSE or LICENSE.txt files in the individual source -directories and subdirectories for license details. diff --git a/ObjectLayout-examples/pom.xml b/ObjectLayout-examples/pom.xml deleted file mode 100644 index c289e6a..0000000 --- a/ObjectLayout-examples/pom.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - 4.0.0 - - - org.objectlayout - ObjectLayout-parent - 1.0.5-SNAPSHOT - - - ObjectLayout-examples - ObjectLayoutExamples - jar - - - UTF-8 - - - - - junit - junit - 4.13.1 - test - - - org.objectlayout - ObjectLayout - ${project.version} - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.7 - - - add-test-source - generate-test-sources - - add-test-source - - - - src/examples/java - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.8 - 1.8 - - -proc:none - UTF-8 - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12.4 - - -Xmx1g - false - - - - - - diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/BPlusTree.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/BPlusTree.java deleted file mode 100644 index 2cff786..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/BPlusTree.java +++ /dev/null @@ -1,869 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, Martin Thompson and Michael Barker, and released - * to the public domain, as explained at: - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import java.lang.invoke.MethodHandles; -import java.util.Comparator; -import java.util.Iterator; -import java.util.Map; -import java.util.NoSuchElementException; - -import org.ObjectLayout.ReferenceArray; -import org.ObjectLayout.StructuredArray; - -@SuppressWarnings("rawtypes") -public class BPlusTree implements Iterable> { - - private static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - private final int nodeSize; - private final Comparator comparator; - private final Leaf firstNode; - private Node root; - private int size; - - private static final Object[] EMPTY_ARGS = {}; - - public BPlusTree(int nodeSize) { - this(nodeSize, null); - } - - - public BPlusTree(int nodeSize, Comparator comparator) { - this.nodeSize = nodeSize; - this.comparator = comparator; - - firstNode = Leaf.newInstance(nodeSize); - this.root = firstNode; - } - - @SuppressWarnings("unchecked") - public V put(K key, V val) { - if (key == null || val == null) { - throw new NullPointerException("Keys and values may not be null"); - } - - Object o = root.put(comparator, key, val); - - if (isSplit(o)) { - Node next = root.next(); - root = Branch.newInstance(root, next, nodeSize); - - o = null; - } - - if (null == o) { - size++; - } - - return (V) o; - } - - @SuppressWarnings("unchecked") - public V get(Object key) { - return (V) root.get(comparator, key); - } - - @SuppressWarnings("unchecked") - public V remove(Object key) { - - Object o = root.remove(comparator, key); - - if (null != o) { - size--; - - if (root.hasOnlyChild()) { - root = (Node) root.firstValue(); - } - } - - return (V) o; - } - - public int size() { - return size; - } - - static class Entry implements Map.Entry { - private Object key; - private Object val; - - public Entry() { - } - - @Override - public Object getKey() { - return key; - } - - @Override - public Object getValue() { - return val; - } - - @Override - public Object setValue(Object value) { - Object oldValue = this.val; - this.val = value; - return oldValue; - } - - @Override - public String toString() { - return "[" + key + "->" + val + "]"; - } - - public void set(Object key, Object val) { - this.key = key; - this.val = val; - } - - public void clear() { - key = null; - val = null; - } - } - - private static int binarySearch(StructuredArray entries, int fromIndex, - int toIndex, Object key, Comparator c) { - int low = fromIndex; - int high = toIndex - 1; - - while (low <= high) { - int mid = (low + high) >>> 1; - Object midVal = entries.get(mid).getKey(); - int cmp = compare(c, midVal, key); - if (cmp < 0) - low = mid + 1; - else if (cmp > 0) - high = mid - 1; - else - return mid; // key found - } - return -(low + 1); // key not found. - } - - static class Leaf extends StructuredArray implements Node { - private int size = 0; - private final int capacity; - private Leaf next; - - public Leaf() { - capacity = (int) this.getLength(); - } - - public Object put(Comparator comparator, Object key, Object val) { - Object oldVal; - - int search = binarySearch(this, 0, size, key, comparator); - if (search > -1) { - Entry entry = get(search); - oldVal = entry.getValue(); - entry.setValue(val); - } else if (size < capacity) { - oldVal = null; - - search = -(search + 1); - insert(search, key, val); - - } else { - Leaf next = Leaf.newInstance(capacity); - - int halfSize = size / 2; - - shallowCopy(this, halfSize, next, 0, halfSize); - clear(halfSize, size); - - size = halfSize; - next.size = halfSize; - - if (compare(comparator, key, next.firstKey()) < 0) { - put(comparator, key, val); - } else { - next.put(comparator, key, val); - } - - next.next = this.next; - this.next = next; - - oldVal = Node.Sentinal.SPLIT; - } - - return oldVal; - } - - private void clear(int offset, int count) { - for (int i = offset; i < count; i++) { - get(i).clear(); - } - } - - public Object get(Comparator comparator, Object key) { - int search = binarySearch(this, 0, size, key, comparator); - if (search < 0) { - return null; - } - - return get(search).getValue(); - } - - @Override - public Object remove(Comparator comparator, Object key) { - int search = binarySearch(this, 0, size, key, comparator); - - if (search < 0) { - return null; - } - - return remove(search); - } - - public BPlusTree.Leaf next() { - return next; - } - - @Override - public boolean requiresCompacting() { - return size < capacity / 2; - } - - @Override - public Object firstKey() { - return get(0).getKey(); - } - - @Override - public Object firstValue() { - return get(0).getValue(); - } - - @Override - public Object lastKey() { - return get(size - 1).getKey(); - } - - @Override - public Object lastValue() { - return get(size - 1).getValue(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("["); - for (int i = 0; i < size; i++) { - Entry entry = get(i); - sb.append(entry.getKey()).append("->").append(entry.getValue()); - sb.append(","); - } - sb.setLength(sb.length() - 1); - sb.append("]"); - - return sb.toString(); - } - - @Override - public int size() { - return size; - } - - @Override - public boolean hasOnlyChild() { - return false; - } - - public void mergeFrom(Node right) { - assert (right.size() == capacity / 2) || (size == capacity / 2) : "Should have exactly half capacity nodes"; - - Leaf leaf = (Leaf) right; - - shallowCopy(leaf, 0, this, size, leaf.size()); - next = leaf.next(); - - size += leaf.size(); - } - - public boolean stealFromRight(Leaf right) { - if (right.size() > capacity / 2) { - append(right.firstKey(), right.firstValue()); - right.removeFirst(); - return true; - } - - return false; - } - - public boolean stealFromLeft(Leaf left) { - if (left.size() > capacity / 2) { - push(left.lastKey(), left.lastValue()); - left.clearLast(); - - return true; - } - - return false; - } - - private void removeFirst() { - remove(0); - } - - private Object remove(int search) { - Object o = this.get(search).getValue(); - if (search != size - 1) { - shallowCopy(this, search + 1, this, search, size - (search + 1)); - } - this.get(size - 1).clear(); - size--; - return o; - } - - private void insert(int search, Object key, Object val) { - if (search != size) { - shallowCopy(this, search, this, search + 1, size - search); - } - this.get(search).set(key, val); - size++; - } - - private void push(Object key, Object val) { - insert(0, key, val); - } - - private void append(Object key, Object val) { - get(size).set(key, val); - size++; - } - - private void clearLast() { - get(size - 1).clear(); - size--; - } - - public static Leaf newInstance(int nodeSize) { - return newInstance(lookup, Leaf.class, Entry.class, nodeSize); - } - } - - static class Branch extends ReferenceArray implements Node { - private final int capacity; - private int size = 0; - - public Branch() { - capacity = ((int) getLength() - 1) / 2; - } - - private void setChild(int i, Object o) - { - set(i, o); - } - - private Object getChild(int i) { - return get(i); - } - - @Override - public Object put(Comparator comparator, Object key, Object val) { - Node node = findNode(comparator, key); - - Object oldVal = node.put(comparator, key, val); - - if (isSplit(oldVal)) { - Node nextNode = node.next(); - Object keyForNextNode = nextNode.firstKey(); - - if (size == capacity) { - splitBranch(comparator, keyForNextNode, nextNode); - } else { - insertNode(comparator, keyForNextNode, nextNode); - oldVal = null; - } - } - - return oldVal; - } - - private void splitBranch(Comparator comparator, Object keyForNextNode, - Node nextNode) { - int halfSize = size / 2; - - int comparison = compareWithMidValues(comparator, keyForNextNode, - halfSize); - - if (comparison == 0) { - Branch nextBranch = create(capacity); - - // Copy half of the nodes from the original - int copyFrom = keyOffset(halfSize); - int length = arraySize() - copyFrom; - shallowCopy(this, copyFrom, nextBranch, 1, length); - nextBranch.size = halfSize; - - // Key from new node moved up. - nextBranch.firstKey(keyForNextNode); - nextBranch.setChild(0, nextNode); - - // clear out latter half... - clearArrayFrom(keyOffset(halfSize)); - size = halfSize; - - // temporarily store the nextBranch for the parent. - next(nextBranch); - } else if (comparison < 0) { - Branch nextBranch = create(capacity); - - // Copy half of the nodes from the original - int copyFrom = keyOffset(halfSize); - int length = arraySize() - copyFrom; - shallowCopy(this, copyFrom, nextBranch, 1, length); - nextBranch.size = halfSize; - - // Last key from first half moved up. - nextBranch.firstKey(storedKey(halfSize - 1)); - nextBranch.setChild(0, getChild(halfSize * 2)); - - // clear out latter half... - clearArrayFrom(keyOffset(halfSize - 1)); - size = halfSize - 1; - - // Insert the new node - insertNode(comparator, keyForNextNode, nextNode); - - // temporarily store the nextBranch for the parent. - next(nextBranch); - } else { - Branch nextBranch = create(capacity); - - // Copy just under half of the nodes from the original - int copyFrom = keyOffset(halfSize + 1); - int length = arraySize() - copyFrom; - shallowCopy(this, copyFrom, nextBranch, 1, length); - nextBranch.size = halfSize - 1; - - // First key from second half moved up. - nextBranch.firstKey(storedKey(halfSize)); - nextBranch.setChild(0, getChild((halfSize + 1) * 2)); - - // clear out latter half... - clearArrayFrom(keyOffset(halfSize)); - size = halfSize; - - // Insert the new node - nextBranch.insertNode(comparator, keyForNextNode, nextNode); - - // temporarily store the nextBranch for the parent. - next(nextBranch); - } - } - - private void clearArrayFrom(int offset) { - for (int i = offset; i < getLength(); i++) { - setChild(i, null); - } - } - - private void clear(int index) { - setChild(index, null); - } - - @Override - public Object get(Comparator comparator, Object key) { - return findNode(comparator, key).get(comparator, key); - } - - @Override - public Object remove(Comparator comparator, Object key) { - int index = findKeyIndex(comparator, key); - int nodeOffset = index * 2; - - Node node = (Node) getChild(nodeOffset); - Object oldVal = node.remove(comparator, key); - - if (node.requiresCompacting()) { - if (node instanceof Leaf) { - compactLeaves((Leaf) node, index, nodeOffset); - } else { - compactBranches((Branch) node, index, nodeOffset); - } - } - - return oldVal; - } - - private void compactLeaves(Leaf node, int index, int nodeOffset) { - if (index + 1 <= size) { - Leaf left = node; - Leaf right = (Leaf) getChild(nodeOffset + 2); - - if (left.stealFromRight(right)) { - setChild(nodeOffset + 1, right.firstKey()); - } else { - left.mergeFrom(right); - removeMergedNode(nodeOffset); - } - } else { - Leaf left = (Leaf) getChild(nodeOffset - 2); - Leaf right = node; - - if (right.stealFromLeft(left)) { - setChild(nodeOffset - 1, right.firstKey()); - } else { - left.mergeFrom(right); - removeMergedNode(nodeOffset); - } - } - } - - private void compactBranches(Branch node, int index, int nodeOffset) { - if (index + 1 <= size) { - Branch right = (Branch) getChild(nodeOffset + 2); - Object rightKey = getChild(nodeOffset + 1); - - if (right.size() > capacity / 2) { - node.append(rightKey, right.firstValue()); - Object poppedKey = right.popKey(); - setChild(nodeOffset + 1, poppedKey); - } else { - node.mergeFrom(rightKey, right); - removeMergedNode(nodeOffset); - } - } else { - Branch left = (Branch) getChild(nodeOffset - 2); - Object nodeKey = getChild(nodeOffset - 1); - - if (left.size() > capacity / 2) { - node.push(left.lastValue(), nodeKey); - setChild(nodeOffset - 1, left.lastKey()); - left.clearLast(); - } else { - left.mergeFrom(nodeKey, node); - removeMergedNode(nodeOffset); - } - } - } - - private void removeMergedNode(int nodeOffset) { - int length = arraySize() - (nodeOffset + 3); - if (length > 0) { - shallowCopy(this, nodeOffset + 3, this, nodeOffset + 1, length); - } - size--; - - clear(arraySize()); - clear(arraySize() + 1); - } - - public void mergeFrom(Object rightKey, Node right) { - Branch branch = (Branch) right; - setChild(arraySize(), rightKey); - shallowCopy(branch, 0, this, arraySize() + 1, branch.arraySize()); - size += branch.size() + 1; - } - - private int compareWithMidValues(Comparator comparator, Object key, - int halfSize) { - Object keyA = storedKey(halfSize - 1); - Object keyB = storedKey(halfSize); - - int compareA = compare(comparator, key, keyA); - int compareB = compare(comparator, key, keyB); - - assert compareA != 0 : "Should not get a key match on split"; - assert compareB != 0 : "Should not get a key match on split"; - - return Integer.signum(compareA) + Integer.signum(compareB); - } - - private void insertNode(Comparator comparator, Object key, Node child) { - int keyIndex = findKeyIndex(comparator, key); - int offset = keyIndex * 2 + 1; - int length = arraySize() - offset; - - if (length > 0) { - shallowCopy(this, offset, this, offset + 2, length); - } - - setChild(offset, key); - setChild(offset + 1, child); - size++; - } - - private void next(Branch nextBranch) { - assert size < capacity : "Can only store next node if node is not full"; - setChild((int) getLength() - 1, nextBranch); - } - - private void firstKey(Object storedKey) { - assert size < capacity : "Can only store first key if node is not full"; - setChild((int) getLength() - 1, storedKey); - } - - @Override - public Node next() { - int offset = (int) getLength() - 1; - Object nextNode = getChild(offset); - - assert nextNode != null : "Can only fetch next once"; - setChild(offset, null); - - return (Node) nextNode; - } - - @Override - public Object firstKey() { - int offset = (int) getLength() - 1; - Object firstKey = getChild(offset); - - assert firstKey != null : "Can only fetch firstKey once"; - setChild(offset, null); - - return firstKey; - } - - public Object popKey() { - Object key = getChild(1); - int length = arraySize() - 2; - shallowCopy(this, 2, this, 0, length); - size--; - clear(arraySize()); - clear(arraySize() + 1); - return key; - } - - @Override - public Node firstValue() { - return (Node) getChild(0); - } - - @Override - public Object lastKey() { - assert size > 0 : "Should not be modifying branch with only child"; - - return getChild(arraySize() - 2); - } - - @Override - public Node lastValue() { - assert size > 0 : "Should not be modifying branch with only child"; - - return (Node) getChild(arraySize() - 1); - } - - private void clearLast() { - assert size > 0 : "Should not be modifying branch with only child"; - - clear(arraySize() - 1); - clear(arraySize() - 2); - size--; - } - - public void push(Node val, Object key) { - shallowCopy(this, 0, this, 2, arraySize()); - setChild(0, val); - setChild(1, key); - size++; - } - - public void append(Object key, Node val) { - setChild(arraySize(), key); - setChild(arraySize() + 1, val); - size++; - } - - @Override - public boolean requiresCompacting() { - return size < capacity / 2; - } - - private Node findNode(Comparator comparator, Object key) { - return storedNode(findKeyIndex(comparator, key)); - } - - private int keyOffset(int index) { - return index * 2 + 1; - } - - private Node storedNode(int search) { - return (Node) getChild(search * 2); - } - - private Object storedKey(int index) { - return getChild(keyOffset(index)); - } - - private int findKeyIndex(Comparator comparator, Object key) { - int lo = 0; - int hi = size - 1; - - while (lo <= hi) { - final int mid = (lo + hi) >>> 1; - - Object stored = storedKey(mid); - int comparison = compare(comparator, key, stored); - - if (comparison == 0) { - return mid + 1; - } else if (comparison < 0) { - hi = mid - 1; - } else { - lo = mid + 1; - } - } - - return lo; - } - - @Override - public String toString() { - - StringBuilder sb = new StringBuilder("B:["); - - for (int i = 0; i < size; i++) { - sb.append(getChild(i)).append(","); - } - - sb.setLength(sb.length() - 1); - sb.append("]"); - - return sb.toString(); - } - - @Override - public int size() { - return size; - } - - @Override - public boolean hasOnlyChild() { - return size == 0; - } - - private int arraySize() { - return size * 2 + 1; - } - - private static Branch newInstance(Node left, Node right, int nodeSize) { - - Branch branch = create(nodeSize); - - branch.setChild(0, left); - branch.setChild(1, right.firstKey()); - branch.setChild(2, right); - branch.size = 1; - - return branch; - } - - private static Branch create(int nodeSize) { - int length = (nodeSize * 2) + 1; - return ReferenceArray.newInstance(lookup, Branch.class, length); - } - } - - interface Node { - enum Sentinal { - SPLIT - }; - - Object get(Comparator comparator, Object key); - - Object put(Comparator comparator, Object key, Object val); - - Object remove(Comparator comparator, Object key); - - Object lastValue(); - - Object lastKey(); - - Object firstValue(); - - int size(); - - boolean requiresCompacting(); - - Object firstKey(); - - Node next(); - - boolean hasOnlyChild(); - } - - @SuppressWarnings("unchecked") - private static int compare(Comparator comparator, Object a, Object b) { - if (null == comparator) { - return ((Comparable) a).compareTo(b); - } else { - return comparator.compare(a, b); - } - } - - private static boolean isSplit(Object o) { - return Node.Sentinal.SPLIT == o; - } - - @Override - public String toString() { - return "org.ObjectLayout.examples.BPlusTree [nodeSize=" + nodeSize + ", comparator=" + comparator - + ", root=" + root + "]"; - } - - public Iterator> iterator() { - return new BPlusTreeIterator(firstNode); - } - - public class BPlusTreeIterator implements Iterator> { - private Leaf leaf; - private int index = -1; - - public BPlusTreeIterator(Leaf leaf) { - this.leaf = leaf; - } - - @Override - public boolean hasNext() { - return (index + 1) < leaf.size() || leaf.next() != null; - } - - @SuppressWarnings("unchecked") - @Override - public Map.Entry next() { - if ((index + 1) < leaf.size()) { - index++; - - Entry entry = leaf.get(index); - return entry; - - } else if (leaf.next() != null) { - leaf = leaf.next(); - index = 0; - - Entry entry = leaf.get(index); - return entry; - } - - throw new NoSuchElementException(); - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - } - - public static void shallowCopy( - final ReferenceArray src, final long srcOffset, - final ReferenceArray dst, final long dstOffset, - final long count) { - - if (srcOffset + count > Integer.MAX_VALUE || dstOffset + count > Integer.MAX_VALUE) { - throw new ArrayIndexOutOfBoundsException(); - } - - int length = (int) count; - int srcOff = (int) srcOffset; - int dstOff = (int) dstOffset; - - System.arraycopy(src.asArray(), srcOff, dst.asArray(), dstOff, length); - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/LICENSE.txt b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/LICENSE.txt deleted file mode 100644 index 83efdd9..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/LICENSE.txt +++ /dev/null @@ -1,45 +0,0 @@ -With the exception of the util subdriectory (which includes it's own -LICENSE file) and it's contents, the following license information -applies to all files in this directory: - -The code in this directory was Written by Gil Tene -Martin Thompson, and Michael Barker and released to the public domain, -as explained at http://creativecommons.org/publicdomain/zero/1.0/ - -For users of this code who wish to consume it under the "BSD" license -rather than under the public domain or CC0 contribution text mentioned -above, the code found under this directory is *also* provided under the -following license (commonly referred to as the BSD 2-Clause License). This -license does not detract from the above stated release of the code into -the public domain, and simply represents an additional license granted by -the Author. - ------------------------------------------------------------------------------ -** Beginning of "BSD 2-Clause License" text. ** - - Copyright (c) 2012, 2013, 2014, 2015 Gil Tene - Copyright (c) 2014, 2014, 2015 Michael Barker - Copyright (c) 2012, 2013, 2014 Martin Thompson - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Line.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Line.java deleted file mode 100644 index 9a966dd..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Line.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.ObjectLayout.Intrinsic; -import org.ObjectLayout.IntrinsicObjects; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A simple Line class example with two intrinsic Point end point objects. Demonstrates use of - * {@link org.ObjectLayout.IntrinsicObjectModel} - * members and their initialization, either at field initialization or during construction. - * - *

- * Note that the following rules apply to intrinsic object members: - *

    - *
  • All intrinsic object members must be private final fields.
  • - *
  • Intrinsic object members should be initialized (either at - * field declaration, initialization code section, or in the containing object's constructor) using - * one of the {@link org.ObjectLayout.IntrinsicObjects#constructWithin} variants
  • - *
  • Intrinsic object members should not be initialized to null
  • - *
  • Intrinsic object members should not be initialized with the value of another intrinsic object member
  • - *
  • Intrinsic object members should be constructed with their containing object as a parameter
  • - *
- * - * Failure to follow these rules can result in error, warnings, or simply in slower execution. - * - */ -public class Line { - - private static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - /** - * Simple intrinsic object declaration and initialization: - */ - @Intrinsic - private final Point endPoint1 = IntrinsicObjects.constructWithin(lookup, "endPoint1", this); - - /** - * Declaration of an intrinsic object field that will be initialized later during construction or other init code: - */ - @Intrinsic - private final Point endPoint2; - - public Line() { - this(0, 0, 0, 0); - } - - public Line(final long x1, final long y1, long x2, long y2) { - /** - * Construction-time Initialization of IntrinsicObject: - */ - this.endPoint2 = IntrinsicObjects.constructWithin(lookup, "endPoint2", this, xy_constructor, x2, y2); - - /** - * Access to IntrinsicObject within constructor: - */ - this.endPoint1.set(x1, y1); - } - - public Line(final Line source) { - this(source.endPoint1.getX(), source.endPoint1.getY(), - source.endPoint2.getX(), source.endPoint2.getY()); - } - - public Point getEndPoint1() { - return endPoint1; - } - - public Point getEndPoint2() { - return endPoint2; - } - - - static final Constructor xy_constructor; - - static { - try { - @SuppressWarnings("unchecked") - Constructor constructor = Point.class.getConstructor(long.class, long.class); - xy_constructor = constructor; - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/MassOrder.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/MassOrder.java deleted file mode 100644 index 4e6c63d..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/MassOrder.java +++ /dev/null @@ -1,225 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, Martin Thompson, and Michael Barker, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import java.util.Iterator; - -import org.ObjectLayout.*; - -public class MassOrder extends - StructuredArray { - - private final long accountId; - private final String instructionId; - private final SimpleOrder.OrderType orderType; - private final long instrumentId; - private final int askOrderIndex; - - MassOrder(final Builder builder) { - this.accountId = builder.accountId; - this.instructionId = builder.instructionId; - this.orderType = builder.orderType; - this.instrumentId = builder.instrumentId; - this.askOrderIndex = builder.bidIndex; - } - - public long getAccountId() { - return accountId; - } - - public String getInstructionId() { - return instructionId; - } - - public SimpleOrder.OrderType getOrderType() { - return orderType; - } - - public long getInstrumentId() { - return instrumentId; - } - - public int getBidOrderIndex() { - return 0; - } - - public int getBidOrderCount() { - return askOrderIndex; - } - - private final Iterable bidIterable = new - Iterable() { - @Override - public Iterator iterator() { - return new ElementIterator(getBidOrderIndex(), getBidOrderCount()); - } - }; - - public Iterable getBids() { - return bidIterable; - } - - public int getAskOrderCount() { - return (int) (getLength() - askOrderIndex); - } - - public int getAskOrderIndex() { - return askOrderIndex; - } - - private final Iterable askIterable = new Iterable() { - @Override - public Iterator iterator() { - return new ElementIterator(getAskOrderIndex(), getAskOrderCount()); - } - }; - - public Iterable getAsks() { - return askIterable; - } - - @Override - public String toString() { - return "MassOrderWithBuilder [accountId=" + this.accountId - + ", instructionId=" + this.instructionId + ", orderType=" - + this.orderType + ", instrumentId=" + this.instrumentId - + ", askOrderIndex=" + this.askOrderIndex + "]"; - } - - private static final ThreadLocal BUILDER = new ThreadLocal() { - protected Builder initialValue() { - try { - return new Builder(); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - }; - - public static Builder builder() { - return BUILDER.get().reset(); - } - - public static final class Builder implements - CtorAndArgsProvider { - - private static CtorAndArgs massOrderCtorAndArgs() { - try { - final Class[] argTypes = { Builder.class }; - return new CtorAndArgs(MassOrder.class, argTypes, (Object) null); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private static CtorAndArgs simpleOrderCtorAndArgs() { - try { - final Class[] argTypes = { Builder.class, SimpleOrder.Side.class, long.class, long.class }; - return new CtorAndArgs(SimpleOrder.class, argTypes, null, null, 0L, 0L); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private static final int MAX_ORDERS_PER_SIDE = 6; - - long accountId; - long instrumentId; - String instructionId; - SimpleOrder.OrderType orderType; - - private int bidIndex; - private long[] bidPrices = new long[MAX_ORDERS_PER_SIDE]; - private long[] bidQuantities = new long[MAX_ORDERS_PER_SIDE]; - - private int askIndex; - private long[] askPrices = new long[MAX_ORDERS_PER_SIDE]; - private long[] askQuantities = new long[MAX_ORDERS_PER_SIDE]; - - // We use final ctorAndArgs per builder instance, since each builder is expect to be used - // in a linear way with a thread (is likely to be thread local in common use). - private final CtorAndArgs massOrderCtorAndArgs = massOrderCtorAndArgs(); - private final CtorAndArgs simpleOrderCtorAndArgs = simpleOrderCtorAndArgs(); - - public Builder() throws NoSuchMethodException { - massOrderCtorAndArgs.setArgs(this); - reset(); - } - - public Builder reset() { - accountId = 0; - instrumentId = 0; - instructionId = null; - orderType = null; - bidIndex = 0; - askIndex = 0; - - return this; - } - - public Builder accountId(long accountId) { - this.accountId = accountId; - return this; - } - - public Builder instrumentId(long instrumentId) { - this.instrumentId = instrumentId; - return this; - } - - public Builder instructionId(String instructionId) { - this.instructionId = instructionId; - return this; - } - - public Builder orderType(SimpleOrder.OrderType orderType) { - this.orderType = orderType; - return this; - } - - public Builder addBid(long price, long quantity) { - bidPrices[bidIndex] = price; - bidQuantities[bidIndex] = quantity; - bidIndex++; - return this; - } - - public Builder addAsk(long price, long quantity) { - askPrices[askIndex] = price; - askQuantities[askIndex] = quantity; - askIndex++; - return this; - } - - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - long index = context.getIndex(); - CtorAndArgs ctorAndArgs = simpleOrderCtorAndArgs; - - if (index > bidIndex + askIndex) { - throw new IllegalArgumentException(); - } - - int i = (int) index; - if (i < bidIndex) { - ctorAndArgs.setArgs(this, SimpleOrder.Side.BID, bidPrices[i], bidQuantities[i]); - } else { - i = i - bidIndex; - ctorAndArgs.setArgs(this, SimpleOrder.Side.BID, askPrices[i], askQuantities[i]); - } - - return ctorAndArgs; - } - - public MassOrder newInstance() { - - // TODO: Order validation and sorting by price. - - long length = bidIndex + askIndex; - return (MassOrder) StructuredArray.newInstance( - massOrderCtorAndArgs, SimpleOrder.class, length, this); - } - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/MassOrderExample.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/MassOrderExample.java deleted file mode 100644 index f6e9e31..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/MassOrderExample.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Michael Barker, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -public class MassOrderExample { - public static void main(String[] args) { - MassOrder massOrder = MassOrder.builder(). - accountId(1). - instructionId("ABC"). - instrumentId(2). - orderType(SimpleOrder.OrderType.LIMIT). - addBid(10, 10). - addBid(11, 10). - addBid(12, 10). - addBid(13, 10). - addAsk(17, 10). - addAsk(18, 10). - addAsk(19, 10). - addAsk(20, 10).newInstance(); - - System.out.println(massOrder); - - for (SimpleOrder order : massOrder.getBids()) { - System.out.println(order); - } - - for (SimpleOrder order : massOrder.getAsks()) { - System.out.println(order); - } - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Octagon.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Octagon.java deleted file mode 100644 index 2eba57b..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Octagon.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - - -import org.ObjectLayout.Intrinsic; -import org.ObjectLayout.IntrinsicObjects; - -import java.lang.invoke.MethodHandles; - -/** - * A simple Octagon class example with an intrinsic StructuredArray of Points. Demonstrates use of - * {@link org.ObjectLayout.IntrinsicObjectModel} members and their initialization, when the - * intrinsic member is a StructuredArray. - * - */ -public class Octagon { - - private static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - /** - * Intrinsic object declaration and initialization for a StructuredArray member: - */ - @Intrinsic(length = 8) - private final PointArray points = IntrinsicObjects.constructWithin(lookup, "points", this); - - private final String color; - - public Octagon() { - this("blank"); - } - - public Octagon(final String color) { - this.color = color; - } - - public Octagon(final Octagon source) { - this.color = source.getColor(); - for (int i = 0; i < points.getLength(); i++) { - points.get(i).setX(source.getPoints().get(i).getX()); - points.get(i).setY(source.getPoints().get(i).getY()); - } - } - - /** - * Build an perfect octagon with center at (centerX, centerY), and first point - * at (centerX + radius, centerY) - * - * @param color - * @param centerX - * @param centerY - * @param radius - */ - public Octagon(final String color, final long centerX, final long centerY, final long radius) { - this.color = color; - for (int i = 0; i < 8; i++) { - double angleRad = i * (2.0 * Math.PI) / 8.0; - long x = centerX + (long)(Math.cos(angleRad) * radius); - long y = centerY + (long)(Math.sin(angleRad) * radius); - points.get(i).setX(x); - points.get(i).setY(y); - } - } - - public PointArray getPoints() { - return points; - } - - public String getColor() { - return color; - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Octagons.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Octagons.java deleted file mode 100644 index cd96fcd..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Octagons.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.ObjectLayout.*; - -import java.lang.reflect.Constructor; -import java.util.Date; - -public class Octagons extends StructuredArray { - - public Date creationDate = new Date(); - - public Octagons() { - } - - public Octagons(Octagons source) { - super(source); - } - - public static Octagons newInstance(final long length) { - return StructuredArray.newInstance(Octagons.class, Octagon.class, length); - } - - public static Octagons newInstance( - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - return StructuredArray.newInstance( - Octagons.class, Octagon.class, length, ctorAndArgsProvider); - } - - public static Octagons newInstance( - final long length, - final String color, - final long initialCenterX, - final long initialCenterY, - final long radius, - final long deltaX, - final long deltaY) { - return newInstance( - length, - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return new CtorAndArgs( - cxyr_constructor, - color, - (initialCenterX + context.getIndex() * deltaX), - (initialCenterY + context.getIndex() * deltaY), - radius - ); - } - }); - } - - static final Constructor cxyr_constructor; - - static { - try { - @SuppressWarnings("unchecked") - Constructor constructor = Octagon.class.getConstructor( - String.class, long.class, long.class, long.class); - cxyr_constructor = constructor; - - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Point.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Point.java deleted file mode 100644 index 43ff917..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/Point.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/** - * A simple x,y point class to be used as an element in various other examples. - * - */ -public class Point { - private long x; - private long y; - - public Point() { - } - - public Point (final long x, final long y) { - this.x = x; - this.y = y; - } - - public Point(final Point source) { - this(source.x, source.y); - } - - public long getX() { - return x; - } - - public void setX(final long x) { - this.x = x; - } - - public long getY() { - return y; - } - - public void setY(final long y) { - this.y = y; - } - - public void set(final long x, final long y) { - this.x = x; - this.y = y; - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/PointArray.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/PointArray.java deleted file mode 100644 index b1f7f8c..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/PointArray.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.ObjectLayout.ConstructionContext; -import org.ObjectLayout.CtorAndArgs; -import org.ObjectLayout.CtorAndArgsProvider; -import org.ObjectLayout.StructuredArray; -import java.lang.reflect.Constructor; - -public class PointArray extends StructuredArray { - - - // expose copy constructor: - public PointArray(PointArray source) { - super(source); - } - - // Default constructor needs to be defined only because we wanted to expose a copy constructor - public PointArray() { - } - - // newInstance wrapper for convenience (cleaner/fewer parameters for API user): - public static PointArray newInstance(final long length) { - return StructuredArray.newInstance(PointArray.class, Point.class, length); - } - - // newInstance wrapper for convenience (cleaner/fewer parameters for API user): - public static PointArray newInstance(final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - return StructuredArray.newInstance( - PointArray.class, Point.class, length, ctorAndArgsProvider); - } - - // If you want to support direct construction parameters for elements, with with - // parameter types you know (statically) have a good constructor associated with the, - // here is an example: - public static PointArray newInstance(final long length, final long x, final long y) { - final CtorAndArgs xy_ctorAndArgs = new CtorAndArgs(xy_constructor, x, y); - return StructuredArray.newInstance( - PointArray.class, - Point.class, - length, - // This can be a Lambda expression in Java 8: - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return xy_ctorAndArgs; - } - }); - } - - static final Constructor xy_constructor; - - static { - try { - @SuppressWarnings("unchecked") - Constructor constructor = Point.class.getConstructor(long.class, long.class); - xy_constructor = constructor; - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/SimpleLine.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/SimpleLine.java deleted file mode 100644 index 2cbd442..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/SimpleLine.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.ObjectLayout.Intrinsic; -import org.ObjectLayout.IntrinsicObjects; - -import java.lang.invoke.MethodHandles; - -/** - * A simple Line class example with two intrinsic Point end point objects. Demonstrates use of - * {@link org.ObjectLayout.Intrinsic} and {@link org.ObjectLayout.IntrinsicObjects} - * - */ -public class SimpleLine { - - private static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - /** - * Simple intrinsic object declaration and initialization: - */ - @Intrinsic - private final Point endPoint1 = IntrinsicObjects.constructWithin(lookup, "endPoint1", this); - @Intrinsic - private final Point endPoint2 = IntrinsicObjects.constructWithin(lookup, "endPoint2", this); - - public SimpleLine() { - this(0, 0, 0, 0); - } - - public SimpleLine(final long x1, final long y1, long x2, long y2) { - this.endPoint1.set(x1, y1); - this.endPoint1.set(x2, y2); - } - - public SimpleLine(final SimpleLine source) { - this(source.endPoint1.getX(), source.endPoint1.getY(), - source.endPoint2.getX(), source.endPoint2.getY()); - } - - public Point getEndPoint1() { - return endPoint1; - } - - public Point getEndPoint2() { - return endPoint2; - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/SimpleOrder.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/SimpleOrder.java deleted file mode 100644 index dcc6369..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/SimpleOrder.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Michael Barker, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -public class SimpleOrder { - - public static enum OrderType { - MARKET, LIMIT - } - - public static enum Side { - BID, ASK - } - - private final long instrumentId; - private final long accountId; - private final SimpleOrder.OrderType orderType; - private final long price; - private final long quantity; - private final Side side; - - private long cancelledQuantity = 0; - private long filledQuantity = 0; - - public SimpleOrder(MassOrder.Builder builder, - Side side, long price, long quantity) { - this.side = side; - this.instrumentId = builder.instrumentId; - this.accountId = builder.accountId; - this.orderType = builder.orderType; - this.price = price; - this.quantity = quantity; - } - - public long getCancelledQuantity() { - return this.cancelledQuantity; - } - - public void updateCancelled(long delta) { - this.cancelledQuantity -= delta; - } - - public long getFilledQuantity() { - return this.filledQuantity; - } - - public void updateFill(long matchedQuantity) { - this.filledQuantity -= matchedQuantity; - } - - public long getInstrumentId() { - return this.instrumentId; - } - - public long getAccountId() { - return this.accountId; - } - - public SimpleOrder.OrderType getOrderType() { - return this.orderType; - } - - public long getPrice() { - return this.price; - } - - public long getQuantity() { - return this.quantity; - } - - @Override - public String toString() { - return "SimpleOrderWithBuilder [instrumentId=" + this.instrumentId - + ", accountId=" + this.accountId + ", orderType=" - + this.orderType + ", side=" + this.side + ", price=" - + this.price + ", quantity=" + this.quantity - + ", cancelledQuantity=" + this.cancelledQuantity - + ", filledQuantity=" + this.filledQuantity + "]"; - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/StructuredArrayOfAtomicLong.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/StructuredArrayOfAtomicLong.java deleted file mode 100644 index d27e5a5..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/StructuredArrayOfAtomicLong.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.ObjectLayout.StructuredArray; - -import java.util.concurrent.atomic.AtomicLong; - -/** - * A simple, minimalistic example of a non-generic subclass of StructuredArray<AtomicLong>. - */ -public class StructuredArrayOfAtomicLong extends StructuredArray { - - public static StructuredArrayOfAtomicLong newInstance(final long length) { - return StructuredArray.newInstance(StructuredArrayOfAtomicLong.class, AtomicLong.class, length); - } - - public AtomicLong get(long index) { - return super.get(index); - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/TwoDimPointMatrix.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/TwoDimPointMatrix.java deleted file mode 100644 index ebe2a15..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/TwoDimPointMatrix.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.ObjectLayout.examples; - -import org.ObjectLayout.*; - -import java.lang.reflect.Constructor; - -/** - * A Matrix arranged as a height long array of columns (logically indexed as [x][y]) - */ -public class TwoDimPointMatrix extends StructuredArray { - - public TwoDimPointMatrix() { - } - - public TwoDimPointMatrix(TwoDimPointMatrix source) { - super(source); - } - - public static TwoDimPointMatrix newInstance(final long width, final long height) { - final CtorAndArgs xy_ctorAndArgs = new CtorAndArgs<>(xy_constructor, 0, 0); - return newInstance( - width, - height, - // This can be a Lambda expression in Java 8: - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return xy_ctorAndArgs; - } - } - ); - } - - public static TwoDimPointMatrix newInstance( - final long width, - final long height, - final CtorAndArgsProvider ctorAndArgsProvider) { - StructuredArrayBuilder builder = - new StructuredArrayBuilder<>( - TwoDimPointMatrix.class, - new StructuredArrayBuilder<>( - PointArray.class, - Point.class, - width). - elementCtorAndArgsProvider(ctorAndArgsProvider), - height); - - return builder.build(); - } - - // If you want to support direct construction parameters for elements, with with parameter types you know - // (statically) have a good constructor associated with the, here is an example: - - public static TwoDimPointMatrix newInstance( - final long width, - final long height, - final long x, - final long y) { - final CtorAndArgs xy_ctorAndArgs = new CtorAndArgs<>(xy_constructor, x, y); - return newInstance(width, height, - // This can be a Lambda expression in Java 8: - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return xy_ctorAndArgs; - } - }); - } - - // An example of how to create a matrix with points pre-initialized to their [x, y] - // in the matrix. This is a good example of using hierarchical context in determining - // the ctorAndArgs for a specific array element: - public static TwoDimPointMatrix newPreInitializedInstance( - final long width, - final long height) { - final CtorAndArgs xy_ctorAndArgs = new CtorAndArgs<>(xy_constructor, 0, 0); - return newInstance( - width, - height, - // This can be a Lambda expression in Java 8: - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return xy_ctorAndArgs.setArgs( - context.getIndex(), - context.getContainingContext().getIndex() - ); - } - } - ); - } - - static final Constructor xy_constructor; - - static { - try { - @SuppressWarnings("unchecked") - Constructor constructor = Point.class.getConstructor(long.class, long.class); - xy_constructor = constructor; - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } -} diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/util/LICENSE b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/util/LICENSE deleted file mode 100644 index 8e41266..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/util/LICENSE +++ /dev/null @@ -1,353 +0,0 @@ -As some files in this directory were ported from OpenJDK 8, the below LICENSE -taken from OpenJDK 8 applies. See specific copyright notices and Classpath -Exception designation in the individual files. - --------------------------------------------------------------------------- - -The GNU General Public License (GPL) - -Version 2, June 1991 - -Copyright (C) 1989, 1991 Free Software Foundation, Inc. -59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Everyone is permitted to copy and distribute verbatim copies of this license -document, but changing it is not allowed. - -Preamble - -The licenses for most software are designed to take away your freedom to share -and change it. By contrast, the GNU General Public License is intended to -guarantee your freedom to share and change free software--to make sure the -software is free for all its users. This General Public License applies to -most of the Free Software Foundation's software and to any other program whose -authors commit to using it. (Some other Free Software Foundation software is -covered by the GNU Library General Public License instead.) You can apply it to -your programs, too. - -When we speak of free software, we are referring to freedom, not price. Our -General Public Licenses are designed to make sure that you have the freedom to -distribute copies of free software (and charge for this service if you wish), -that you receive source code or can get it if you want it, that you can change -the software or use pieces of it in new free programs; and that you know you -can do these things. - -To protect your rights, we need to make restrictions that forbid anyone to deny -you these rights or to ask you to surrender the rights. These restrictions -translate to certain responsibilities for you if you distribute copies of the -software, or if you modify it. - -For example, if you distribute copies of such a program, whether gratis or for -a fee, you must give the recipients all the rights that you have. You must -make sure that they, too, receive or can get the source code. And you must -show them these terms so they know their rights. - -We protect your rights with two steps: (1) copyright the software, and (2) -offer you this license which gives you legal permission to copy, distribute -and/or modify the software. - -Also, for each author's protection and ours, we want to make certain that -everyone understands that there is no warranty for this free software. If the -software is modified by someone else and passed on, we want its recipients to -know that what they have is not the original, so that any problems introduced -by others will not reflect on the original authors' reputations. - -Finally, any free program is threatened constantly by software patents. We -wish to avoid the danger that redistributors of a free program will -individually obtain patent licenses, in effect making the program proprietary. -To prevent this, we have made it clear that any patent must be licensed for -everyone's free use or not licensed at all. - -The precise terms and conditions for copying, distribution and modification -follow. - -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - -0. This License applies to any program or other work which contains a notice -placed by the copyright holder saying it may be distributed under the terms of -this General Public License. The "Program", below, refers to any such program -or work, and a "work based on the Program" means either the Program or any -derivative work under copyright law: that is to say, a work containing the -Program or a portion of it, either verbatim or with modifications and/or -translated into another language. (Hereinafter, translation is included -without limitation in the term "modification".) Each licensee is addressed as -"you". - -Activities other than copying, distribution and modification are not covered by -this License; they are outside its scope. The act of running the Program is -not restricted, and the output from the Program is covered only if its contents -constitute a work based on the Program (independent of having been made by -running the Program). Whether that is true depends on what the Program does. - -1. You may copy and distribute verbatim copies of the Program's source code as -you receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice and -disclaimer of warranty; keep intact all the notices that refer to this License -and to the absence of any warranty; and give any other recipients of the -Program a copy of this License along with the Program. - -You may charge a fee for the physical act of transferring a copy, and you may -at your option offer warranty protection in exchange for a fee. - -2. You may modify your copy or copies of the Program or any portion of it, thus -forming a work based on the Program, and copy and distribute such modifications -or work under the terms of Section 1 above, provided that you also meet all of -these conditions: - - a) You must cause the modified files to carry prominent notices stating - that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in whole or - in part contains or is derived from the Program or any part thereof, to be - licensed as a whole at no charge to all third parties under the terms of - this License. - - c) If the modified program normally reads commands interactively when run, - you must cause it, when started running for such interactive use in the - most ordinary way, to print or display an announcement including an - appropriate copyright notice and a notice that there is no warranty (or - else, saying that you provide a warranty) and that users may redistribute - the program under these conditions, and telling the user how to view a copy - of this License. (Exception: if the Program itself is interactive but does - not normally print such an announcement, your work based on the Program is - not required to print an announcement.) - -These requirements apply to the modified work as a whole. If identifiable -sections of that work are not derived from the Program, and can be reasonably -considered independent and separate works in themselves, then this License, and -its terms, do not apply to those sections when you distribute them as separate -works. But when you distribute the same sections as part of a whole which is a -work based on the Program, the distribution of the whole must be on the terms -of this License, whose permissions for other licensees extend to the entire -whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest your -rights to work written entirely by you; rather, the intent is to exercise the -right to control the distribution of derivative or collective works based on -the Program. - -In addition, mere aggregation of another work not based on the Program with the -Program (or with a work based on the Program) on a volume of a storage or -distribution medium does not bring the other work under the scope of this -License. - -3. You may copy and distribute the Program (or a work based on it, under -Section 2) in object code or executable form under the terms of Sections 1 and -2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable source - code, which must be distributed under the terms of Sections 1 and 2 above - on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three years, to - give any third party, for a charge no more than your cost of physically - performing source distribution, a complete machine-readable copy of the - corresponding source code, to be distributed under the terms of Sections 1 - and 2 above on a medium customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer to - distribute corresponding source code. (This alternative is allowed only - for noncommercial distribution and only if you received the program in - object code or executable form with such an offer, in accord with - Subsection b above.) - -The source code for a work means the preferred form of the work for making -modifications to it. For an executable work, complete source code means all -the source code for all modules it contains, plus any associated interface -definition files, plus the scripts used to control compilation and installation -of the executable. However, as a special exception, the source code -distributed need not include anything that is normally distributed (in either -source or binary form) with the major components (compiler, kernel, and so on) -of the operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the source -code from the same place counts as distribution of the source code, even though -third parties are not compelled to copy the source along with the object code. - -4. You may not copy, modify, sublicense, or distribute the Program except as -expressly provided under this License. Any attempt otherwise to copy, modify, -sublicense or distribute the Program is void, and will automatically terminate -your rights under this License. However, parties who have received copies, or -rights, from you under this License will not have their licenses terminated so -long as such parties remain in full compliance. - -5. You are not required to accept this License, since you have not signed it. -However, nothing else grants you permission to modify or distribute the Program -or its derivative works. These actions are prohibited by law if you do not -accept this License. Therefore, by modifying or distributing the Program (or -any work based on the Program), you indicate your acceptance of this License to -do so, and all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - -6. Each time you redistribute the Program (or any work based on the Program), -the recipient automatically receives a license from the original licensor to -copy, distribute or modify the Program subject to these terms and conditions. -You may not impose any further restrictions on the recipients' exercise of the -rights granted herein. You are not responsible for enforcing compliance by -third parties to this License. - -7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), conditions -are imposed on you (whether by court order, agreement or otherwise) that -contradict the conditions of this License, they do not excuse you from the -conditions of this License. If you cannot distribute so as to satisfy -simultaneously your obligations under this License and any other pertinent -obligations, then as a consequence you may not distribute the Program at all. -For example, if a patent license would not permit royalty-free redistribution -of the Program by all those who receive copies directly or indirectly through -you, then the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply and -the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any patents or -other property right claims or to contest validity of any such claims; this -section has the sole purpose of protecting the integrity of the free software -distribution system, which is implemented by public license practices. Many -people have made generous contributions to the wide range of software -distributed through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing to -distribute software through any other system and a licensee cannot impose that -choice. - -This section is intended to make thoroughly clear what is believed to be a -consequence of the rest of this License. - -8. If the distribution and/or use of the Program is restricted in certain -countries either by patents or by copyrighted interfaces, the original -copyright holder who places the Program under this License may add an explicit -geographical distribution limitation excluding those countries, so that -distribution is permitted only in or among countries not thus excluded. In -such case, this License incorporates the limitation as if written in the body -of this License. - -9. The Free Software Foundation may publish revised and/or new versions of the -General Public License from time to time. Such new versions will be similar in -spirit to the present version, but may differ in detail to address new problems -or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any later -version", you have the option of following the terms and conditions either of -that version or of any later version published by the Free Software Foundation. -If the Program does not specify a version number of this License, you may -choose any version ever published by the Free Software Foundation. - -10. If you wish to incorporate parts of the Program into other free programs -whose distribution conditions are different, write to the author to ask for -permission. For software which is copyrighted by the Free Software Foundation, -write to the Free Software Foundation; we sometimes make exceptions for this. -Our decision will be guided by the two goals of preserving the free status of -all derivatives of our free software and of promoting the sharing and reuse of -software generally. - -NO WARRANTY - -11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR -THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE -STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE -PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND -PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, -YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - -12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL -ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE -PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR -INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA -BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER -OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -END OF TERMS AND CONDITIONS - -How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest possible -use to the public, the best way to achieve this is to make it free software -which everyone can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach -them to the start of each source file to most effectively convey the exclusion -of warranty; and each file should have at least the "copyright" line and a -pointer to where the full notice is found. - - One line to give the program's name and a brief idea of what it does. - - Copyright (C) - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., 59 - Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this when it -starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author Gnomovision comes - with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free - software, and you are welcome to redistribute it under certain conditions; - type 'show c' for details. - -The hypothetical commands 'show w' and 'show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may be -called something other than 'show w' and 'show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your school, -if any, to sign a "copyright disclaimer" for the program, if necessary. Here -is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - 'Gnomovision' (which makes passes at compilers) written by James Hacker. - - signature of Ty Coon, 1 April 1989 - - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General Public -License instead of this License. - - -"CLASSPATH" EXCEPTION TO THE GPL - -Certain source files distributed by Oracle America and/or its affiliates are -subject to the following clarification and special exception to the GPL, but -only where Oracle has expressly included in the particular source file's header -the words "Oracle designates this particular file as subject to the "Classpath" -exception as provided by Oracle in the LICENSE file that accompanied this code." - - Linking this library statically or dynamically with other modules is making - a combined work based on this library. Thus, the terms and conditions of - the GNU General Public License cover the whole combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent modules, - and to copy and distribute the resulting executable under terms of your - choice, provided that you also meet, for each linked independent module, - the terms and conditions of the license of that module. An independent - module is a module which is not derived from or based on this library. If - you modify this library, you may extend this exception to your version of - the library, but you are not obligated to do so. If you do not wish to do - so, delete this exception statement from your version. diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/util/SAAbstractMap.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/util/SAAbstractMap.java deleted file mode 100644 index dc7ff57..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/util/SAAbstractMap.java +++ /dev/null @@ -1,842 +0,0 @@ -package org.ObjectLayout.examples.util; -/* Ported from OpenJDK8's java.util.AbstractMap by Gil Tene. - * Copyright (c) 2015, Gil Tene. All rights reserved. - * Please note the LICENSE file in this directory, and the below - * Oracle copyright, GPLv2 license notice, and Classpath EXception. - */ -/* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import java.util.*; - -/** - * This class provides a skeletal implementation of the Map - * interface, to minimize the effort required to implement this interface. - * - *

To implement an unmodifiable map, the programmer needs only to extend this - * class and provide an implementation for the entrySet method, which - * returns a set-view of the map's mappings. Typically, the returned set - * will, in turn, be implemented atop AbstractSet. This set should - * not support the add or remove methods, and its iterator - * should not support the remove method. - * - *

To implement a modifiable map, the programmer must additionally override - * this class's put method (which otherwise throws an - * UnsupportedOperationException), and the iterator returned by - * entrySet().iterator() must additionally implement its - * remove method. - * - *

The programmer should generally provide a void (no argument) and map - * constructor, as per the recommendation in the Map interface - * specification. - * - *

The documentation for each non-abstract method in this class describes its - * implementation in detail. Each of these methods may be overridden if the - * map being implemented admits a more efficient implementation. - * - *

This class is a member of the - * - * Java Collections Framework. - * - * @param the type of keys maintained by this map - * @param the type of mapped values - * - * @author Josh Bloch - * @author Neal Gafter - * @see Map - * @see Collection - * @since 1.2 - */ - -public abstract class SAAbstractMap implements Map { - /** - * Sole constructor. (For invocation by subclass constructors, typically - * implicit.) - */ - protected SAAbstractMap() { - } - - // Query Operations - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation returns entrySet().size(). - */ - public int size() { - return entrySet().size(); - } - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation returns size() == 0. - */ - public boolean isEmpty() { - return size() == 0; - } - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation iterates over entrySet() searching - * for an entry with the specified value. If such an entry is found, - * true is returned. If the iteration terminates without - * finding such an entry, false is returned. Note that this - * implementation requires linear time in the size of the map. - * - * @throws ClassCastException {@inheritDoc} - * @throws NullPointerException {@inheritDoc} - */ - public boolean containsValue(Object value) { - Iterator> i = entrySet().iterator(); - if (value==null) { - while (i.hasNext()) { - Entry e = i.next(); - if (e.getValue()==null) - return true; - } - } else { - while (i.hasNext()) { - Entry e = i.next(); - if (value.equals(e.getValue())) - return true; - } - } - return false; - } - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation iterates over entrySet() searching - * for an entry with the specified key. If such an entry is found, - * true is returned. If the iteration terminates without - * finding such an entry, false is returned. Note that this - * implementation requires linear time in the size of the map; many - * implementations will override this method. - * - * @throws ClassCastException {@inheritDoc} - * @throws NullPointerException {@inheritDoc} - */ - public boolean containsKey(Object key) { - Iterator> i = entrySet().iterator(); - if (key==null) { - while (i.hasNext()) { - Entry e = i.next(); - if (e.getKey()==null) - return true; - } - } else { - while (i.hasNext()) { - Entry e = i.next(); - if (key.equals(e.getKey())) - return true; - } - } - return false; - } - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation iterates over entrySet() searching - * for an entry with the specified key. If such an entry is found, - * the entry's value is returned. If the iteration terminates without - * finding such an entry, null is returned. Note that this - * implementation requires linear time in the size of the map; many - * implementations will override this method. - * - * @throws ClassCastException {@inheritDoc} - * @throws NullPointerException {@inheritDoc} - */ - public V get(Object key) { - Iterator> i = entrySet().iterator(); - if (key==null) { - while (i.hasNext()) { - Entry e = i.next(); - if (e.getKey()==null) - return e.getValue(); - } - } else { - while (i.hasNext()) { - Entry e = i.next(); - if (key.equals(e.getKey())) - return e.getValue(); - } - } - return null; - } - - - // Modification Operations - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation always throws an - * UnsupportedOperationException. - * - * @throws UnsupportedOperationException {@inheritDoc} - * @throws ClassCastException {@inheritDoc} - * @throws NullPointerException {@inheritDoc} - * @throws IllegalArgumentException {@inheritDoc} - */ - public V put(K key, V value) { - throw new UnsupportedOperationException(); - } - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation iterates over entrySet() searching for an - * entry with the specified key. If such an entry is found, its value is - * obtained with its getValue operation, the entry is removed - * from the collection (and the backing map) with the iterator's - * remove operation, and the saved value is returned. If the - * iteration terminates without finding such an entry, null is - * returned. Note that this implementation requires linear time in the - * size of the map; many implementations will override this method. - * - *

Note that this implementation throws an - * UnsupportedOperationException if the entrySet - * iterator does not support the remove method and this map - * contains a mapping for the specified key. - * - * @throws UnsupportedOperationException {@inheritDoc} - * @throws ClassCastException {@inheritDoc} - * @throws NullPointerException {@inheritDoc} - */ - public V remove(Object key) { - Iterator> i = entrySet().iterator(); - Entry correctEntry = null; - if (key==null) { - while (correctEntry==null && i.hasNext()) { - Entry e = i.next(); - if (e.getKey()==null) - correctEntry = e; - } - } else { - while (correctEntry==null && i.hasNext()) { - Entry e = i.next(); - if (key.equals(e.getKey())) - correctEntry = e; - } - } - - V oldValue = null; - if (correctEntry !=null) { - oldValue = correctEntry.getValue(); - i.remove(); - } - return oldValue; - } - - - // Bulk Operations - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation iterates over the specified map's - * entrySet() collection, and calls this map's put - * operation once for each entry returned by the iteration. - * - *

Note that this implementation throws an - * UnsupportedOperationException if this map does not support - * the put operation and the specified map is nonempty. - * - * @throws UnsupportedOperationException {@inheritDoc} - * @throws ClassCastException {@inheritDoc} - * @throws NullPointerException {@inheritDoc} - * @throws IllegalArgumentException {@inheritDoc} - */ - public void putAll(Map m) { - for (Map.Entry e : m.entrySet()) - put(e.getKey(), e.getValue()); - } - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation calls entrySet().clear(). - * - *

Note that this implementation throws an - * UnsupportedOperationException if the entrySet - * does not support the clear operation. - * - * @throws UnsupportedOperationException {@inheritDoc} - */ - public void clear() { - entrySet().clear(); - } - - - // Views - - /** - * Each of these fields are initialized to contain an instance of the - * appropriate view the first time this view is requested. The views are - * stateless, so there's no reason to create more than one of each. - */ - transient volatile Set keySet; - transient volatile Collection values; - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation returns a set that subclasses {@link AbstractSet}. - * The subclass's iterator method returns a "wrapper object" over this - * map's entrySet() iterator. The size method - * delegates to this map's size method and the - * contains method delegates to this map's - * containsKey method. - * - *

The set is created the first time this method is called, - * and returned in response to all subsequent calls. No synchronization - * is performed, so there is a slight chance that multiple calls to this - * method will not all return the same set. - */ - public Set keySet() { - if (keySet == null) { - keySet = new AbstractSet() { - public Iterator iterator() { - return new Iterator() { - private Iterator> i = entrySet().iterator(); - - public boolean hasNext() { - return i.hasNext(); - } - - public K next() { - return i.next().getKey(); - } - - public void remove() { - i.remove(); - } - }; - } - - public int size() { - return SAAbstractMap.this.size(); - } - - public boolean isEmpty() { - return SAAbstractMap.this.isEmpty(); - } - - public void clear() { - SAAbstractMap.this.clear(); - } - - public boolean contains(Object k) { - return SAAbstractMap.this.containsKey(k); - } - }; - } - return keySet; - } - - /** - * {@inheritDoc} - * - * @implSpec - * This implementation returns a collection that subclasses {@link - * AbstractCollection}. The subclass's iterator method returns a - * "wrapper object" over this map's entrySet() iterator. - * The size method delegates to this map's size - * method and the contains method delegates to this map's - * containsValue method. - * - *

The collection is created the first time this method is called, and - * returned in response to all subsequent calls. No synchronization is - * performed, so there is a slight chance that multiple calls to this - * method will not all return the same collection. - */ - public Collection values() { - if (values == null) { - values = new AbstractCollection() { - public Iterator iterator() { - return new Iterator() { - private Iterator> i = entrySet().iterator(); - - public boolean hasNext() { - return i.hasNext(); - } - - public V next() { - return i.next().getValue(); - } - - public void remove() { - i.remove(); - } - }; - } - - public int size() { - return SAAbstractMap.this.size(); - } - - public boolean isEmpty() { - return SAAbstractMap.this.isEmpty(); - } - - public void clear() { - SAAbstractMap.this.clear(); - } - - public boolean contains(Object v) { - return SAAbstractMap.this.containsValue(v); - } - }; - } - return values; - } - - public abstract Set> entrySet(); - - - // Comparison and hashing - - /** - * Compares the specified object with this map for equality. Returns - * true if the given object is also a map and the two maps - * represent the same mappings. More formally, two maps m1 and - * m2 represent the same mappings if - * m1.entrySet().equals(m2.entrySet()). This ensures that the - * equals method works properly across different implementations - * of the Map interface. - * - * @implSpec - * This implementation first checks if the specified object is this map; - * if so it returns true. Then, it checks if the specified - * object is a map whose size is identical to the size of this map; if - * not, it returns false. If so, it iterates over this map's - * entrySet collection, and checks that the specified map - * contains each mapping that this map contains. If the specified map - * fails to contain such a mapping, false is returned. If the - * iteration completes, true is returned. - * - * @param o object to be compared for equality with this map - * @return true if the specified object is equal to this map - */ - public boolean equals(Object o) { - if (o == this) - return true; - - if (!(o instanceof Map)) - return false; - Map m = (Map) o; - if (m.size() != size()) - return false; - - try { - Iterator> i = entrySet().iterator(); - while (i.hasNext()) { - Entry e = i.next(); - K key = e.getKey(); - V value = e.getValue(); - if (value == null) { - if (!(m.get(key)==null && m.containsKey(key))) - return false; - } else { - if (!value.equals(m.get(key))) - return false; - } - } - } catch (ClassCastException unused) { - return false; - } catch (NullPointerException unused) { - return false; - } - - return true; - } - - /** - * Returns the hash code value for this map. The hash code of a map is - * defined to be the sum of the hash codes of each entry in the map's - * entrySet() view. This ensures that m1.equals(m2) - * implies that m1.hashCode()==m2.hashCode() for any two maps - * m1 and m2, as required by the general contract of - * {@link Object#hashCode}. - * - * @implSpec - * This implementation iterates over entrySet(), calling - * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the - * set, and adding up the results. - * - * @return the hash code value for this map - * @see Map.Entry#hashCode() - * @see Object#equals(Object) - * @see Set#equals(Object) - */ - public int hashCode() { - int h = 0; - Iterator> i = entrySet().iterator(); - while (i.hasNext()) - h += i.next().hashCode(); - return h; - } - - /** - * Returns a string representation of this map. The string representation - * consists of a list of key-value mappings in the order returned by the - * map's entrySet view's iterator, enclosed in braces - * ("{}"). Adjacent mappings are separated by the characters - * ", " (comma and space). Each key-value mapping is rendered as - * the key followed by an equals sign ("=") followed by the - * associated value. Keys and values are converted to strings as by - * {@link String#valueOf(Object)}. - * - * @return a string representation of this map - */ - public String toString() { - Iterator> i = entrySet().iterator(); - if (! i.hasNext()) - return "{}"; - - StringBuilder sb = new StringBuilder(); - sb.append('{'); - for (;;) { - Entry e = i.next(); - K key = e.getKey(); - V value = e.getValue(); - sb.append(key == this ? "(this Map)" : key); - sb.append('='); - sb.append(value == this ? "(this Map)" : value); - if (! i.hasNext()) - return sb.append('}').toString(); - sb.append(',').append(' '); - } - } - - /** - * Returns a shallow copy of this AbstractMap instance: the keys - * and values themselves are not cloned. - * - * @return a shallow copy of this map - */ - protected Object clone() throws CloneNotSupportedException { - SAAbstractMap result = (SAAbstractMap)super.clone(); - result.keySet = null; - result.values = null; - return result; - } - - /** - * Utility method for SimpleEntry and SimpleImmutableEntry. - * Test for equality, checking for nulls. - * - * NB: Do not replace with Object.equals until JDK-8015417 is resolved. - */ - private static boolean eq(Object o1, Object o2) { - return o1 == null ? o2 == null : o1.equals(o2); - } - - // Implementation Note: SimpleEntry and SimpleImmutableEntry - // are distinct unrelated classes, even though they share - // some code. Since you can't add or subtract final-ness - // of a field in a subclass, they can't share representations, - // and the amount of duplicated code is too small to warrant - // exposing a common abstract class. - - - /** - * An Entry maintaining a key and a value. The value may be - * changed using the setValue method. This class - * facilitates the process of building custom map - * implementations. For example, it may be convenient to return - * arrays of SimpleEntry instances in method - * Map.entrySet().toArray. - * - * @since 1.6 - */ - public static class SimpleEntry - implements Entry, java.io.Serializable - { - private static final long serialVersionUID = -8499721149061103585L; - - private final K key; - private V value; - - /** - * Creates an entry representing a mapping from the specified - * key to the specified value. - * - * @param key the key represented by this entry - * @param value the value represented by this entry - */ - public SimpleEntry(K key, V value) { - this.key = key; - this.value = value; - } - - /** - * Creates an entry representing the same mapping as the - * specified entry. - * - * @param entry the entry to copy - */ - public SimpleEntry(Entry entry) { - this.key = entry.getKey(); - this.value = entry.getValue(); - } - - /** - * Returns the key corresponding to this entry. - * - * @return the key corresponding to this entry - */ - public K getKey() { - return key; - } - - /** - * Returns the value corresponding to this entry. - * - * @return the value corresponding to this entry - */ - public V getValue() { - return value; - } - - /** - * Replaces the value corresponding to this entry with the specified - * value. - * - * @param value new value to be stored in this entry - * @return the old value corresponding to the entry - */ - public V setValue(V value) { - V oldValue = this.value; - this.value = value; - return oldValue; - } - - /** - * Compares the specified object with this entry for equality. - * Returns {@code true} if the given object is also a map entry and - * the two entries represent the same mapping. More formally, two - * entries {@code e1} and {@code e2} represent the same mapping - * if

-         *   (e1.getKey()==null ?
-         *    e2.getKey()==null :
-         *    e1.getKey().equals(e2.getKey()))
-         *   &&
-         *   (e1.getValue()==null ?
-         *    e2.getValue()==null :
-         *    e1.getValue().equals(e2.getValue()))
- * This ensures that the {@code equals} method works properly across - * different implementations of the {@code Map.Entry} interface. - * - * @param o object to be compared for equality with this map entry - * @return {@code true} if the specified object is equal to this map - * entry - * @see #hashCode - */ - public boolean equals(Object o) { - if (!(o instanceof Map.Entry)) - return false; - Map.Entry e = (Map.Entry)o; - return eq(key, e.getKey()) && eq(value, e.getValue()); - } - - /** - * Returns the hash code value for this map entry. The hash code - * of a map entry {@code e} is defined to be:
-         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
-         *   (e.getValue()==null ? 0 : e.getValue().hashCode())
- * This ensures that {@code e1.equals(e2)} implies that - * {@code e1.hashCode()==e2.hashCode()} for any two Entries - * {@code e1} and {@code e2}, as required by the general - * contract of {@link Object#hashCode}. - * - * @return the hash code value for this map entry - * @see #equals - */ - public int hashCode() { - return (key == null ? 0 : key.hashCode()) ^ - (value == null ? 0 : value.hashCode()); - } - - /** - * Returns a String representation of this map entry. This - * implementation returns the string representation of this - * entry's key followed by the equals character ("=") - * followed by the string representation of this entry's value. - * - * @return a String representation of this map entry - */ - public String toString() { - return key + "=" + value; - } - - } - - /** - * An Entry maintaining an immutable key and value. This class - * does not support method setValue. This class may be - * convenient in methods that return thread-safe snapshots of - * key-value mappings. - * - * @since 1.6 - */ - public static class SimpleImmutableEntry - implements Entry, java.io.Serializable - { - private static final long serialVersionUID = 7138329143949025153L; - - private final K key; - private final V value; - - /** - * Creates an entry representing a mapping from the specified - * key to the specified value. - * - * @param key the key represented by this entry - * @param value the value represented by this entry - */ - public SimpleImmutableEntry(K key, V value) { - this.key = key; - this.value = value; - } - - /** - * Creates an entry representing the same mapping as the - * specified entry. - * - * @param entry the entry to copy - */ - public SimpleImmutableEntry(Entry entry) { - this.key = entry.getKey(); - this.value = entry.getValue(); - } - - /** - * Returns the key corresponding to this entry. - * - * @return the key corresponding to this entry - */ - public K getKey() { - return key; - } - - /** - * Returns the value corresponding to this entry. - * - * @return the value corresponding to this entry - */ - public V getValue() { - return value; - } - - /** - * Replaces the value corresponding to this entry with the specified - * value (optional operation). This implementation simply throws - * UnsupportedOperationException, as this class implements - * an immutable map entry. - * - * @param value new value to be stored in this entry - * @return (Does not return) - * @throws UnsupportedOperationException always - */ - public V setValue(V value) { - throw new UnsupportedOperationException(); - } - - /** - * Compares the specified object with this entry for equality. - * Returns {@code true} if the given object is also a map entry and - * the two entries represent the same mapping. More formally, two - * entries {@code e1} and {@code e2} represent the same mapping - * if
-         *   (e1.getKey()==null ?
-         *    e2.getKey()==null :
-         *    e1.getKey().equals(e2.getKey()))
-         *   &&
-         *   (e1.getValue()==null ?
-         *    e2.getValue()==null :
-         *    e1.getValue().equals(e2.getValue()))
- * This ensures that the {@code equals} method works properly across - * different implementations of the {@code Map.Entry} interface. - * - * @param o object to be compared for equality with this map entry - * @return {@code true} if the specified object is equal to this map - * entry - * @see #hashCode - */ - public boolean equals(Object o) { - if (!(o instanceof Map.Entry)) - return false; - Map.Entry e = (Map.Entry)o; - return eq(key, e.getKey()) && eq(value, e.getValue()); - } - - /** - * Returns the hash code value for this map entry. The hash code - * of a map entry {@code e} is defined to be:
-         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
-         *   (e.getValue()==null ? 0 : e.getValue().hashCode())
- * This ensures that {@code e1.equals(e2)} implies that - * {@code e1.hashCode()==e2.hashCode()} for any two Entries - * {@code e1} and {@code e2}, as required by the general - * contract of {@link Object#hashCode}. - * - * @return the hash code value for this map entry - * @see #equals - */ - public int hashCode() { - return (key == null ? 0 : key.hashCode()) ^ - (value == null ? 0 : value.hashCode()); - } - - /** - * Returns a String representation of this map entry. This - * implementation returns the string representation of this - * entry's key followed by the equals character ("=") - * followed by the string representation of this entry's value. - * - * @return a String representation of this map entry - */ - public String toString() { - return key + "=" + value; - } - - } - -} \ No newline at end of file diff --git a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/util/SAHashMap.java b/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/util/SAHashMap.java deleted file mode 100644 index f6ff5f6..0000000 --- a/ObjectLayout-examples/src/main/java/org/ObjectLayout/examples/util/SAHashMap.java +++ /dev/null @@ -1,2476 +0,0 @@ -package org.ObjectLayout.examples.util; -/* Ported from OpenJDK8's java.util.HashMap by Gil Tene. - * Copyright (c) 2015, Gil Tene. All rights reserved. - * Please note the LICENSE file in this directory, and the below - * Oracle copyright, GPLv2 license notice, and Classpath EXception. - */ -/* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.Serializable; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.*; -import java.util.function.BiConsumer; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Function; - -import org.ObjectLayout.CtorAndArgs; -import org.ObjectLayout.StructuredArray; - -/** - * Hash table based implementation of the Map interface. This - * implementation provides all of the optional map operations, and permits - * null values and the null key. (The HashMap - * class is roughly equivalent to Hashtable, except that it is - * unsynchronized and permits nulls.) This class makes no guarantees as to - * the order of the map; in particular, it does not guarantee that the order - * will remain constant over time. - * - *

This implementation provides constant-time performance for the basic - * operations (get and put), assuming the hash function - * disperses the elements properly among the buckets. Iteration over - * collection views requires time proportional to the "capacity" of the - * HashMap instance (the number of buckets) plus its size (the number - * of key-value mappings). Thus, it's very important not to set the initial - * capacity too high (or the load factor too low) if iteration performance is - * important. - * - *

An instance of HashMap has two parameters that affect its - * performance: initial capacity and load factor. The - * capacity is the number of buckets in the hash table, and the initial - * capacity is simply the capacity at the time the hash table is created. The - * load factor is a measure of how full the hash table is allowed to - * get before its capacity is automatically increased. When the number of - * entries in the hash table exceeds the product of the load factor and the - * current capacity, the hash table is rehashed (that is, internal data - * structures are rebuilt) so that the hash table has approximately twice the - * number of buckets. - * - *

As a general rule, the default load factor (.75) offers a good - * tradeoff between time and space costs. Higher values decrease the - * space overhead but increase the lookup cost (reflected in most of - * the operations of the HashMap class, including - * get and put). The expected number of entries in - * the map and its load factor should be taken into account when - * setting its initial capacity, so as to minimize the number of - * rehash operations. If the initial capacity is greater than the - * maximum number of entries divided by the load factor, no rehash - * operations will ever occur. - * - *

If many mappings are to be stored in a HashMap - * instance, creating it with a sufficiently large capacity will allow - * the mappings to be stored more efficiently than letting it perform - * automatic rehashing as needed to grow the table. Note that using - * many keys with the same {@code hashCode()} is a sure way to slow - * down performance of any hash table. To ameliorate impact, when keys - * are {@link Comparable}, this class may use comparison order among - * keys to help break ties. - * - *

Note that this implementation is not synchronized. - * If multiple threads access a hash map concurrently, and at least one of - * the threads modifies the map structurally, it must be - * synchronized externally. (A structural modification is any operation - * that adds or deletes one or more mappings; merely changing the value - * associated with a key that an instance already contains is not a - * structural modification.) This is typically accomplished by - * synchronizing on some object that naturally encapsulates the map. - * - * If no such object exists, the map should be "wrapped" using the - * {@link Collections#synchronizedMap Collections.synchronizedMap} - * method. This is best done at creation time, to prevent accidental - * unsynchronized access to the map:

- *   Map m = Collections.synchronizedMap(new HashMap(...));
- * - *

The iterators returned by all of this class's "collection view methods" - * are fail-fast: if the map is structurally modified at any time after - * the iterator is created, in any way except through the iterator's own - * remove method, the iterator will throw a - * {@link ConcurrentModificationException}. Thus, in the face of concurrent - * modification, the iterator fails quickly and cleanly, rather than risking - * arbitrary, non-deterministic behavior at an undetermined time in the - * future. - * - *

Note that the fail-fast behavior of an iterator cannot be guaranteed - * as it is, generally speaking, impossible to make any hard guarantees in the - * presence of unsynchronized concurrent modification. Fail-fast iterators - * throw ConcurrentModificationException on a best-effort basis. - * Therefore, it would be wrong to write a program that depended on this - * exception for its correctness: the fail-fast behavior of iterators - * should be used only to detect bugs. - * - *

This class is a member of the - * - * Java Collections Framework. - * - * @param the type of keys maintained by this map - * @param the type of mapped values - * - * @author Doug Lea - * @author Josh Bloch - * @author Arthur van Hoff - * @author Neal Gafter - * @see Object#hashCode() - * @see Collection - * @see Map - * @see TreeMap - * @see Hashtable - * @since 1.2 - */ -public class SAHashMap extends SAAbstractMap - implements Map, Cloneable, Serializable { - - private static final long serialVersionUID = 362498820763181265L; - - /* - * Implementation notes. - * - * This map usually acts as a binned (bucketed) hash table, but - * when bins get too large, they are transformed into bins of - * TreeNodes, each structured similarly to those in - * java.util.TreeMap. Most methods try to use normal bins, but - * relay to TreeNode methods when applicable (simply by checking - * instanceof a node). Bins of TreeNodes may be traversed and - * used like any others, but additionally support faster lookup - * when overpopulated. However, since the vast majority of bins in - * normal use are not overpopulated, checking for existence of - * tree bins may be delayed in the course of table methods. - * - * Tree bins (i.e., bins whose elements are all TreeNodes) are - * ordered primarily by hashCode, but in the case of ties, if two - * elements are of the same "class C implements Comparable", - * type then their compareTo method is used for ordering. (We - * conservatively check generic types via reflection to validate - * this -- see method comparableClassFor). The added complexity - * of tree bins is worthwhile in providing worst-case O(log n) - * operations when keys either have distinct hashes or are - * orderable, Thus, performance degrades gracefully under - * accidental or malicious usages in which hashCode() methods - * return values that are poorly distributed, as well as those in - * which many keys share a hashCode, so long as they are also - * Comparable. (If neither of these apply, we may waste about a - * factor of two in time and space compared to taking no - * precautions. But the only known cases stem from poor user - * programming practices that are already so slow that this makes - * little difference.) - * - * Because TreeNodes are about twice the size of regular nodes, we - * use them only when bins contain enough nodes to warrant use - * (see TREEIFY_THRESHOLD). And when they become too small (due to - * removal or resizing) they are converted back to plain bins. In - * usages with well-distributed user hashCodes, tree bins are - * rarely used. Ideally, under random hashCodes, the frequency of - * nodes in bins follows a Poisson distribution - * (http://en.wikipedia.org/wiki/Poisson_distribution) with a - * parameter of about 0.5 on average for the default resizing - * threshold of 0.75, although with a large variance because of - * resizing granularity. Ignoring variance, the expected - * occurrences of list size k are (exp(-0.5) * pow(0.5, k) / - * factorial(k)). The first values are: - * - * 0: 0.60653066 - * 1: 0.30326533 - * 2: 0.07581633 - * 3: 0.01263606 - * 4: 0.00157952 - * 5: 0.00015795 - * 6: 0.00001316 - * 7: 0.00000094 - * 8: 0.00000006 - * more: less than 1 in ten million - * - * The root of a tree bin is normally its first node. However, - * sometimes (currently only upon Iterator.remove), the root might - * be elsewhere, but can be recovered following parent links - * (method TreeNode.root()). - * - * All applicable internal methods accept a hash code as an - * argument (as normally supplied from a public method), allowing - * them to call each other without recomputing user hashCodes. - * Most internal methods also accept a "tab" argument, that is - * normally the current table, but may be a new or old one when - * resizing or converting. - * - * When bin lists are treeified, split, or untreeified, we keep - * them in the same relative access/traversal order (i.e., field - * Node.next) to better preserve locality, and to slightly - * simplify handling of splits and traversals that invoke - * iterator.remove. When using comparators on insertion, to keep a - * total ordering (or as close as is required here) across - * rebalancings, we compare classes and identityHashCodes as - * tie-breakers. - * - * The use and transitions among plain vs tree modes is - * complicated by the existence of subclass LinkedHashMap. See - * below for hook methods defined to be invoked upon insertion, - * removal and access that allow LinkedHashMap internals to - * otherwise remain independent of these mechanics. (This also - * requires that a map instance be passed to some utility methods - * that may create new nodes.) - * - * The concurrent-programming-like SSA-based coding style helps - * avoid aliasing errors amid all of the twisty pointer operations. - */ - - /** - * The default initial capacity - MUST be a power of two. - */ - static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16 - - /** - * The maximum capacity, used if a higher value is implicitly specified - * by either of the constructors with arguments. - * MUST be a power of two <= 1<<30. - */ - static final int MAXIMUM_CAPACITY = 1 << 30; - - /** - * The load factor used when none specified in constructor. - */ - static final float DEFAULT_LOAD_FACTOR = 0.75f; - - /** - * The bin count threshold for using a tree rather than list for a - * bin. Bins are converted to trees when adding an element to a - * bin with at least this many nodes. The value must be greater - * than 2 and should be at least 8 to mesh with assumptions in - * tree removal about conversion back to plain bins upon - * shrinkage. - */ - static final int TREEIFY_THRESHOLD = 8; - - /** - * The bin count threshold for untreeifying a (split) bin during a - * resize operation. Should be less than TREEIFY_THRESHOLD, and at - * most 6 to mesh with shrinkage detection under removal. - */ - static final int UNTREEIFY_THRESHOLD = 6; - - /** - * The smallest table capacity for which bins may be treeified. - * (Otherwise the table is resized if too many nodes in a bin.) - * Should be at least 4 * TREEIFY_THRESHOLD to avoid conflicts - * between resizing and treeification thresholds. - */ - static final int MIN_TREEIFY_CAPACITY = 64; - - /** - * Basic hash bin node, used for most entries. (See below for - * TreeNode subclass, and in LinkedHashMap for its Entry subclass.) - */ - static class Node implements Map.Entry { - int hash; - K key; - V value; - Node next; - private boolean isSentinel = true; - - Node(int hash, K key, V value, Node next) { - this.hash = hash; - this.key = key; - this.value = value; - this.next = next; - this.isSentinel = false; - } - - Node() { - } - - public void setContents(int hash, K key, V value, Node next) { - this.hash = hash; - this.key = key; - this.value = value; - this.next = next; - this.isSentinel = false; - } - - public void setContents(Node e) { - if (e != null) { - this.hash = e.hash; - this.key = e.key; - this.value = e.value; - this.next = e.next; - this.isSentinel = e.isSentinel; - } else { - this.isSentinel = true; - } - } - - public boolean isSentinel() { - return isSentinel; - } - - public void setSentinel(boolean isSentinel) { - this.isSentinel = isSentinel; - } - - public final K getKey() { return key; } - public final V getValue() { return value; } - public final String toString() { return key + "=" + value; } - - public final int hashCode() { - return Objects.hashCode(key) ^ Objects.hashCode(value); - } - - public final V setValue(V newValue) { - V oldValue = value; - value = newValue; - return oldValue; - } - - public final boolean equals(Object o) { - if (o == this) - return true; - if (o instanceof Map.Entry) { - Map.Entry e = (Map.Entry)o; - if (Objects.equals(key, e.getKey()) && - Objects.equals(value, e.getValue())) - return true; - } - return false; - } - } - - /* ---------------- Static utilities -------------- */ - - /** - * Computes key.hashCode() and spreads (XORs) higher bits of hash - * to lower. Because the table uses power-of-two masking, sets of - * hashes that vary only in bits above the current mask will - * always collide. (Among known examples are sets of Float keys - * holding consecutive whole numbers in small tables.) So we - * apply a transform that spreads the impact of higher bits - * downward. There is a tradeoff between speed, utility, and - * quality of bit-spreading. Because many common sets of hashes - * are already reasonably distributed (so don't benefit from - * spreading), and because we use trees to handle large sets of - * collisions in bins, we just XOR some shifted bits in the - * cheapest possible way to reduce systematic lossage, as well as - * to incorporate impact of the highest bits that would otherwise - * never be used in index calculations because of table bounds. - */ - static final int hash(Object key) { - int h; - return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16); - } - - /** - * Returns x's Class if it is of the form "class C implements - * Comparable", else null. - */ - static Class comparableClassFor(Object x) { - if (x instanceof Comparable) { - Class c; Type[] ts, as; Type t; ParameterizedType p; - if ((c = x.getClass()) == String.class) // bypass checks - return c; - if ((ts = c.getGenericInterfaces()) != null) { - for (int i = 0; i < ts.length; ++i) { - if (((t = ts[i]) instanceof ParameterizedType) && - ((p = (ParameterizedType)t).getRawType() == - Comparable.class) && - (as = p.getActualTypeArguments()) != null && - as.length == 1 && as[0] == c) // type arg is c - return c; - } - } - } - return null; - } - - /** - * Returns k.compareTo(x) if x matches kc (k's screened comparable - * class), else 0. - */ - @SuppressWarnings({"rawtypes","unchecked"}) // for cast to Comparable - static int compareComparables(Class kc, Object k, Object x) { - return (x == null || x.getClass() != kc ? 0 : - ((Comparable)k).compareTo(x)); - } - - /** - * Returns a power of two size for the given target capacity. - */ - static final int tableSizeFor(int cap) { - int n = cap - 1; - n |= n >>> 1; - n |= n >>> 2; - n |= n >>> 4; - n |= n >>> 8; - n |= n >>> 16; - return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1; - } - - /* ---------------- Fields -------------- */ - - static class NodeTable extends StructuredArray> { - private static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - static final Constructor nodeConstructor; - static final CtorAndArgs nodeCtorAndArgs; - static final Constructor nodeTableConstructor; - static final CtorAndArgs nodeTableCtorAndArgs; - static { - try { - nodeConstructor = Node.class.getDeclaredConstructor(); - nodeConstructor.setAccessible(true); - nodeCtorAndArgs = new CtorAndArgs(nodeConstructor); - nodeTableConstructor = NodeTable.class.getDeclaredConstructor(); - nodeTableConstructor.setAccessible(true); - nodeTableCtorAndArgs = new CtorAndArgs(nodeTableConstructor); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - - @SuppressWarnings("unchecked") - public static NodeTable newInstance(final long length) { - return StructuredArray.newInstance(nodeTableCtorAndArgs, nodeCtorAndArgs, length); -// return StructuredArray.newInstance(lookup, NodeTable.class, Node.class, length); - } - } - - /** - * The table, initialized on first use, and resized as - * necessary. When allocated, length is always a power of two. - * (We also tolerate length zero in some operations to allow - * bootstrapping mechanics that are currently not needed.) - */ -// transient Node[] table; - transient NodeTable saTable; - - /** - * Holds cached entrySet(). Note that AbstractMap fields are used - * for keySet() and values(). - */ - transient Set> entrySet; - - /** - * The number of key-value mappings contained in this map. - */ - transient int size; - - /** - * The number of times this HashMap has been structurally modified - * Structural modifications are those that change the number of mappings in - * the HashMap or otherwise modify its internal structure (e.g., - * rehash). This field is used to make iterators on Collection-views of - * the HashMap fail-fast. (See ConcurrentModificationException). - */ - transient int modCount; - - /** - * The next size value at which to resize (capacity * load factor). - * - * @serial - */ - // (The javadoc description is true upon serialization. - // Additionally, if the table array has not been allocated, this - // field holds the initial array capacity, or zero signifying - // DEFAULT_INITIAL_CAPACITY.) - int threshold; - - /** - * The load factor for the hash table. - * - * @serial - */ - final float loadFactor; - - /* ---------------- Public operations -------------- */ - - /** - * Constructs an empty HashMap with the specified initial - * capacity and load factor. - * - * @param initialCapacity the initial capacity - * @param loadFactor the load factor - * @throws IllegalArgumentException if the initial capacity is negative - * or the load factor is nonpositive - */ - public SAHashMap(int initialCapacity, float loadFactor) { - if (initialCapacity < 0) - throw new IllegalArgumentException("Illegal initial capacity: " + - initialCapacity); - if (initialCapacity > MAXIMUM_CAPACITY) - initialCapacity = MAXIMUM_CAPACITY; - if (loadFactor <= 0 || Float.isNaN(loadFactor)) - throw new IllegalArgumentException("Illegal load factor: " + - loadFactor); - this.loadFactor = loadFactor; - this.threshold = tableSizeFor(initialCapacity); - } - - /** - * Constructs an empty HashMap with the specified initial - * capacity and the default load factor (0.75). - * - * @param initialCapacity the initial capacity. - * @throws IllegalArgumentException if the initial capacity is negative. - */ - public SAHashMap(int initialCapacity) { - this(initialCapacity, DEFAULT_LOAD_FACTOR); - } - - /** - * Constructs an empty HashMap with the default initial capacity - * (16) and the default load factor (0.75). - */ - public SAHashMap() { - this.loadFactor = DEFAULT_LOAD_FACTOR; // all other fields defaulted - } - - /** - * Constructs a new HashMap with the same mappings as the - * specified Map. The HashMap is created with - * default load factor (0.75) and an initial capacity sufficient to - * hold the mappings in the specified Map. - * - * @param m the map whose mappings are to be placed in this map - * @throws NullPointerException if the specified map is null - */ - public SAHashMap(Map m) { - this.loadFactor = DEFAULT_LOAD_FACTOR; - putMapEntries(m, false); - } - - /** - * Implements Map.putAll and Map constructor - * - * @param m the map - * @param evict false when initially constructing this map, else - * true (relayed to method afterNodeInsertion). - */ - final void putMapEntries(Map m, boolean evict) { - int s = m.size(); - if (s > 0) { - if (saTable == null) { // pre-size - float ft = ((float)s / loadFactor) + 1.0F; - int t = ((ft < (float)MAXIMUM_CAPACITY) ? - (int)ft : MAXIMUM_CAPACITY); - if (t > threshold) - threshold = tableSizeFor(t); - } - else if (s > threshold) - resize(); - for (Map.Entry e : m.entrySet()) { - K key = e.getKey(); - V value = e.getValue(); - putVal(hash(key), key, value, false, evict); - } - } - } - - /** - * Returns the number of key-value mappings in this map. - * - * @return the number of key-value mappings in this map - */ - public int size() { - return size; - } - - /** - * Returns true if this map contains no key-value mappings. - * - * @return true if this map contains no key-value mappings - */ - public boolean isEmpty() { - return size == 0; - } - - /** - * Returns the value to which the specified key is mapped, - * or {@code null} if this map contains no mapping for the key. - * - *

More formally, if this map contains a mapping from a key - * {@code k} to a value {@code v} such that {@code (key==null ? k==null : - * key.equals(k))}, then this method returns {@code v}; otherwise - * it returns {@code null}. (There can be at most one such mapping.) - * - *

A return value of {@code null} does not necessarily - * indicate that the map contains no mapping for the key; it's also - * possible that the map explicitly maps the key to {@code null}. - * The {@link #containsKey containsKey} operation may be used to - * distinguish these two cases. - * - * @see #put(Object, Object) - */ - public V get(Object key) { - Node e; - return (e = getNode(hash(key), key)) == null ? null : e.value; - } - - /** - * Implements Map.get and related methods - * - * @param hash hash for key - * @param key the key - * @return the node, or null if none - */ - final Node getNode(int hash, Object key) { - NodeTable tab; Node first, e; int n; K k; - if ((tab = saTable) != null && (n = (int)tab.getLength()) > 0 && - (first = tab.get((n - 1) & hash)).isSentinel() != true) { - if (first.hash == hash && // always check first node - ((k = first.key) == key || (key != null && key.equals(k)))) - return first; - if ((e = first.next) != null) { -// if (first instanceof TreeNode) -// return ((TreeNode)first).getTreeNode(hash, key); - do { - if (e.hash == hash && - ((k = e.key) == key || (key != null && key.equals(k)))) - return e; - } while ((e = e.next) != null); - } - } - return null; - } - - /** - * Returns true if this map contains a mapping for the - * specified key. - * - * @param key The key whose presence in this map is to be tested - * @return true if this map contains a mapping for the specified - * key. - */ - public boolean containsKey(Object key) { - return getNode(hash(key), key) != null; - } - - /** - * Associates the specified value with the specified key in this map. - * If the map previously contained a mapping for the key, the old - * value is replaced. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return the previous value associated with key, or - * null if there was no mapping for key. - * (A null return can also indicate that the map - * previously associated null with key.) - */ - public V put(K key, V value) { - return putVal(hash(key), key, value, false, true); - } - - /** - * Implements Map.put and related methods - * - * @param hash hash for key - * @param key the key - * @param value the value to put - * @param onlyIfAbsent if true, don't change existing value - * @param evict if false, the table is in creation mode. - * @return previous value, or null if none - */ - final V putVal(int hash, K key, V value, boolean onlyIfAbsent, - boolean evict) { - NodeTable tab; Node p; int n, i; - if ((tab = saTable) == null || (n = (int)tab.getLength()) == 0) - n = (int)(tab = resize()).getLength(); - if ((p = tab.get(i = (n - 1) & hash)).isSentinel() == true) -// tab[i] = newNode(hash, key, value, null); - tab.get(i).setContents(hash, key, value, null); - else { - Node e; K k; - if (p.hash == hash && - ((k = p.key) == key || (key != null && key.equals(k)))) - e = p; -// else if (p instanceof TreeNode) -// e = ((TreeNode)p).putTreeVal(this, tab, hash, key, value); - else { - for (int binCount = 0; ; ++binCount) { - if ((e = p.next) == null) { - p.next = newNode(hash, key, value, null); -// if (binCount >= TREEIFY_THRESHOLD - 1) // -1 for 1st -// treeifyBin(tab, hash); - break; - } - if (e.hash == hash && - ((k = e.key) == key || (key != null && key.equals(k)))) - break; - p = e; - } - } - if (e != null) { // existing mapping for key - V oldValue = e.value; - if (!onlyIfAbsent || oldValue == null) - e.value = value; - afterNodeAccess(e); - return oldValue; - } - } - ++modCount; - if (++size > threshold) - resize(); - afterNodeInsertion(evict); - return null; - } - - /** - * Initializes or doubles table size. If null, allocates in - * accord with initial capacity target held in field threshold. - * Otherwise, because we are using power-of-two expansion, the - * elements from each bin must either stay at same index, or move - * with a power of two offset in the new table. - * - * @return the table - */ - final NodeTable resize() { -// Node[] oldTab = table; - NodeTable oldTab = saTable; - int oldCap = (oldTab == null) ? 0 : (int) oldTab.getLength(); - int oldThr = threshold; - int newCap, newThr = 0; - if (oldCap > 0) { - if (oldCap >= MAXIMUM_CAPACITY) { - threshold = Integer.MAX_VALUE; - return oldTab; - } - else if ((newCap = oldCap << 1) < MAXIMUM_CAPACITY && - oldCap >= DEFAULT_INITIAL_CAPACITY) - newThr = oldThr << 1; // double threshold - } - else if (oldThr > 0) // initial capacity was placed in threshold - newCap = oldThr; - else { // zero initial threshold signifies using defaults - newCap = DEFAULT_INITIAL_CAPACITY; - newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY); - } - if (newThr == 0) { - float ft = (float)newCap * loadFactor; - newThr = (newCap < MAXIMUM_CAPACITY && ft < (float)MAXIMUM_CAPACITY ? - (int)ft : Integer.MAX_VALUE); - } - threshold = newThr; - @SuppressWarnings({"rawtypes","unchecked"}) -// Node[] newTab = (Node[])new Node[newCap]; - NodeTable newTab = NodeTable.newInstance(newCap); - saTable = newTab; - if (oldTab != null) { - for (int j = 0; j < oldCap; ++j) { - Node e; - if ((e = oldTab.get(j)).isSentinel != true) { -// oldTab[j] = null; -// oldTab.get(j).setSentinel(true); -// if (e.next == null) -// newTab[e.hash & (newCap - 1)] = e; - if (e.next == null) { - newTab.get(e.hash & (newCap - 1)).setContents(e); - } -// else if (e instanceof TreeNode) -// ((TreeNode)e).split(this, newTab, j, oldCap); - else { // preserve order - Node loHead = null, loTail = null; - Node hiHead = null, hiTail = null; - Node next; - do { - next = e.next; - if ((e.hash & oldCap) == 0) { - if (loTail == null) - loHead = e; - else - loTail.next = e; - loTail = e; - } - else { - if (hiTail == null) - hiHead = e; - else - hiTail.next = e; - hiTail = e; - } - } while ((e = next) != null); - if (loTail != null) { - loTail.next = null; -// newTab[j] = loHead; - newTab.get(j).setContents(loHead); - } - if (hiTail != null) { - hiTail.next = null; -// newTab[j + oldCap] = hiHead; - newTab.get(j + oldCap).setContents(hiHead); - } - } - } - } - } - return newTab; - } - - /** - * Replaces all linked nodes in bin at index for given hash unless - * table is too small, in which case resizes instead. - */ -// final void treeifyBin(NodeTable tab, int hash) { -// int n, index; Node e; -// if (tab == null || (n = (int)tab.getLength()) < MIN_TREEIFY_CAPACITY) -// resize(); -// else if ((e = tab.get(index = (n - 1) & hash)).isSentinel != true) { -// TreeNode hd = null, tl = null; -// do { -// TreeNode p = replacementTreeNode(e, null); -// if (tl == null) -// hd = p; -// else { -// p.prev = tl; -// tl.next = p; -// } -// tl = p; -// } while ((e = e.next) != null); -// if ((tab[index] = hd) != null) -// hd.treeify(tab); -// } -// } - - /** - * Copies all of the mappings from the specified map to this map. - * These mappings will replace any mappings that this map had for - * any of the keys currently in the specified map. - * - * @param m mappings to be stored in this map - * @throws NullPointerException if the specified map is null - */ - public void putAll(Map m) { - putMapEntries(m, true); - } - - /** - * Removes the mapping for the specified key from this map if present. - * - * @param key key whose mapping is to be removed from the map - * @return the previous value associated with key, or - * null if there was no mapping for key. - * (A null return can also indicate that the map - * previously associated null with key.) - */ - public V remove(Object key) { - Node e; - return (e = removeNode(hash(key), key, null, false, true)) == null ? - null : e.value; - } - - /** - * Implements Map.remove and related methods - * - * @param hash hash for key - * @param key the key - * @param value the value to match if matchValue, else ignored - * @param matchValue if true only remove if value is equal - * @param movable if false do not move other nodes while removing - * @return the node, or null if none - */ - final Node removeNode(int hash, Object key, Object value, - boolean matchValue, boolean movable) { - NodeTable tab; Node p; int n, index; - if ((tab = saTable) != null && (n = (int)tab.getLength()) > 0 && - (p = tab.get(index = (n - 1) & hash)).isSentinel != true) { - Node node = null, e; K k; V v; - if (p.hash == hash && - ((k = p.key) == key || (key != null && key.equals(k)))) - node = p; - else if ((e = p.next) != null) { -// if (p instanceof TreeNode) -// node = ((TreeNode)p).getTreeNode(hash, key); -// else { - do { - if (e.hash == hash && - ((k = e.key) == key || - (key != null && key.equals(k)))) { - node = e; - break; - } - p = e; - } while ((e = e.next) != null); -// } - } - if (node != null && (!matchValue || (v = node.value) == value || - (value != null && value.equals(v)))) { -// if (node instanceof TreeNode) -// ((TreeNode)node).removeTreeNode(this, tab, movable); -// else if (node == p) -// tab[index] = node.next; - if (node == p) { - // We are removign the head of the list. We need to create an - // independent node with the same contents that will be returned. - // Also needs to be passed to afterNodeRemoval(). - // Danger. Danger. (what if afterNodeRemoval was holding some links on a specific node) - // XXX GGG TODO - node = new Node(node.hash, node.key, node.value, node.next); - tab.get(index).setContents(node.next); - } - else - p.next = node.next; - ++modCount; - --size; - afterNodeRemoval(node); - return node; - } - } - return null; - } - - /** - * Removes all of the mappings from this map. - * The map will be empty after this call returns. - */ - public void clear() { - NodeTable tab; - modCount++; - if ((tab = saTable) != null && size > 0) { - size = 0; - for (int i = 0; i < tab.getLength(); ++i) -// tab[i] = null; - tab.get(i).setSentinel(true); - } - } - - /** - * Returns true if this map maps one or more keys to the - * specified value. - * - * @param value value whose presence in this map is to be tested - * @return true if this map maps one or more keys to the - * specified value - */ - public boolean containsValue(Object value) { - NodeTable tab; V v; - if ((tab = saTable) != null && size > 0) { - for (int i = 0; i < tab.getLength(); ++i) { - for (Node e = tab.get(i); (e != null) && (!e.isSentinel()); e = e.next) { - if ((v = e.value) == value || - (value != null && value.equals(v))) - return true; - } - } - } - return false; - } - - /** - * Returns a {@link Set} view of the keys contained in this map. - * The set is backed by the map, so changes to the map are - * reflected in the set, and vice-versa. If the map is modified - * while an iteration over the set is in progress (except through - * the iterator's own remove operation), the results of - * the iteration are undefined. The set supports element removal, - * which removes the corresponding mapping from the map, via the - * Iterator.remove, Set.remove, - * removeAll, retainAll, and clear - * operations. It does not support the add or addAll - * operations. - * - * @return a set view of the keys contained in this map - */ - public Set keySet() { - Set ks; - return (ks = keySet) == null ? (keySet = new KeySet()) : ks; - } - - final class KeySet extends AbstractSet { - public final int size() { return size; } - public final void clear() { SAHashMap.this.clear(); } - public final Iterator iterator() { return new KeyIterator(); } - public final boolean contains(Object o) { return containsKey(o); } - public final boolean remove(Object key) { - return removeNode(hash(key), key, null, false, true) != null; - } - public final Spliterator spliterator() { - return new KeySpliterator(SAHashMap.this, 0, -1, 0, 0); - } - public final void forEach(Consumer action) { - NodeTable tab; - if (action == null) - throw new NullPointerException(); - if (size > 0 && (tab = saTable) != null) { - int mc = modCount; - for (int i = 0; i < tab.getLength(); ++i) { - for (Node e = tab.get(i); ((e != null) && !e.isSentinel()) ; e = e.next) - action.accept(e.key); - } - if (modCount != mc) // lgtm [java/constant-comparison] - throw new ConcurrentModificationException(); - } - } - } - - /** - * Returns a {@link Collection} view of the values contained in this map. - * The collection is backed by the map, so changes to the map are - * reflected in the collection, and vice-versa. If the map is - * modified while an iteration over the collection is in progress - * (except through the iterator's own remove operation), - * the results of the iteration are undefined. The collection - * supports element removal, which removes the corresponding - * mapping from the map, via the Iterator.remove, - * Collection.remove, removeAll, - * retainAll and clear operations. It does not - * support the add or addAll operations. - * - * @return a view of the values contained in this map - */ - public Collection values() { - Collection vs; - return (vs = values) == null ? (values = new Values()) : vs; - } - - final class Values extends AbstractCollection { - public final int size() { return size; } - public final void clear() { SAHashMap.this.clear(); } - public final Iterator iterator() { return new ValueIterator(); } - public final boolean contains(Object o) { return containsValue(o); } - public final Spliterator spliterator() { - return new ValueSpliterator(SAHashMap.this, 0, -1, 0, 0); - } - public final void forEach(Consumer action) { - NodeTable tab; - if (action == null) - throw new NullPointerException(); - if (size > 0 && (tab = saTable) != null) { - int mc = modCount; - for (int i = 0; i < tab.getLength(); ++i) { - for (Node e = tab.get(i); ((e != null) && !e.isSentinel()); e = e.next) - action.accept(e.value); - } - if (modCount != mc) - throw new ConcurrentModificationException(); - } - } - } - - /** - * Returns a {@link Set} view of the mappings contained in this map. - * The set is backed by the map, so changes to the map are - * reflected in the set, and vice-versa. If the map is modified - * while an iteration over the set is in progress (except through - * the iterator's own remove operation, or through the - * setValue operation on a map entry returned by the - * iterator) the results of the iteration are undefined. The set - * supports element removal, which removes the corresponding - * mapping from the map, via the Iterator.remove, - * Set.remove, removeAll, retainAll and - * clear operations. It does not support the - * add or addAll operations. - * - * @return a set view of the mappings contained in this map - */ - public Set> entrySet() { - Set> es; - return (es = entrySet) == null ? (entrySet = new EntrySet()) : es; - } - - final class EntrySet extends AbstractSet> { - public final int size() { return size; } - public final void clear() { SAHashMap.this.clear(); } - public final Iterator> iterator() { - return new EntryIterator(); - } - public final boolean contains(Object o) { - if (!(o instanceof Map.Entry)) - return false; - Map.Entry e = (Map.Entry) o; - Object key = e.getKey(); - Node candidate = getNode(hash(key), key); - return candidate != null && candidate.equals(e); - } - public final boolean remove(Object o) { - if (o instanceof Map.Entry) { - Map.Entry e = (Map.Entry) o; - Object key = e.getKey(); - Object value = e.getValue(); - return removeNode(hash(key), key, value, true, true) != null; - } - return false; - } - public final Spliterator> spliterator() { - return new EntrySpliterator(SAHashMap.this, 0, -1, 0, 0); - } - public final void forEach(Consumer> action) { - NodeTable tab; - if (action == null) - throw new NullPointerException(); - if (size > 0 && (tab = saTable) != null) { - int mc = modCount; - for (int i = 0; i < tab.getLength(); ++i) { - for (Node e = tab.get(i); ((e != null) && !e.isSentinel()); e = e.next) - action.accept(e); - } - if (modCount != mc) // lgtm [java/constant-comparison] - throw new ConcurrentModificationException(); - } - } - } - - // Overrides of JDK8 Map extension methods - - @Override - public V getOrDefault(Object key, V defaultValue) { - Node e; - return (e = getNode(hash(key), key)) == null ? defaultValue : e.value; - } - - @Override - public V putIfAbsent(K key, V value) { - return putVal(hash(key), key, value, true, true); - } - - @Override - public boolean remove(Object key, Object value) { - return removeNode(hash(key), key, value, true, true) != null; - } - - @Override - public boolean replace(K key, V oldValue, V newValue) { - Node e; V v; - if ((e = getNode(hash(key), key)) != null && - ((v = e.value) == oldValue || (v != null && v.equals(oldValue)))) { - e.value = newValue; - afterNodeAccess(e); - return true; - } - return false; - } - - @Override - public V replace(K key, V value) { - Node e; - if ((e = getNode(hash(key), key)) != null) { - V oldValue = e.value; - e.value = value; - afterNodeAccess(e); - return oldValue; - } - return null; - } - - @Override - public V computeIfAbsent(K key, - Function mappingFunction) { - if (mappingFunction == null) - throw new NullPointerException(); - int hash = hash(key); - NodeTable tab; Node first; int n, i; - int binCount = 0; -// TreeNode t = null; - Node old = null; - if (size > threshold || (tab = saTable) == null || - (n = (int)tab.getLength()) == 0) - n = (int)(tab = resize()).getLength(); - if ((first = tab.get(i = (n - 1) & hash)).isSentinel() != true) { -// if (first instanceof TreeNode) -// old = (t = (TreeNode)first).getTreeNode(hash, key); -// else { - Node e = first; K k; - do { - if (e.hash == hash && - ((k = e.key) == key || (key != null && key.equals(k)))) { - old = e; - break; - } - ++binCount; - } while ((e = e.next) != null); -// } - V oldValue; - if (old != null && (oldValue = old.value) != null) { - afterNodeAccess(old); - return oldValue; - } - } - V v = mappingFunction.apply(key); - if (v == null) { - return null; - } else if (old != null) { - old.value = v; - afterNodeAccess(old); - return v; - } -// else if (t != null) -// t.putTreeVal(this, tab, hash, key, v); -// else { -// tab[i] = newNode(hash, key, v, first); -// if (binCount >= TREEIFY_THRESHOLD - 1) -// treeifyBin(tab, hash); -// } - tab.get(i).setContents(hash, key, v, first); - - ++modCount; - ++size; - afterNodeInsertion(true); - return v; - } - - public V computeIfPresent(K key, - BiFunction remappingFunction) { - if (remappingFunction == null) - throw new NullPointerException(); - Node e; V oldValue; - int hash = hash(key); - if ((e = getNode(hash, key)) != null && - (oldValue = e.value) != null) { - V v = remappingFunction.apply(key, oldValue); - if (v != null) { - e.value = v; - afterNodeAccess(e); - return v; - } - else - removeNode(hash, key, null, false, true); - } - return null; - } - - @Override - public V compute(K key, - BiFunction remappingFunction) { - if (remappingFunction == null) - throw new NullPointerException(); - int hash = hash(key); - NodeTable tab; Node first; int n, i; - int binCount = 0; -// TreeNode t = null; - Node old = null; - if (size > threshold || (tab = saTable) == null || - (n = (int)tab.getLength()) == 0) - n = (int)(tab = resize()).getLength(); - if ((first = tab.get(i = (n - 1) & hash)).isSentinel() != true) { -// if (first instanceof TreeNode) -// old = (t = (TreeNode)first).getTreeNode(hash, key); -// else { - Node e = first; K k; - do { - if (e.hash == hash && - ((k = e.key) == key || (key != null && key.equals(k)))) { - old = e; - break; - } - ++binCount; - } while ((e = e.next) != null); -// } - } - V oldValue = (old == null) ? null : old.value; - V v = remappingFunction.apply(key, oldValue); - if (old != null) { - if (v != null) { - old.value = v; - afterNodeAccess(old); - } - else - removeNode(hash, key, null, false, true); - } - else if (v != null) { -// if (t != null) -// t.putTreeVal(this, tab, hash, key, v); -// else { -// tab[i] = newNode(hash, key, v, first); -// if (binCount >= TREEIFY_THRESHOLD - 1) -// treeifyBin(tab, hash); -// } - tab.get(i).setContents(hash, key, v, first); - - ++modCount; - ++size; - afterNodeInsertion(true); - } - return v; - } - - @Override - public V merge(K key, V value, - BiFunction remappingFunction) { - if (value == null) - throw new NullPointerException(); - if (remappingFunction == null) - throw new NullPointerException(); - int hash = hash(key); - NodeTable tab; Node first; int n, i; - int binCount = 0; -// TreeNode t = null; - Node old = null; - if (size > threshold || (tab = saTable) == null || - (n = (int)tab.getLength()) == 0) - n = (int)(tab = resize()).getLength(); - if ((first = tab.get(i = (n - 1) & hash)).isSentinel() != true) { -// if (first instanceof TreeNode) -// old = (t = (TreeNode)first).getTreeNode(hash, key); -// else { - Node e = first; K k; - do { - if (e.hash == hash && - ((k = e.key) == key || (key != null && key.equals(k)))) { - old = e; - break; - } - ++binCount; - } while ((e = e.next) != null); -// } - } - if (old != null) { - V v; - if (old.value != null) - v = remappingFunction.apply(old.value, value); - else - v = value; - if (v != null) { - old.value = v; - afterNodeAccess(old); - } - else - removeNode(hash, key, null, false, true); - return v; - } -// if (value != null) { -// if (t != null) -// t.putTreeVal(this, tab, hash, key, value); -// else { -// tab[i] = newNode(hash, key, value, first); -// if (binCount >= TREEIFY_THRESHOLD - 1) -// treeifyBin(tab, hash); -// } - tab.get(i).setContents(hash, key, value, first); - - ++modCount; - ++size; - afterNodeInsertion(true); -// } - return value; - } - - @Override - public void forEach(BiConsumer action) { - NodeTable tab; - if (action == null) - throw new NullPointerException(); - if (size > 0 && (tab = saTable) != null) { - int mc = modCount; - for (int i = 0; i < tab.getLength(); ++i) { - for (Node e = tab.get(i); ((e != null) && !e.isSentinel()); e = e.next) - action.accept(e.key, e.value); - } - if (modCount != mc) // lgtm [java/constant-comparison] - throw new ConcurrentModificationException(); - } - } - - @Override - public void replaceAll(BiFunction function) { - NodeTable tab; - if (function == null) - throw new NullPointerException(); - if (size > 0 && (tab = saTable) != null) { - int mc = modCount; - for (int i = 0; i < tab.getLength(); ++i) { - for (Node e = tab.get(i); ((e != null) && !e.isSentinel()); e = e.next) { - e.value = function.apply(e.key, e.value); - } - } - if (modCount != mc) // lgtm [java/constant-comparison] - throw new ConcurrentModificationException(); - } - } - - /* ------------------------------------------------------------ */ - // Cloning and serialization - - /** - * Returns a shallow copy of this HashMap instance: the keys and - * values themselves are not cloned. - * - * @return a shallow copy of this map - */ - @SuppressWarnings("unchecked") - @Override - public Object clone() { - SAHashMap result; - try { - result = (SAHashMap)super.clone(); - } catch (CloneNotSupportedException e) { - // this shouldn't happen, since we are Cloneable - throw new InternalError(e); - } - result.reinitialize(); - result.putMapEntries(this, false); - return result; - } - - // These methods are also used when serializing HashSets - final float loadFactor() { return loadFactor; } - final int capacity() { - return (saTable != null) ? (int)saTable.getLength() : - (threshold > 0) ? threshold : - DEFAULT_INITIAL_CAPACITY; - } - - /** - * Save the state of the HashMap instance to a stream (i.e., - * serialize it). - * - * @serialData The capacity of the HashMap (the length of the - * bucket array) is emitted (int), followed by the - * size (an int, the number of key-value - * mappings), followed by the key (Object) and value (Object) - * for each key-value mapping. The key-value mappings are - * emitted in no particular order. - */ - private void writeObject(java.io.ObjectOutputStream s) - throws IOException { - int buckets = capacity(); - // Write out the threshold, loadfactor, and any hidden stuff - s.defaultWriteObject(); - s.writeInt(buckets); - s.writeInt(size); - internalWriteEntries(s); - } - - /** - * Reconstitute the {@code HashMap} instance from a stream (i.e., - * deserialize it). - */ - private void readObject(java.io.ObjectInputStream s) - throws IOException, ClassNotFoundException { - // Read in the threshold (ignored), loadfactor, and any hidden stuff - s.defaultReadObject(); - reinitialize(); - if (loadFactor <= 0 || Float.isNaN(loadFactor)) - throw new InvalidObjectException("Illegal load factor: " + - loadFactor); - s.readInt(); // Read and ignore number of buckets - int mappings = s.readInt(); // Read number of mappings (size) - if (mappings < 0) - throw new InvalidObjectException("Illegal mappings count: " + - mappings); - else if (mappings > 0) { // (if zero, use defaults) - // Size the table using given load factor only if within - // range of 0.25...4.0 - float lf = Math.min(Math.max(0.25f, loadFactor), 4.0f); - float fc = (float)mappings / lf + 1.0f; - int cap = ((fc < DEFAULT_INITIAL_CAPACITY) ? - DEFAULT_INITIAL_CAPACITY : - (fc >= MAXIMUM_CAPACITY) ? - MAXIMUM_CAPACITY : - tableSizeFor((int)fc)); - float ft = (float)cap * lf; - threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ? - (int)ft : Integer.MAX_VALUE); - @SuppressWarnings({"rawtypes","unchecked"}) -// Node[] tab = (Node[])new Node[cap]; - NodeTable tab = NodeTable.newInstance(cap); - saTable = tab; - - // Read the keys and values, and put the mappings in the HashMap - for (int i = 0; i < mappings; i++) { - @SuppressWarnings("unchecked") - K key = (K) s.readObject(); - @SuppressWarnings("unchecked") - V value = (V) s.readObject(); - putVal(hash(key), key, value, false, false); - } - } - } - - /* ------------------------------------------------------------ */ - // iterators - - abstract class HashIterator { - Node next; // next entry to return - Node current; // current entry - int expectedModCount; // for fast-fail - int index; // current slot - - HashIterator() { - expectedModCount = modCount; - NodeTable t = saTable; - current = next = null; - index = 0; - if (t != null && size > 0) { // advance to first entry - do {} while (index < t.getLength() && (next = t.get(index++)) == null); - } - } - - public final boolean hasNext() { - return next != null; - } - - final Node nextNode() { - NodeTable t; - Node e = next; - if (modCount != expectedModCount) - throw new ConcurrentModificationException(); - if (e == null) - throw new NoSuchElementException(); - if ((next = (current = e).next) == null && (t = saTable) != null) { - do {} while (index < t.getLength() && (next = t.get(index++)) == null); - } - return e; - } - - public final void remove() { - Node p = current; - if (p == null) - throw new IllegalStateException(); - if (modCount != expectedModCount) - throw new ConcurrentModificationException(); - current = null; - K key = p.key; - removeNode(hash(key), key, null, false, false); - expectedModCount = modCount; - } - } - - final class KeyIterator extends HashIterator - implements Iterator { - public final K next() { return nextNode().key; } - } - - final class ValueIterator extends HashIterator - implements Iterator { - public final V next() { return nextNode().value; } - } - - final class EntryIterator extends HashIterator - implements Iterator> { - public final Map.Entry next() { return nextNode(); } - } - - /* ------------------------------------------------------------ */ - // spliterators - - static class HashMapSpliterator { - final SAHashMap map; - Node current; // current node - int index; // current index, modified on advance/split - int fence; // one past last index - int est; // size estimate - int expectedModCount; // for comodification checks - - HashMapSpliterator(SAHashMap m, int origin, - int fence, int est, - int expectedModCount) { - this.map = m; - this.index = origin; - this.fence = fence; - this.est = est; - this.expectedModCount = expectedModCount; - } - - final int getFence() { // initialize fence and size on first use - int hi; - if ((hi = fence) < 0) { - SAHashMap m = map; - est = m.size; - expectedModCount = m.modCount; - NodeTable tab = m.saTable; - hi = fence = (tab == null) ? 0 : (int)tab.getLength(); - } - return hi; - } - - public final long estimateSize() { - getFence(); // force init - return (long) est; - } - } - - static final class KeySpliterator - extends HashMapSpliterator - implements Spliterator { - KeySpliterator(SAHashMap m, int origin, int fence, int est, - int expectedModCount) { - super(m, origin, fence, est, expectedModCount); - } - - public KeySpliterator trySplit() { - int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; - return (lo >= mid || ((current != null) && !current.isSentinel())) ? null : - new KeySpliterator(map, lo, index = mid, est >>>= 1, - expectedModCount); - } - - public void forEachRemaining(Consumer action) { - int i, hi, mc; - if (action == null) - throw new NullPointerException(); - SAHashMap m = map; - NodeTable tab = m.saTable; - if ((hi = fence) < 0) { - mc = expectedModCount = m.modCount; - hi = fence = (tab == null) ? 0 : (int)tab.getLength(); - } - else - mc = expectedModCount; - if (tab != null && tab.getLength() >= hi && - (i = index) >= 0 && (i < (index = hi) || ((current != null) && !current.isSentinel()))) { - Node p = current; - current = null; - do { - if (p == null) - p = tab.get(i++); - else { - action.accept(p.key); - p = p.next; - } - } while (((p != null) && !p.isSentinel) || i < hi); - if (m.modCount != mc) - throw new ConcurrentModificationException(); - } - } - - public boolean tryAdvance(Consumer action) { - int hi; - if (action == null) - throw new NullPointerException(); - NodeTable tab = map.saTable; - if (tab != null && tab.getLength() >= (hi = getFence()) && index >= 0) { - while (((current != null) && !current.isSentinel()) || index < hi) { - if (current == null) - current = tab.get(index++); - else { - K k = current.key; - current = current.next; - action.accept(k); - if (map.modCount != expectedModCount) - throw new ConcurrentModificationException(); - return true; - } - } - } - return false; - } - - public int characteristics() { - return (fence < 0 || est == map.size ? Spliterator.SIZED : 0) | - Spliterator.DISTINCT; - } - } - - static final class ValueSpliterator - extends HashMapSpliterator - implements Spliterator { - ValueSpliterator(SAHashMap m, int origin, int fence, int est, - int expectedModCount) { - super(m, origin, fence, est, expectedModCount); - } - - public ValueSpliterator trySplit() { - int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; - return (lo >= mid || ((current != null) && !current.isSentinel())) ? null : - new ValueSpliterator(map, lo, index = mid, est >>>= 1, - expectedModCount); - } - - public void forEachRemaining(Consumer action) { - int i, hi, mc; - if (action == null) - throw new NullPointerException(); - SAHashMap m = map; - NodeTable tab = m.saTable; - if ((hi = fence) < 0) { - mc = expectedModCount = m.modCount; - hi = fence = (tab == null) ? 0 : (int)tab.getLength(); - } - else - mc = expectedModCount; - if (tab != null && tab.getLength() >= hi && - (i = index) >= 0 && (i < (index = hi) || ((current != null) && !current.isSentinel()))) { - Node p = current; - current = null; - do { - if (p == null) - p = tab.get(i++); - else { - action.accept(p.value); - p = p.next; - } - } while (((p != null) && !p.isSentinel()) || i < hi); - if (m.modCount != mc) - throw new ConcurrentModificationException(); - } - } - - public boolean tryAdvance(Consumer action) { - int hi; - if (action == null) - throw new NullPointerException(); - NodeTable tab = map.saTable; - if (tab != null && tab.getLength() >= (hi = getFence()) && index >= 0) { - while (((current != null) && !current.isSentinel()) || index < hi) { - if (current == null) - current = tab.get(index++); - else { - V v = current.value; - current = current.next; - action.accept(v); - if (map.modCount != expectedModCount) - throw new ConcurrentModificationException(); - return true; - } - } - } - return false; - } - - public int characteristics() { - return (fence < 0 || est == map.size ? Spliterator.SIZED : 0); - } - } - - static final class EntrySpliterator - extends HashMapSpliterator - implements Spliterator> { - EntrySpliterator(SAHashMap m, int origin, int fence, int est, - int expectedModCount) { - super(m, origin, fence, est, expectedModCount); - } - - public EntrySpliterator trySplit() { - int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; - return (lo >= mid || ((current != null) && !current.isSentinel())) ? null : - new EntrySpliterator(map, lo, index = mid, est >>>= 1, - expectedModCount); - } - - public void forEachRemaining(Consumer> action) { - int i, hi, mc; - if (action == null) - throw new NullPointerException(); - SAHashMap m = map; - NodeTable tab = m.saTable; - if ((hi = fence) < 0) { - mc = expectedModCount = m.modCount; - hi = fence = (tab == null) ? 0 : (int)tab.getLength(); - } - else - mc = expectedModCount; - if (tab != null && tab.getLength() >= hi && - (i = index) >= 0 && (i < (index = hi) || ((current != null) && !current.isSentinel()))) { - Node p = current; - current = null; - do { - if (p == null) - p = tab.get(i++); - else { - action.accept(p); - p = p.next; - } - } while (((p != null) && !p.isSentinel()) || i < hi); - if (m.modCount != mc) - throw new ConcurrentModificationException(); - } - } - - public boolean tryAdvance(Consumer> action) { - int hi; - if (action == null) - throw new NullPointerException(); - NodeTable tab = map.saTable; - if (tab != null && tab.getLength() >= (hi = getFence()) && index >= 0) { - while (((current != null) && !current.isSentinel()) || index < hi) { - if (current == null) - current = tab.get(index++); - else { - Node e = current; - current = current.next; - action.accept(e); - if (map.modCount != expectedModCount) - throw new ConcurrentModificationException(); - return true; - } - } - } - return false; - } - - public int characteristics() { - return (fence < 0 || est == map.size ? Spliterator.SIZED : 0) | - Spliterator.DISTINCT; - } - } - - /* ------------------------------------------------------------ */ - // LinkedHashMap support - - - /* - * The following package-protected methods are designed to be - * overridden by LinkedHashMap, but not by any other subclass. - * Nearly all other internal methods are also package-protected - * but are declared final, so can be used by LinkedHashMap, view - * classes, and HashSet. - */ - - // Create a regular (non-tree) node - Node newNode(int hash, K key, V value, Node next) { - return new Node(hash, key, value, next); - } - - // For conversion from TreeNodes to plain nodes - Node replacementNode(Node p, Node next) { - return new Node(p.hash, p.key, p.value, next); - } - -// // Create a tree bin node -// TreeNode newTreeNode(int hash, K key, V value, Node next) { -// return new TreeNode(hash, key, value, next); -// } -// -// // For treeifyBin -// TreeNode replacementTreeNode(Node p, Node next) { -// return new TreeNode(p.hash, p.key, p.value, next); -// } - - /** - * Reset to initial default state. Called by clone and readObject. - */ - void reinitialize() { - saTable = null; - entrySet = null; - keySet = null; - values = null; - modCount = 0; - threshold = 0; - size = 0; - } - - // Callbacks to allow LinkedHashMap post-actions - void afterNodeAccess(Node p) { } - void afterNodeInsertion(boolean evict) { } - void afterNodeRemoval(Node p) { } - - // Called only from writeObject, to ensure compatible ordering. - void internalWriteEntries(java.io.ObjectOutputStream s) throws IOException { - NodeTable tab; - if (size > 0 && (tab = saTable) != null) { - for (int i = 0; i < tab.getLength(); ++i) { - for (Node e = tab.get(i); ((e != null) & !e.isSentinel()); e = e.next) { - s.writeObject(e.key); - s.writeObject(e.value); - } - } - } - } - -// /* ------------------------------------------------------------ */ -// // Tree bins -// -// /** -// * Entry for Tree bins. Extends LinkedHashMap.Entry (which in turn -// * extends Node) so can be used as extension of either regular or -// * linked node. -// */ -// static final class TreeNode extends SALinkedHashMap.Entry { -// TreeNode parent; // red-black tree links -// TreeNode left; -// TreeNode right; -// TreeNode prev; // needed to unlink next upon deletion -// boolean red; -// TreeNode(int hash, K key, V val, Node next) { -// super(hash, key, val, next); -// } -// -// /** -// * Returns root of tree containing this node. -// */ -// final TreeNode root() { -// for (TreeNode r = this, p;;) { -// if ((p = r.parent) == null) -// return r; -// r = p; -// } -// } -// -// /** -// * Ensures that the given root is the first node of its bin. -// */ -// static void moveRootToFront(Node[] tab, TreeNode root) { -// int n; -// if (root != null && tab != null && (n = tab.length) > 0) { -// int index = (n - 1) & root.hash; -// TreeNode first = (TreeNode)tab[index]; -// if (root != first) { -// Node rn; -// tab[index] = root; -// TreeNode rp = root.prev; -// if ((rn = root.next) != null) -// ((TreeNode)rn).prev = rp; -// if (rp != null) -// rp.next = rn; -// if (first != null) -// first.prev = root; -// root.next = first; -// root.prev = null; -// } -// assert checkInvariants(root); -// } -// } -// -// /** -// * Finds the node starting at root p with the given hash and key. -// * The kc argument caches comparableClassFor(key) upon first use -// * comparing keys. -// */ -// final TreeNode find(int h, Object k, Class kc) { -// TreeNode p = this; -// do { -// int ph, dir; K pk; -// TreeNode pl = p.left, pr = p.right, q; -// if ((ph = p.hash) > h) -// p = pl; -// else if (ph < h) -// p = pr; -// else if ((pk = p.key) == k || (k != null && k.equals(pk))) -// return p; -// else if (pl == null) -// p = pr; -// else if (pr == null) -// p = pl; -// else if ((kc != null || -// (kc = comparableClassFor(k)) != null) && -// (dir = compareComparables(kc, k, pk)) != 0) -// p = (dir < 0) ? pl : pr; -// else if ((q = pr.find(h, k, kc)) != null) -// return q; -// else -// p = pl; -// } while (p != null); -// return null; -// } -// -// /** -// * Calls find for root node. -// */ -// final TreeNode getTreeNode(int h, Object k) { -// return ((parent != null) ? root() : this).find(h, k, null); -// } -// -// /** -// * Tie-breaking utility for ordering insertions when equal -// * hashCodes and non-comparable. We don't require a total -// * order, just a consistent insertion rule to maintain -// * equivalence across rebalancings. Tie-breaking further than -// * necessary simplifies testing a bit. -// */ -// static int tieBreakOrder(Object a, Object b) { -// int d; -// if (a == null || b == null || -// (d = a.getClass().getName(). -// compareTo(b.getClass().getName())) == 0) -// d = (System.identityHashCode(a) <= System.identityHashCode(b) ? -// -1 : 1); -// return d; -// } -// -// /** -// * Forms tree of the nodes linked from this node. -// * @return root of tree -// */ -// final void treeify(Node[] tab) { -// TreeNode root = null; -// for (TreeNode x = this, next; x != null; x = next) { -// next = (TreeNode)x.next; -// x.left = x.right = null; -// if (root == null) { -// x.parent = null; -// x.red = false; -// root = x; -// } -// else { -// K k = x.key; -// int h = x.hash; -// Class kc = null; -// for (TreeNode p = root;;) { -// int dir, ph; -// K pk = p.key; -// if ((ph = p.hash) > h) -// dir = -1; -// else if (ph < h) -// dir = 1; -// else if ((kc == null && -// (kc = comparableClassFor(k)) == null) || -// (dir = compareComparables(kc, k, pk)) == 0) -// dir = tieBreakOrder(k, pk); -// -// TreeNode xp = p; -// if ((p = (dir <= 0) ? p.left : p.right) == null) { -// x.parent = xp; -// if (dir <= 0) -// xp.left = x; -// else -// xp.right = x; -// root = balanceInsertion(root, x); -// break; -// } -// } -// } -// } -// moveRootToFront(tab, root); -// } -// -// /** -// * Returns a list of non-TreeNodes replacing those linked from -// * this node. -// */ -// final Node untreeify(org.ObjectLayout.examples.util.SAHashMap map) { -// Node hd = null, tl = null; -// for (Node q = this; q != null; q = q.next) { -// Node p = map.replacementNode(q, null); -// if (tl == null) -// hd = p; -// else -// tl.next = p; -// tl = p; -// } -// return hd; -// } -// -// /** -// * Tree version of putVal. -// */ -// final TreeNode putTreeVal(org.ObjectLayout.examples.util.SAHashMap map, Node[] tab, -// int h, K k, V v) { -// Class kc = null; -// boolean searched = false; -// TreeNode root = (parent != null) ? root() : this; -// for (TreeNode p = root;;) { -// int dir, ph; K pk; -// if ((ph = p.hash) > h) -// dir = -1; -// else if (ph < h) -// dir = 1; -// else if ((pk = p.key) == k || (k != null && k.equals(pk))) -// return p; -// else if ((kc == null && -// (kc = comparableClassFor(k)) == null) || -// (dir = compareComparables(kc, k, pk)) == 0) { -// if (!searched) { -// TreeNode q, ch; -// searched = true; -// if (((ch = p.left) != null && -// (q = ch.find(h, k, kc)) != null) || -// ((ch = p.right) != null && -// (q = ch.find(h, k, kc)) != null)) -// return q; -// } -// dir = tieBreakOrder(k, pk); -// } -// -// TreeNode xp = p; -// if ((p = (dir <= 0) ? p.left : p.right) == null) { -// Node xpn = xp.next; -// TreeNode x = map.newTreeNode(h, k, v, xpn); -// if (dir <= 0) -// xp.left = x; -// else -// xp.right = x; -// xp.next = x; -// x.parent = x.prev = xp; -// if (xpn != null) -// ((TreeNode)xpn).prev = x; -// moveRootToFront(tab, balanceInsertion(root, x)); -// return null; -// } -// } -// } -// -// /** -// * Removes the given node, that must be present before this call. -// * This is messier than typical red-black deletion code because we -// * cannot swap the contents of an interior node with a leaf -// * successor that is pinned by "next" pointers that are accessible -// * independently during traversal. So instead we swap the tree -// * linkages. If the current tree appears to have too few nodes, -// * the bin is converted back to a plain bin. (The test triggers -// * somewhere between 2 and 6 nodes, depending on tree structure). -// */ -// final void removeTreeNode(org.ObjectLayout.examples.util.SAHashMap map, Node[] tab, -// boolean movable) { -// int n; -// if (tab == null || (n = tab.length) == 0) -// return; -// int index = (n - 1) & hash; -// TreeNode first = (TreeNode)tab[index], root = first, rl; -// TreeNode succ = (TreeNode)next, pred = prev; -// if (pred == null) -// tab[index] = first = succ; -// else -// pred.next = succ; -// if (succ != null) -// succ.prev = pred; -// if (first == null) -// return; -// if (root.parent != null) -// root = root.root(); -// if (root == null || root.right == null || -// (rl = root.left) == null || rl.left == null) { -// tab[index] = first.untreeify(map); // too small -// return; -// } -// TreeNode p = this, pl = left, pr = right, replacement; -// if (pl != null && pr != null) { -// TreeNode s = pr, sl; -// while ((sl = s.left) != null) // find successor -// s = sl; -// boolean c = s.red; s.red = p.red; p.red = c; // swap colors -// TreeNode sr = s.right; -// TreeNode pp = p.parent; -// if (s == pr) { // p was s's direct parent -// p.parent = s; -// s.right = p; -// } -// else { -// TreeNode sp = s.parent; -// if ((p.parent = sp) != null) { -// if (s == sp.left) -// sp.left = p; -// else -// sp.right = p; -// } -// if ((s.right = pr) != null) -// pr.parent = s; -// } -// p.left = null; -// if ((p.right = sr) != null) -// sr.parent = p; -// if ((s.left = pl) != null) -// pl.parent = s; -// if ((s.parent = pp) == null) -// root = s; -// else if (p == pp.left) -// pp.left = s; -// else -// pp.right = s; -// if (sr != null) -// replacement = sr; -// else -// replacement = p; -// } -// else if (pl != null) -// replacement = pl; -// else if (pr != null) -// replacement = pr; -// else -// replacement = p; -// if (replacement != p) { -// TreeNode pp = replacement.parent = p.parent; -// if (pp == null) -// root = replacement; -// else if (p == pp.left) -// pp.left = replacement; -// else -// pp.right = replacement; -// p.left = p.right = p.parent = null; -// } -// -// TreeNode r = p.red ? root : balanceDeletion(root, replacement); -// -// if (replacement == p) { // detach -// TreeNode pp = p.parent; -// p.parent = null; -// if (pp != null) { -// if (p == pp.left) -// pp.left = null; -// else if (p == pp.right) -// pp.right = null; -// } -// } -// if (movable) -// moveRootToFront(tab, r); -// } -// -// /** -// * Splits nodes in a tree bin into lower and upper tree bins, -// * or untreeifies if now too small. Called only from resize; -// * see above discussion about split bits and indices. -// * -// * @param map the map -// * @param tab the table for recording bin heads -// * @param index the index of the table being split -// * @param bit the bit of hash to split on -// */ -// final void split(org.ObjectLayout.examples.util.SAHashMap map, Node[] tab, int index, int bit) { -// TreeNode b = this; -// // Relink into lo and hi lists, preserving order -// TreeNode loHead = null, loTail = null; -// TreeNode hiHead = null, hiTail = null; -// int lc = 0, hc = 0; -// for (TreeNode e = b, next; e != null; e = next) { -// next = (TreeNode)e.next; -// e.next = null; -// if ((e.hash & bit) == 0) { -// if ((e.prev = loTail) == null) -// loHead = e; -// else -// loTail.next = e; -// loTail = e; -// ++lc; -// } -// else { -// if ((e.prev = hiTail) == null) -// hiHead = e; -// else -// hiTail.next = e; -// hiTail = e; -// ++hc; -// } -// } -// -// if (loHead != null) { -// if (lc <= UNTREEIFY_THRESHOLD) -// tab[index] = loHead.untreeify(map); -// else { -// tab[index] = loHead; -// if (hiHead != null) // (else is already treeified) -// loHead.treeify(tab); -// } -// } -// if (hiHead != null) { -// if (hc <= UNTREEIFY_THRESHOLD) -// tab[index + bit] = hiHead.untreeify(map); -// else { -// tab[index + bit] = hiHead; -// if (loHead != null) -// hiHead.treeify(tab); -// } -// } -// } -// -// /* ------------------------------------------------------------ */ -// // Red-black tree methods, all adapted from CLR -// -// static TreeNode rotateLeft(TreeNode root, -// TreeNode p) { -// TreeNode r, pp, rl; -// if (p != null && (r = p.right) != null) { -// if ((rl = p.right = r.left) != null) -// rl.parent = p; -// if ((pp = r.parent = p.parent) == null) -// (root = r).red = false; -// else if (pp.left == p) -// pp.left = r; -// else -// pp.right = r; -// r.left = p; -// p.parent = r; -// } -// return root; -// } -// -// static TreeNode rotateRight(TreeNode root, -// TreeNode p) { -// TreeNode l, pp, lr; -// if (p != null && (l = p.left) != null) { -// if ((lr = p.left = l.right) != null) -// lr.parent = p; -// if ((pp = l.parent = p.parent) == null) -// (root = l).red = false; -// else if (pp.right == p) -// pp.right = l; -// else -// pp.left = l; -// l.right = p; -// p.parent = l; -// } -// return root; -// } -// -// static TreeNode balanceInsertion(TreeNode root, -// TreeNode x) { -// x.red = true; -// for (TreeNode xp, xpp, xppl, xppr;;) { -// if ((xp = x.parent) == null) { -// x.red = false; -// return x; -// } -// else if (!xp.red || (xpp = xp.parent) == null) -// return root; -// if (xp == (xppl = xpp.left)) { -// if ((xppr = xpp.right) != null && xppr.red) { -// xppr.red = false; -// xp.red = false; -// xpp.red = true; -// x = xpp; -// } -// else { -// if (x == xp.right) { -// root = rotateLeft(root, x = xp); -// xpp = (xp = x.parent) == null ? null : xp.parent; -// } -// if (xp != null) { -// xp.red = false; -// if (xpp != null) { -// xpp.red = true; -// root = rotateRight(root, xpp); -// } -// } -// } -// } -// else { -// if (xppl != null && xppl.red) { -// xppl.red = false; -// xp.red = false; -// xpp.red = true; -// x = xpp; -// } -// else { -// if (x == xp.left) { -// root = rotateRight(root, x = xp); -// xpp = (xp = x.parent) == null ? null : xp.parent; -// } -// if (xp != null) { -// xp.red = false; -// if (xpp != null) { -// xpp.red = true; -// root = rotateLeft(root, xpp); -// } -// } -// } -// } -// } -// } -// -// static TreeNode balanceDeletion(TreeNode root, -// TreeNode x) { -// for (TreeNode xp, xpl, xpr;;) { -// if (x == null || x == root) -// return root; -// else if ((xp = x.parent) == null) { -// x.red = false; -// return x; -// } -// else if (x.red) { -// x.red = false; -// return root; -// } -// else if ((xpl = xp.left) == x) { -// if ((xpr = xp.right) != null && xpr.red) { -// xpr.red = false; -// xp.red = true; -// root = rotateLeft(root, xp); -// xpr = (xp = x.parent) == null ? null : xp.right; -// } -// if (xpr == null) -// x = xp; -// else { -// TreeNode sl = xpr.left, sr = xpr.right; -// if ((sr == null || !sr.red) && -// (sl == null || !sl.red)) { -// xpr.red = true; -// x = xp; -// } -// else { -// if (sr == null || !sr.red) { -// if (sl != null) -// sl.red = false; -// xpr.red = true; -// root = rotateRight(root, xpr); -// xpr = (xp = x.parent) == null ? -// null : xp.right; -// } -// if (xpr != null) { -// xpr.red = (xp == null) ? false : xp.red; -// if ((sr = xpr.right) != null) -// sr.red = false; -// } -// if (xp != null) { -// xp.red = false; -// root = rotateLeft(root, xp); -// } -// x = root; -// } -// } -// } -// else { // symmetric -// if (xpl != null && xpl.red) { -// xpl.red = false; -// xp.red = true; -// root = rotateRight(root, xp); -// xpl = (xp = x.parent) == null ? null : xp.left; -// } -// if (xpl == null) -// x = xp; -// else { -// TreeNode sl = xpl.left, sr = xpl.right; -// if ((sl == null || !sl.red) && -// (sr == null || !sr.red)) { -// xpl.red = true; -// x = xp; -// } -// else { -// if (sl == null || !sl.red) { -// if (sr != null) -// sr.red = false; -// xpl.red = true; -// root = rotateLeft(root, xpl); -// xpl = (xp = x.parent) == null ? -// null : xp.left; -// } -// if (xpl != null) { -// xpl.red = (xp == null) ? false : xp.red; -// if ((sl = xpl.left) != null) -// sl.red = false; -// } -// if (xp != null) { -// xp.red = false; -// root = rotateRight(root, xp); -// } -// x = root; -// } -// } -// } -// } -// } -// -// /** -// * Recursive invariant check -// */ -// static boolean checkInvariants(TreeNode t) { -// TreeNode tp = t.parent, tl = t.left, tr = t.right, -// tb = t.prev, tn = (TreeNode)t.next; -// if (tb != null && tb.next != t) -// return false; -// if (tn != null && tn.prev != t) -// return false; -// if (tp != null && t != tp.left && t != tp.right) -// return false; -// if (tl != null && (tl.parent != t || tl.hash > t.hash)) -// return false; -// if (tr != null && (tr.parent != t || tr.hash < t.hash)) -// return false; -// if (t.red && tl != null && tl.red && tr != null && tr.red) -// return false; -// if (tl != null && !checkInvariants(tl)) -// return false; -// if (tr != null && !checkInvariants(tr)) -// return false; -// return true; -// } -// } - -} \ No newline at end of file diff --git a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/BPlusTreeTest.java b/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/BPlusTreeTest.java deleted file mode 100644 index 0a07b13..0000000 --- a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/BPlusTreeTest.java +++ /dev/null @@ -1,196 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, Martin Thompson and Michael Barker, and released - * to the public domain, as explained at: - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import static java.util.Arrays.sort; - -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Random; -import java.util.TreeMap; - -import org.ObjectLayout.examples.BPlusTree; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Test; - -public class BPlusTreeTest { - private final BPlusTree tree = new BPlusTree( - 8); - - @Test - public void test() { - int[] values = new int[] { 10, 20, 30, 40, 50, 60, 70, 80 }; - - for (int value : values) { - tree.put(value, value); - } - - tree.put(21, 21); - - Assert.assertThat(tree.get(49), CoreMatchers.is(CoreMatchers.nullValue())); - Assert.assertThat(tree.get(50), CoreMatchers.is((Object) 50)); - Assert.assertThat(tree.get(51), CoreMatchers.is(CoreMatchers.nullValue())); - Assert.assertThat(tree.get(21), CoreMatchers.is((Object) 21)); - } - - @Test - public void insertsAndGetsAndRemovesRandomValues() throws Exception { - int[] values = nextInts(new Random(5), Integer.MAX_VALUE, - new int[10000]); - - putAll(tree, values); - assertGet(tree, values); - - TreeMap treeMap = new TreeMap(); - putAll(treeMap, values); - - Assert.assertThat(tree.size(), CoreMatchers.is(treeMap.size())); - Assert.assertThat(count(tree), CoreMatchers.is(treeMap.size())); - - int count = 0; - for (int value : values) { - Assert.assertThat("{" + count + "}", tree.get(value), - CoreMatchers.is(treeMap.get(value))); - Integer removed = tree.remove(value); - Integer mapRemoved = treeMap.remove(value); - - Assert.assertThat("{" + count + "}", removed, CoreMatchers.is(mapRemoved)); - Assert.assertThat("{" + count + "}", tree.size(), CoreMatchers.is(treeMap.size())); - Assert.assertThat("{" + count + "}", count(tree), CoreMatchers.is(treeMap.size())); - Assert.assertThat("{" + count + "}", tree.get(value), CoreMatchers.is(CoreMatchers.nullValue())); - - count++; - } - } - - private int count(BPlusTree tree) { - Iterator> iterator = tree.iterator(); - int i = 0; - while (iterator.hasNext()) { - iterator.next(); - i++; - } - return i; - } - - @Test - public void putsAndDeletesWithoutBranching() { - int[] values = new int[] { 10, 20, 30, 40, 50, 60, 70, 80 }; - putAll(tree, values); - - int size = tree.size(); - - for (int value : values) { - int removed = tree.remove(value); - Assert.assertThat(removed, CoreMatchers.is(value)); - Assert.assertThat(tree.size(), CoreMatchers.is(--size)); - } - } - - @Test - public void putsAndDeletesFromLeftWithBranching() { - int[] values = new int[] { 10, 20, 30, 40, 50, 60, 70, 80, 90 }; - putAll(tree, values); - - int size = tree.size(); - - for (int value : values) { - int removed = tree.remove(value); - Assert.assertThat(removed, CoreMatchers.is(value)); - Assert.assertThat(tree.size(), CoreMatchers.is(--size)); - } - } - - @Test - public void putsAndDeletesFromRightWithBranching() { - int[] values = new int[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 45 }; - putAll(tree, values); - - int size = tree.size(); - sort(values); - - for (int value : reverse(values)) { - int removed = tree.remove(value); - Assert.assertThat(removed, CoreMatchers.is(value)); - Assert.assertThat(tree.size(), CoreMatchers.is(--size)); - } - } - - private int[] reverse(int[] values) { - - int[] reversed = new int[values.length]; - int index = reversed.length; - for (int value : values) { - reversed[--index] = value; - } - - return reversed; - } - - @Test - public void splitsLeavesTwiceToRight() throws Exception { - int[] values = new int[] { 10, 20, 30, 40, 50, 60, 70, 80, 51, 52, 53, - 54, 55 }; - assertPutAndGet(values); - } - - @Test - public void splitsLeavesTwiceToLeft() throws Exception { - int[] values = new int[] { 10, 20, 30, 40, 50, 60, 70, 80, 1, 2, 3, 4, - 5 }; - assertPutAndGet(values); - } - - @Test - public void splitsLeavesTwiceBothWays() throws Exception { - int[] values = new int[] { 10, 20, 30, 40, 50, 60, 70, 80, 41, 42, 43, - 44, 45 }; - assertPutAndGet(values); - } - - private void assertPutAndGet(int[] values) { - for (int value : values) { - tree.put(value, value); - } - - for (int value : values) { - Assert.assertThat(tree.get(value), CoreMatchers.is((Object) value)); - } - } - - private static void putAll(BPlusTree node, int... values) { - int counter = 0; - for (int value : values) { - try { - node.put(value, value); - counter++; - } catch (Exception e) { - throw new RuntimeException("" + counter, e); - } - } - } - - private static void assertGet(BPlusTree tree, int[] values) { - for (int value : values) { - Assert.assertThat(tree.get(value), CoreMatchers.is((Object) value)); - } - } - - private static void putAll(TreeMap treeMap, int[] values) { - for (int value : values) { - treeMap.put(value, value); - } - } - - private int[] nextInts(Random r, int maxValue, int[] values) { - for (int i = 0; i < values.length; i++) { - values[i] = r.nextInt(maxValue); - } - - return values; - } - -} diff --git a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/LICENSE.txt b/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/LICENSE.txt deleted file mode 100644 index 06f48d0..0000000 --- a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/LICENSE.txt +++ /dev/null @@ -1,41 +0,0 @@ -The code in this directory was Written by Gil Tene -Martin Thompson, and Michael Barker and released to the public domain, -as explained at http://creativecommons.org/publicdomain/zero/1.0/ - -For users of this code who wish to consume it under the "BSD" license -rather than under the public domain or CC0 contribution text mentioned -above, the code found under this directory is *also* provided under the -following license (commonly referred to as the BSD 2-Clause License). This -license does not detract from the above stated release of the code into -the public domain, and simply represents an additional license granted by -the Author. - ------------------------------------------------------------------------------ -** Beginning of "BSD 2-Clause License" text. ** - - Copyright (c) 2012, 2013, 2014, 2015 Gil Tene - Copyright (c) 2014, 2014, 2015 Michael Barker - Copyright (c) 2012, 2013, 2014 Martin Thompson - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/LineTest.java b/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/LineTest.java deleted file mode 100644 index 8184d66..0000000 --- a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/LineTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.ObjectLayout.examples.Line; -import org.ObjectLayout.examples.Point; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Test; - -import static java.lang.Long.valueOf; - -public class LineTest { - - @Test - public void shouldConstructLine() throws NoSuchMethodException { - Line line = new Line(); - Point endPoint1 = line.getEndPoint1(); - Point endPoint2 = line.getEndPoint2(); - - Assert.assertThat(valueOf(endPoint1.getX()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(endPoint1.getY()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(endPoint2.getX()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(endPoint2.getY()), CoreMatchers.is(0L)); - - Line line2 = new Line(1, 2, 3, 4); - endPoint1 = line2.getEndPoint1(); - endPoint2 = line2.getEndPoint2(); - - Assert.assertThat(valueOf(endPoint1.getX()), CoreMatchers.is(1L)); - Assert.assertThat(valueOf(endPoint1.getY()), CoreMatchers.is(2L)); - Assert.assertThat(valueOf(endPoint2.getX()), CoreMatchers.is(3L)); - Assert.assertThat(valueOf(endPoint2.getY()), CoreMatchers.is(4L)); - - Line line3 = new Line(line2); - endPoint1 = line3.getEndPoint1(); - endPoint2 = line3.getEndPoint2(); - - Assert.assertThat(valueOf(endPoint1.getX()), CoreMatchers.is(1L)); - Assert.assertThat(valueOf(endPoint1.getY()), CoreMatchers.is(2L)); - Assert.assertThat(valueOf(endPoint2.getX()), CoreMatchers.is(3L)); - Assert.assertThat(valueOf(endPoint2.getY()), CoreMatchers.is(4L)); - } -} diff --git a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/OctagonTest.java b/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/OctagonTest.java deleted file mode 100644 index ec0c1c0..0000000 --- a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/OctagonTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.ObjectLayout.examples.Octagon; -import org.ObjectLayout.examples.Point; -import org.ObjectLayout.examples.PointArray; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Test; - -import static java.lang.Long.valueOf; - -public class OctagonTest { - - @Test - public void shouldConstructOctagon() throws NoSuchMethodException { - Octagon octagon = new Octagon(); - PointArray points = octagon.getPoints(); - - Assert.assertThat(valueOf(points.get(0).getX()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(points.get(0).getY()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(points.get(7).getX()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(points.get(7).getY()), CoreMatchers.is(0L)); - - int i = 0; - for (Point p : points) { - p.setX(++i); - p.setY(++i); - } - - Assert.assertThat(valueOf(points.get(0).getX()), CoreMatchers.is(1L)); - Assert.assertThat(valueOf(points.get(0).getY()), CoreMatchers.is(2L)); - Assert.assertThat(valueOf(points.get(1).getX()), CoreMatchers.is(3L)); - Assert.assertThat(valueOf(points.get(1).getY()), CoreMatchers.is(4L)); - Assert.assertThat(valueOf(points.get(7).getX()), CoreMatchers.is(15L)); - Assert.assertThat(valueOf(points.get(7).getY()), CoreMatchers.is(16L)); - - Octagon octagon2 = new Octagon(octagon); - points = octagon2.getPoints(); - - Assert.assertThat(valueOf(points.get(0).getX()), CoreMatchers.is(1L)); - Assert.assertThat(valueOf(points.get(0).getY()), CoreMatchers.is(2L)); - Assert.assertThat(valueOf(points.get(1).getX()), CoreMatchers.is(3L)); - Assert.assertThat(valueOf(points.get(1).getY()), CoreMatchers.is(4L)); - Assert.assertThat(valueOf(points.get(7).getX()), CoreMatchers.is(15L)); - Assert.assertThat(valueOf(points.get(7).getY()), CoreMatchers.is(16L)); - } -} diff --git a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/OctagonsTest.java b/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/OctagonsTest.java deleted file mode 100644 index cf3aa60..0000000 --- a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/OctagonsTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Test; - -import static java.lang.Long.valueOf; - -public class OctagonsTest { - - @Test - public void shouldConstructOctagon() throws NoSuchMethodException { - Octagons octagons = Octagons.newInstance( - 100, - "Orange", - 0, 0 /*initial center */, - 20 /* radius */, - 100, 100 /* delta in center between members */ - ); - - PointArray points = octagons.get(0).getPoints(); - - Assert.assertThat(valueOf(points.get(0).getX()), CoreMatchers.is(20L)); - Assert.assertThat(valueOf(points.get(0).getY()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(points.get(7).getX()), CoreMatchers.is(14L)); - Assert.assertThat(valueOf(points.get(7).getY()), CoreMatchers.is(-14L)); - - points = octagons.get(10).getPoints(); - - Assert.assertThat(valueOf(points.get(0).getX()), CoreMatchers.is(1000 + 20L)); - Assert.assertThat(valueOf(points.get(0).getY()), CoreMatchers.is(1000 + 0L)); - Assert.assertThat(valueOf(points.get(7).getX()), CoreMatchers.is(1000 + 14L)); - Assert.assertThat(valueOf(points.get(7).getY()), CoreMatchers.is(1000 + -14L)); - - Octagons octagons2 = Octagons.copyInstance(octagons); - points = octagons2.get(0).getPoints(); - - Assert.assertThat(valueOf(points.get(0).getX()), CoreMatchers.is(20L)); - Assert.assertThat(valueOf(points.get(0).getY()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(points.get(7).getX()), CoreMatchers.is(14L)); - Assert.assertThat(valueOf(points.get(7).getY()), CoreMatchers.is(-14L)); - - points = octagons.get(10).getPoints(); - - Assert.assertThat(valueOf(points.get(0).getX()), CoreMatchers.is(1000 + 20L)); - Assert.assertThat(valueOf(points.get(0).getY()), CoreMatchers.is(1000 + 0L)); - Assert.assertThat(valueOf(points.get(7).getX()), CoreMatchers.is(1000 + 14L)); - Assert.assertThat(valueOf(points.get(7).getY()), CoreMatchers.is(1000 + -14L)); - } -} diff --git a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/PointArrayTest.java b/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/PointArrayTest.java deleted file mode 100644 index b96f2f5..0000000 --- a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/PointArrayTest.java +++ /dev/null @@ -1,527 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.ObjectLayout.*; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Test; - -import static java.lang.Long.valueOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -public class PointArrayTest { - - @Test - public void shouldConstructArrayOfGivenDirectLengths() throws NoSuchMethodException { - final long[] lengths = {7L, 8L, 9L}; - - @SuppressWarnings("unchecked") - final StructuredArray> array = - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - PointArray.class, - Point.class, - lengths[2] - ), - lengths[1] - ), - lengths[0] - ).build(); - - Assert.assertThat(valueOf(array.getLength()), CoreMatchers.is(lengths[0])); - Assert.assertThat(valueOf(array.get(0).getLength()), CoreMatchers.is(lengths[1])); - Assert.assertThat(valueOf(array.get(0).get(0).getLength()), CoreMatchers.is(lengths[2])); - - Assert.assertTrue(array.getElementClass().isAssignableFrom(StructuredArray.class)); - Assert.assertTrue(array.get(0).getElementClass().isAssignableFrom(PointArray.class)); - Assert.assertTrue(array.get(0).get(0).getElementClass() == Point.class); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithNewInstance() throws NoSuchMethodException { - long length = 9L; - PointArray array = PointArray.newInstance(length); - - Assert.assertThat(valueOf(array.getLength()), CoreMatchers.is(valueOf(length))); - Assert.assertTrue(array.getElementClass() == Point.class); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilder() throws NoSuchMethodException { - long length = 9L; - PointArray array = - new StructuredArrayBuilder( - PointArray.class, - Point.class, - length - ).build(); - - Assert.assertThat(valueOf(array.getLength()), CoreMatchers.is(valueOf(length))); - Assert.assertTrue(array.getElementClass() == Point.class); - } - - @Test - public void shouldConstructArrayOfGivenLengthAndInitValues() throws NoSuchMethodException { - final long initialX = 4; - final long initialY = 777; - - long length = 9L; - - final PointArray array = - PointArray.newInstance(length, initialX, initialY); - - assertCorrectFixedInitialisation(initialX, initialY, new long[] {length}, array); - } - - @Test - public void shouldConstructArrayElementsViaConstantCtorAndArgsProvider() throws NoSuchMethodException { - final Class[] initArgTypes = {long.class, long.class}; - final long initialX = 4; - final long initialY = 777; - - long length = 9L; - - final CtorAndArgs ctorAndArgs = - new CtorAndArgs(Point.class, initArgTypes, initialX, initialY); - final CtorAndArgsProvider ctorAndArgsProvider = - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return ctorAndArgs; - } - }; - - final PointArray array = - PointArray.newInstance( - PointArray.class, Point.class, length, ctorAndArgsProvider); - - assertCorrectFixedInitialisation(initialX, initialY, new long[] {length}, array); - } - - @Test - public void shouldConstructArrayElementsViaCtorAndArgsProvider() throws NoSuchMethodException { - final long[] lengths = {9}; - final PointCtorAndArgsProvider ctorAndArgsProvider = new PointCtorAndArgsProvider(); - final PointArray array = - PointArray.newInstance(lengths[0], ctorAndArgsProvider); - - assertCorrectVariableInitialisation(lengths, array); - } - - @SuppressWarnings("unchecked") - @Test - public void shouldConstructArrayElementsViaCtorAndArgsProvider3D() throws NoSuchMethodException { - final long[] lengths = {7, 8, 9}; - final PointCtorAndArgsProvider ctorAndArgsProvider = new PointCtorAndArgsProvider(); - - final StructuredArrayBuilder>, - StructuredArray> builder = get3dBuilder(lengths); - builder.getStructuredSubArrayBuilder(). - getStructuredSubArrayBuilder(). - elementCtorAndArgsProvider(ctorAndArgsProvider); - - final StructuredArray> array = builder.build(); - - assertCorrectVariableInitialisation(lengths, array); - } - - @Test - public void shouldSetAndGetCorrectValueAtGivenIndex() throws NoSuchMethodException { - final long[] lengths = {11, 10, 3}; - final StructuredArray> array = get3dBuilder(lengths).build(); - - initValues(lengths, array); - assertCorrectVariableInitialisation(lengths, array); - } - - @Test - public void shouldIterateOverArray() throws NoSuchMethodException { - final long[] lengths = {11}; - final PointArray array = - PointArray.newInstance(lengths[0]); - - initValues(lengths, array); - - PointArray.ElementIterator iter = array.iterator(); - - long sum = 0; - long elementCount = 0; - while (iter.hasNext()) { - final long index = iter.getCursor(); - final Point point = iter.next(); - - Assert.assertThat(valueOf(point.getX()), CoreMatchers.is(valueOf(index))); - Assert.assertThat(valueOf(point.getY()), CoreMatchers.is(valueOf(index * 2))); - sum += index; - elementCount++; - } - - long sum2 = 0; - long elementCount2 = 0; - for (final Point point : array) { - sum2 += point.getX(); - elementCount2++; - } - - Assert.assertThat(valueOf(elementCount), CoreMatchers.is(valueOf(array.getLength()))); - Assert.assertThat(valueOf(sum), CoreMatchers.is(valueOf(sum2))); - Assert.assertThat(valueOf(elementCount), CoreMatchers.is(valueOf(elementCount2))); - } - - @Test - public void shouldIterateOverArrayAndResetAgain() throws NoSuchMethodException { - final long length = 11; - final PointArray array = - PointArray.newInstance(length); - - initValues(new long[] {length}, array); - - int i = 0; - final PointArray.ElementIterator iter = array.iterator(); - while (iter.hasNext()) { - final long index = iter.getCursor(); - final Point point = iter.next(); - Assert.assertThat(valueOf(point.getX()), CoreMatchers.is(valueOf(index))); - Assert.assertThat(valueOf(point.getY()), CoreMatchers.is(valueOf(index * 2))); - i++; - } - - iter.reset(); - i = 0; - while (iter.hasNext()) { - final long index = iter.getCursor(); - final Point point = iter.next(); - Assert.assertThat(valueOf(point.getX()), CoreMatchers.is(valueOf(index))); - Assert.assertThat(valueOf(point.getY()), CoreMatchers.is(valueOf(index * 2))); - i++; - } - - Assert.assertThat(valueOf(i), CoreMatchers.is(valueOf(length))); - } - - @Test - public void shouldConstructCopyOfArray() throws NoSuchMethodException { - final long length = 15; - final PointCtorAndArgsProvider ctorAndArgsProvider = new PointCtorAndArgsProvider(); - final PointArray sourceArray = - PointArray.newInstance(length, ctorAndArgsProvider); - - Assert.assertThat(valueOf(sourceArray.getLength()), CoreMatchers.is(valueOf(length))); - Assert.assertTrue(sourceArray.getElementClass() == Point.class); - - final PointArray newArray = - (PointArray) StructuredArray.copyInstance(sourceArray); - - // We expect MockStructure elements to be initialized with index = index, and testValue = index * 2: - assertCorrectVariableInitialisation(new long[] {length}, newArray); - } - - @SuppressWarnings("unchecked") - @Test - public void shouldConstructCopyOfArray3D() throws NoSuchMethodException { - final long[] lengths = {15, 7, 5}; - final PointCtorAndArgsProvider ctorAndArgsProvider = new PointCtorAndArgsProvider(); - - final StructuredArrayBuilder>, - StructuredArray> builder = get3dBuilder(lengths); - builder.getStructuredSubArrayBuilder(). - getStructuredSubArrayBuilder(). - elementCtorAndArgsProvider(ctorAndArgsProvider); - - final StructuredArray> sourceArray = builder.build(); - - StructuredArray subArray1 = sourceArray.get(0); - PointArray subArray2 = subArray1.get(0); - - Assert.assertThat(valueOf(sourceArray.getLength()), CoreMatchers.is(valueOf(lengths[0]))); - Assert.assertThat(valueOf(subArray1.getLength()), CoreMatchers.is(valueOf(lengths[1]))); - Assert.assertThat(valueOf(subArray2.getLength()), CoreMatchers.is(valueOf(lengths[2]))); - Assert.assertTrue(subArray2.getElementClass() == Point.class); - - final StructuredArray> newArray = - StructuredArray.copyInstance(sourceArray); - - // We expect MockStructure elements to be initialized with index = index, and testValue = index * 2: - assertCorrectVariableInitialisation(lengths, newArray); - } - - @SuppressWarnings("unchecked") - @Test - public void shouldConstructCopyOfArrayRange() throws NoSuchMethodException { - final long[] lengths = {15, 7, 5}; - final PointCtorAndArgsProvider ctorAndArgsProvider = new PointCtorAndArgsProvider(); - - final StructuredArrayBuilder>, - StructuredArray> builder = get3dBuilder(lengths); - builder.getStructuredSubArrayBuilder(). - getStructuredSubArrayBuilder(). - elementCtorAndArgsProvider(ctorAndArgsProvider); - - final StructuredArray> sourceArray = builder.build(); - - StructuredArray subArray1 = sourceArray.get(0); - PointArray subArray2 = subArray1.get(0); - - Assert.assertThat(valueOf(sourceArray.getLength()), CoreMatchers.is(valueOf(lengths[0]))); - Assert.assertThat(valueOf(subArray1.getLength()), CoreMatchers.is(valueOf(lengths[1]))); - Assert.assertThat(valueOf(subArray2.getLength()), CoreMatchers.is(valueOf(lengths[2]))); - Assert.assertTrue(subArray2.getElementClass() == Point.class); - - long[] offsets = {2, 2, 2}; - long[] counts = {13, 5, 3}; - final StructuredArray> newArray = - StructuredArray.copyInstance(sourceArray, offsets, counts); - - assertCorrectVariableInitialisation(counts, newArray, 2); - } - - @Test(expected = ArrayIndexOutOfBoundsException.class) - public void shouldThrowOutOfBoundExceptionForAccessesOutOfBounds() throws NoSuchMethodException { - final long length = 11; - final PointArray array = - PointArray.newInstance(length); - - array.get(length); - } - - @Test - public void shouldNotThrowIncompatibleTypeExceptionForGetsOfProperTypes() throws NoSuchMethodException { - final long[] lengths = {11, 7, 4}; - final StructuredArray> array = get3dBuilder(lengths).build(); - - // Step by step gets of the correct type (array vs. element) per dimension: - StructuredArray subArray1 = array.get(2); - PointArray subArray2 = subArray1.get(2); - subArray2.get(2); - } - - @Test - public void shouldCopyRegionLeftInArray() throws NoSuchMethodException { - final long length = 11; - final PointArray array = - PointArray.newInstance(length); - - initValues(new long[]{length}, array); - - StructuredArray.shallowCopy(array, 4, array, 3, 2, false); - - Assert.assertThat(valueOf(array.get(3).getX()), CoreMatchers.is(valueOf(4))); - Assert.assertThat(valueOf(array.get(4).getX()), CoreMatchers.is(valueOf(5))); - Assert.assertThat(valueOf(array.get(5).getX()), CoreMatchers.is(valueOf(5))); - } - - @Test - public void shouldCopyRegionRightInArray() throws NoSuchMethodException { - final long length = 11; - final PointArray array = - PointArray.newInstance(length); - - initValues(new long[]{length}, array); - - StructuredArray.shallowCopy(array, 5, array, 6, 2, false); - - Assert.assertThat(valueOf(array.get(5).getX()), CoreMatchers.is(valueOf(5))); - Assert.assertThat(valueOf(array.get(6).getX()), CoreMatchers.is(valueOf(5))); - Assert.assertThat(valueOf(array.get(7).getX()), CoreMatchers.is(valueOf(6))); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailToConstructDirectly() throws NoSuchMethodException { - final PointArray array = new PointArray(); - } - - - /////////////////////////////////////////////////////////////////////////////////////////////// - // Test support below - /////////////////////////////////////////////////////////////////////////////////////////////// - - private void assertCorrectFixedInitialisation(final long expectedX, final long expectedY, final long[] lengths, - final StructuredArray array) { - StructuredArray a = array; - for (int i = 0; i < lengths.length - 1; i++) { - Assert.assertThat(valueOf(a.getLength()), CoreMatchers.is(valueOf(lengths[i]))); - a = (StructuredArray) a.get(0); - } - PointArray ap = (PointArray) a; - Assert.assertThat(valueOf(ap.getLength()), CoreMatchers.is(valueOf(lengths[lengths.length - 1]))); - - Assert.assertTrue(ap.getElementClass() == Point.class); - - long totalElementCount = 1; - for (long l : lengths) { - totalElementCount *= l; - } - - final long[] cursors = new long[lengths.length]; - - long elementCountToCursor = 0; - - while (elementCountToCursor < totalElementCount) { - // Check element at cursors: - a = array; - for (int i = 0; i < cursors.length - 1; i++) { - a = (StructuredArray) a.get(cursors[i]); - } - ap = (PointArray) a; - Point point = ap.get(cursors[cursors.length - 1]); - - Assert.assertThat(valueOf(point.getX()), CoreMatchers.is(valueOf(expectedX))); - Assert.assertThat(valueOf(point.getY()), CoreMatchers.is(valueOf(expectedY))); - - // Increment cursors from inner-most dimension out: - for (int cursorDimension = cursors.length - 1; cursorDimension >= 0; cursorDimension--) { - if ((++cursors[cursorDimension]) < lengths[cursorDimension]) { - break; - } - // This dimension wrapped. Reset to zero and continue to one dimension higher - cursors[cursorDimension] = 0; - } - elementCountToCursor++; - } - } - - private void assertCorrectVariableInitialisation(final long[] lengths, - final StructuredArray array) { - assertCorrectVariableInitialisation(lengths, array, 0); - } - - private void assertCorrectVariableInitialisation(final long[] lengths, - final StructuredArray array, long indexOffset) { - StructuredArray a = array; - for (int i = 0; i < lengths.length - 1; i++) { - Assert.assertThat(valueOf(a.getLength()), CoreMatchers.is(valueOf(lengths[i]))); - a = (StructuredArray) a.get(0); - } - PointArray ap = (PointArray) a; - Assert.assertThat(valueOf(ap.getLength()), CoreMatchers.is(valueOf(lengths[lengths.length - 1]))); - - Assert.assertTrue(ap.getElementClass() == Point.class); - - long totalElementCount = 1; - for (long l : lengths) { - totalElementCount *= l; - } - - final long[] cursors = new long[lengths.length]; - - long elementCountToCursor = 0; - - while (elementCountToCursor < totalElementCount) { - // Check element at cursors: - a = array; - for (int i = 0; i < cursors.length - 1; i++) { - a = (StructuredArray) a.get(cursors[i]); - } - ap = (PointArray) a; - Point point = ap.get(cursors[cursors.length - 1]); - - long indexSum = 0; - String cursorsString = ""; - for (long index : cursors) { - indexSum += index + indexOffset; - cursorsString += index + ","; - } - - Assert.assertThat("elementCountToCursor: " + elementCountToCursor + " cursors: " + cursorsString, - valueOf(point.getX()), CoreMatchers.is(valueOf(indexSum))); - Assert.assertThat("elementCountToCursor: " + elementCountToCursor + " cursors: " + cursorsString, - valueOf(point.getY()), CoreMatchers.is(valueOf(indexSum * 2))); - - // Increment cursors from inner-most dimension out: - for (int cursorDimension = cursors.length - 1; cursorDimension >= 0; cursorDimension--) { - if ((++cursors[cursorDimension]) < lengths[cursorDimension]) { - break; - } - // This dimension wrapped. Reset to zero and continue to one dimension higher - cursors[cursorDimension] = 0; - } - elementCountToCursor++; - } - } - - private void initValues(final long[] lengths, final StructuredArray array) { - final long[] cursors = new long[lengths.length]; - long totalElementCount = 1; - for (long l : lengths) { - totalElementCount *= l; - } - - long elementCountToCursor = 0; - - while (elementCountToCursor < totalElementCount) { - // Check element at cursors: - - StructuredArray a = array; - for (int i = 0; i < cursors.length - 1; i++) { - a = (StructuredArray) a.get(cursors[i]); - } - PointArray ap = (PointArray) a; - Point point = ap.get(cursors[cursors.length - 1]); - - long indexSum = 0; - for (long index : cursors) { - indexSum += index; - } - - point.set(indexSum, indexSum * 2); - - // Increment cursors from inner-most dimension out: - for (int cursorDimension = cursors.length - 1; cursorDimension >= 0; cursorDimension--) { - if ((++cursors[cursorDimension]) < lengths[cursorDimension]) { - break; - } - - // This dimension wrapped. Reset to zero and continue to one dimension higher - cursors[cursorDimension] = 0; - } - elementCountToCursor++; - } - } - - - private static class PointCtorAndArgsProvider implements CtorAndArgsProvider { - - private final Class[] argsTypes = {long.class, long.class}; - - @Override - public CtorAndArgs getForContext(ConstructionContext context) throws NoSuchMethodException { - long indexSum = 0; - for (ConstructionContext c = context; c != null; c = c.getContainingContext()) { - indexSum += c.getIndex(); - } - Object[] args = {(int)indexSum, (int)(indexSum * 2)}; - // We could do this much more efficiently with atomic caching of a single allocated CtorAndArgs, - // as CopyCtorAndArgsProvider does, but no need to put in the effort in a test... - return new CtorAndArgs(Point.class.getConstructor(argsTypes), args); } - } - - - StructuredArrayBuilder>, - StructuredArray> get3dBuilder(long... lengths) { - @SuppressWarnings("unchecked") - StructuredArrayBuilder>, - StructuredArray> builder = - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - PointArray.class, - Point.class, - lengths[2] - ), - lengths[1] - ), - lengths[0] - ); - return builder; - } -} diff --git a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/SimpleLineTest.java b/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/SimpleLineTest.java deleted file mode 100644 index 15f3e1b..0000000 --- a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/SimpleLineTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.ObjectLayout.examples.Line; -import org.ObjectLayout.examples.Point; -import org.ObjectLayout.examples.SimpleLine; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Test; - -import static java.lang.Long.valueOf; - -public class SimpleLineTest { - - @Test - public void shouldConstructLine() throws NoSuchMethodException { - SimpleLine line = new SimpleLine(); - Point endPoint1 = line.getEndPoint1(); - Point endPoint2 = line.getEndPoint2(); - - Assert.assertThat(valueOf(endPoint1.getX()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(endPoint1.getY()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(endPoint2.getX()), CoreMatchers.is(0L)); - Assert.assertThat(valueOf(endPoint2.getY()), CoreMatchers.is(0L)); - - Line line2 = new Line(1, 2, 3, 4); - endPoint1 = line2.getEndPoint1(); - endPoint2 = line2.getEndPoint2(); - - Assert.assertThat(valueOf(endPoint1.getX()), CoreMatchers.is(1L)); - Assert.assertThat(valueOf(endPoint1.getY()), CoreMatchers.is(2L)); - Assert.assertThat(valueOf(endPoint2.getX()), CoreMatchers.is(3L)); - Assert.assertThat(valueOf(endPoint2.getY()), CoreMatchers.is(4L)); - - Line line3 = new Line(line2); - endPoint1 = line3.getEndPoint1(); - endPoint2 = line3.getEndPoint2(); - - Assert.assertThat(valueOf(endPoint1.getX()), CoreMatchers.is(1L)); - Assert.assertThat(valueOf(endPoint1.getY()), CoreMatchers.is(2L)); - Assert.assertThat(valueOf(endPoint2.getX()), CoreMatchers.is(3L)); - Assert.assertThat(valueOf(endPoint2.getY()), CoreMatchers.is(4L)); - } -} diff --git a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/StructuredArrayOfAtomicLongTest.java b/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/StructuredArrayOfAtomicLongTest.java deleted file mode 100644 index 93fdd99..0000000 --- a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/StructuredArrayOfAtomicLongTest.java +++ /dev/null @@ -1,180 +0,0 @@ -package org.ObjectLayout.examples;/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.ObjectLayout.StructuredArray; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Test; - -import java.util.concurrent.atomic.AtomicLong; - -import static java.lang.Long.valueOf; - -public class StructuredArrayOfAtomicLongTest { - - @Test - public void shouldInitializeToCorrectValues() { - final long length = 1444; - final StructuredArrayOfAtomicLong array = - StructuredArrayOfAtomicLong.newInstance(length); - - initSumValues(array); - - assertCorrectVariableInitialisation(length, array); - } - - @Test - public void shouldIterateOverArray() { - final long length = 1444; - final StructuredArrayOfAtomicLong array = - StructuredArrayOfAtomicLong.newInstance(length); - - initSumValues(array); - - long sum = 0; - long elementCount = 0; - long indexSum = 0; - long index = 0; - for (final AtomicLong atomicLong : array) { - indexSum += index++; - Assert.assertThat(valueOf(atomicLong.get()), CoreMatchers.is(valueOf(indexSum))); - sum += indexSum; - elementCount++; - } - - long sum2 = 0; - long elementCount2 = 0; - for (final AtomicLong atomicLong : array) { - sum2 += atomicLong.get(); - elementCount2++; - } - - Assert.assertThat(valueOf(elementCount), CoreMatchers.is(valueOf(array.getLength()))); - Assert.assertThat(valueOf(sum), CoreMatchers.is(valueOf(sum2))); - Assert.assertThat(valueOf(elementCount), CoreMatchers.is(valueOf(elementCount2))); - } - - @Test - public void shouldIterateOverArrayAndResetAgain() throws NoSuchMethodException { - final long length = 2456; - final StructuredArrayOfAtomicLong array = - StructuredArrayOfAtomicLong.newInstance(length); - - initSumValues(array); - - long index = 0; - long indexSum = 0; - final StructuredArrayOfAtomicLong.ElementIterator iter = array.iterator(); - while (iter.hasNext()) { - final AtomicLong atomicLong = iter.next(); - indexSum += index++; - Assert.assertThat(valueOf(atomicLong.get()), CoreMatchers.is(valueOf(indexSum))); - } - - iter.reset(); - indexSum = index = 0; - while (iter.hasNext()) { - final AtomicLong atomicLong = iter.next(); - indexSum += index++; - Assert.assertThat(valueOf(atomicLong.get()), CoreMatchers.is(valueOf(indexSum))); - } - - Assert.assertThat(valueOf(index), CoreMatchers.is(valueOf(length))); - } - - @Test(expected = ArrayIndexOutOfBoundsException.class) - public void shouldThrowOutOfBoundExceptionForAccessesOutOfBounds() throws NoSuchMethodException { - final long length = 111; - final StructuredArrayOfAtomicLong array = - StructuredArrayOfAtomicLong.newInstance(length); - - array.get(length); - } - - - @Test - public void shouldNotThrowIncompatibleTypeExceptionForGetsOfProperTypes() throws NoSuchMethodException { - final StructuredArrayOfAtomicLong array = - StructuredArrayOfAtomicLong.newInstance(111); - array.get(2); - } - - @Test - public void shouldCopyRegionLeftInArray() throws NoSuchMethodException { - final long length = 11; - final StructuredArrayOfAtomicLong array = - StructuredArrayOfAtomicLong.newInstance(length); - - initLinearValues(array); - - StructuredArray.shallowCopy(array, 4, array, 3, 2, false); - - Assert.assertThat(valueOf(array.get(3).get()), CoreMatchers.is(valueOf(4))); - Assert.assertThat(valueOf(array.get(4).get()), CoreMatchers.is(valueOf(5))); - Assert.assertThat(valueOf(array.get(5).get()), CoreMatchers.is(valueOf(5))); - } - - @Test - public void shouldCopyRegionRightInArray() throws NoSuchMethodException { - final long length = 11; - final StructuredArrayOfAtomicLong array = - StructuredArrayOfAtomicLong.newInstance(length); - - initLinearValues(array); - - StructuredArray.shallowCopy(array, 5, array, 6, 2, false); - - Assert.assertThat(valueOf(array.get(5).get()), CoreMatchers.is(valueOf(5))); - Assert.assertThat(valueOf(array.get(6).get()), CoreMatchers.is(valueOf(5))); - Assert.assertThat(valueOf(array.get(7).get()), CoreMatchers.is(valueOf(6))); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldFailToConstructDirectly() throws NoSuchMethodException { - final StructuredArrayOfAtomicLong array = new StructuredArrayOfAtomicLong(); - } - - - /////////////////////////////////////////////////////////////////////////////////////////////// - // Test support below - /////////////////////////////////////////////////////////////////////////////////////////////// - - private void assertCorrectVariableInitialisation(final long length, - final StructuredArrayOfAtomicLong array) { - Assert.assertThat(valueOf(array.getLength()), CoreMatchers.is(valueOf(length))); - Assert.assertTrue(array.getElementClass() == AtomicLong.class); - - long indexSum = 0; - - for (long index = 0; index < length; index++) { - indexSum += index; - Assert.assertThat("index: " + index + ": ", valueOf(array.get(index).get()), CoreMatchers.is(valueOf - (indexSum))); - } - } - - private void initSumValues(final StructuredArrayOfAtomicLong array) { - long length = array.getLength(); - long indexSum = 0; - - for (long index = 0; index < length; index++) { - indexSum += index; - array.get(index).set(indexSum); - } - } - - private void initLinearValues(final StructuredArrayOfAtomicLong array) { - long length = array.getLength(); - - for (long index = 0; index < length; index++) { - array.get(index).set(index); - } - } - - public long accessArrayElementValue(StructuredArrayOfAtomicLong array, long index) { - return array.get(index).get(); - } - -} diff --git a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/util/SAHashMapTest.java b/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/util/SAHashMapTest.java deleted file mode 100644 index 5b5a60a..0000000 --- a/ObjectLayout-examples/src/test/java/org/ObjectLayout/examples/util/SAHashMapTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.ObjectLayout.examples.util;/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Test; -import org.ObjectLayout.examples.util.SAHashMap; - -import java.util.HashMap; - -public class SAHashMapTest { - - @Test - public void hashMapPopulateTest() throws NoSuchMethodException { - final SAHashMap saMap = new SAHashMap(); - final HashMap map = new HashMap(); - - final int length = 1<<16; - - // populate hashmaps: - System.out.println(); - for (int i = 0; i < length; i++) { - String intAsString = "Int:" + Integer.toString(i); - saMap.put(i, intAsString); - map.put(i, intAsString); - // Verify: - String e; - Assert.assertThat("Map sizes should be equal", saMap.size(), CoreMatchers.is(map.size())); - Assert.assertThat("saMap entry value mismatch", saMap.get(i), CoreMatchers.is(intAsString)); - Assert.assertThat("map entry value mismatch", map.get(i), CoreMatchers.is(intAsString)); - } - } -} diff --git a/ObjectLayout/LICENSE.txt b/ObjectLayout/LICENSE.txt deleted file mode 100644 index 06f48d0..0000000 --- a/ObjectLayout/LICENSE.txt +++ /dev/null @@ -1,41 +0,0 @@ -The code in this directory was Written by Gil Tene -Martin Thompson, and Michael Barker and released to the public domain, -as explained at http://creativecommons.org/publicdomain/zero/1.0/ - -For users of this code who wish to consume it under the "BSD" license -rather than under the public domain or CC0 contribution text mentioned -above, the code found under this directory is *also* provided under the -following license (commonly referred to as the BSD 2-Clause License). This -license does not detract from the above stated release of the code into -the public domain, and simply represents an additional license granted by -the Author. - ------------------------------------------------------------------------------ -** Beginning of "BSD 2-Clause License" text. ** - - Copyright (c) 2012, 2013, 2014, 2015 Gil Tene - Copyright (c) 2014, 2014, 2015 Michael Barker - Copyright (c) 2012, 2013, 2014 Martin Thompson - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ObjectLayout/pom.xml b/ObjectLayout/pom.xml deleted file mode 100644 index bfac7d6..0000000 --- a/ObjectLayout/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - 4.0.0 - - - org.objectlayout - ObjectLayout-parent - 1.0.5-SNAPSHOT - - - ObjectLayout - ObjectLayout - jar - - - UTF-8 - - - - - junit - junit - 4.13.1 - test - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.7 - - - add-test-source - generate-test-sources - - add-test-source - - - - src/examples/java - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.7 - 1.7 - - -proc:none - UTF-8 - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12.4 - - -Xmx1g - false - - - - - - diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractIntrinsicObjectModel.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractIntrinsicObjectModel.java deleted file mode 100644 index 1176070..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractIntrinsicObjectModel.java +++ /dev/null @@ -1,182 +0,0 @@ -package org.ObjectLayout; - -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.*; - -/** - * This class contains the intrinsifiable portions of IntrinsicObjectModel behavior. JDK implementations - * that choose to intrinsify IntrinsicObjectModel are expected to replace the implementation of this - * base class. - * - * @param The type of the intrinsic object - */ - -abstract class AbstractIntrinsicObjectModel { - MethodHandles.Lookup lookup; - private final Field field; - private final Class containingClass; - private final Class objectClass; - private final AbstractPrimitiveArrayModel primitiveArrayModel; - private final AbstractStructuredArrayModel structuredArrayModel; - - AbstractIntrinsicObjectModel( - MethodHandles.Lookup lookup, - final Field field, - final AbstractPrimitiveArrayModel primitiveArrayModel, - final AbstractStructuredArrayModel structuredArrayModel) { - - @SuppressWarnings("unchecked") - Class objectClass = (Class) field.getType(); - - this.lookup = lookup; - this.field = field; - this.containingClass = field.getDeclaringClass(); - this.objectClass = objectClass; - this.primitiveArrayModel = primitiveArrayModel; - this.structuredArrayModel = structuredArrayModel; - - - try { - // Only set field accessible if the caller actually has access to it: - // Since we cannot get a setter to a final (not asetAccessible) field with - // lookup.findSetter() or lookup.unreflectSetter, we derive the caller's - // access permission to the final field by proving that we can get a getter - // to it (which would not be possible if it were e.g. private and the caller - // was not the declaring class). Once we prove to ourselves that the - // caller is allowed to access the field, we make (our internal copy of) - // field setAccesible to allow overwriting of final fields... - MethodHandle getter = lookup.unreflectGetter(field); // May throw IllegalAccessException - field.setAccessible(true); - } catch (IllegalAccessException ex) { - throw new IllegalArgumentException(ex); - } - - - sanityCheckAtModelConstruction(lookup); - } - - Class getObjectClass() { - return objectClass; - } - - private void sanityCheckAtModelConstruction(MethodHandles.Lookup lookup) { - if ((primitiveArrayModel != null) && - !primitiveArrayModel._getArrayClass().equals(objectClass)) { - throw new IllegalArgumentException("Generic object class \"" + objectClass + - "\" does not match the array class \"" + primitiveArrayModel._getArrayClass() + - "\" in the supplied array model"); - - } - if ((structuredArrayModel != null) && - !structuredArrayModel._getArrayClass().equals(objectClass)) { - throw new IllegalArgumentException("Generic object class \"" + objectClass + - "\" does not match the array class \"" + structuredArrayModel._getArrayClass() + - "\" in the supplied array model"); - - } - // Verify field is private, final, non-static, and an object reference of the proper type: - if (!Object.class.isAssignableFrom(objectClass)) { - throw new IllegalArgumentException("Declared generic object class (\"" + objectClass.getName() + - "\" is not a reference type (must derive from Object)"); - } - if (!(Modifier.isFinal(field.getModifiers()) && - Modifier.isPrivate(field.getModifiers()))) { - throw new IllegalArgumentException("Intrinsic objects can only be declared for private final fields"); - } - if (Modifier.isStatic(field.getModifiers())) { - throw new IllegalArgumentException("Intrinsic objects can only be declared for instance fields. " + - "Cannot be static"); - } - if (objectClass != field.getType()) { - throw new IllegalArgumentException( - "The field type \"" + field.getType().getName() + "\" does not match the " + - "specified objectClass \"" + objectClass.getName() + "\""); - } - } - - /** - * Construct a fresh element intended to occupy a given intrinsic field in the containing object, using the - * supplied constructor and arguments. - * - * OPTIMIZATION NOTE: Optimized JDK implementations may replace this implementation with a - * construction-in-place call on a previously allocated memory location associated with the given index. - */ - final T constructElementWithin( - final Object containingObject, - final Constructor constructor, - final Object... args) - throws InstantiationException, IllegalAccessException, InvocationTargetException { - T element = constructor.newInstance(args); - directlyInitializeTargetField(containingObject, element); - return element; - } - - /** - * Construct a fresh primitive sub-array intended to occupy a given intrinsic field in the containing object, - * at the field described by the supplied intrinsicObjectModel, using the supplied constructor and arguments. - * - * OPTIMIZATION NOTE: Optimized JDK implementations may replace this implementation with a - * construction-in-place call on a previously allocated memory location associated with the given index. - */ - final T constructPrimitiveArrayWithin( - final Object containingObject, - final Constructor constructor, - final Object... args) - throws InstantiationException, IllegalAccessException, InvocationTargetException { - int length = (int) primitiveArrayModel._getLength(); - @SuppressWarnings("unchecked") - Constructor c = (Constructor) constructor; - @SuppressWarnings("unchecked") - T element = (T) AbstractPrimitiveArray._newInstance(length, c, args); - directlyInitializeTargetField(containingObject, element); - return element; - } - - final void _sanityCheckInstantiation(final Object containingObject) { - try { - if (field.get(containingObject) != null) { - throw new IllegalStateException("Intrinsic object field \"" + field.getName() + - "\" in containing object is already initialized"); - } - } catch (IllegalAccessException e) { - throw new IllegalStateException(e); - } - } - - final boolean _isPrimitiveArray() { - return (primitiveArrayModel != null); - } - - final boolean _isStructuredArray() { - return (structuredArrayModel != null); - } - - final AbstractStructuredArrayModel _getStructuredArrayModel() { - return structuredArrayModel; - } - - final AbstractPrimitiveArrayModel _getPrimitiveArrayModel() { - return primitiveArrayModel; - } - - void directlyInitializeTargetField(final Object containingObject, - T intrinsicObject) { - try { - if (field.get(containingObject) != null) { - throw new IllegalStateException( - "Bad value for field \"" + - field.getName() + - "\". Intrinsic object field was initialized without being " + - "constructed by IntrinsicObjectModel.constructWithin(). " + - "Cannot make any of the intrinsic objects fields accessible." - ); - } - field.set(containingObject, intrinsicObject); - } catch (IllegalAccessException e) { - throw new IllegalStateException(e); - } catch (Throwable ex) { - throw new RuntimeException(ex); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveArray.java deleted file mode 100644 index ef9ef55..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveArray.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Array; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -/** - * A abstract base class for subclassable primitive and reference arrays. - * - * Subclassable arrays are useful for modeling the commonly used "struct with variable array at the end" - * available in the C family of languages. JDKs may optimize the layout of a PrimitiveArray such that - * access to the array members may be faster than regular de-referenced access through a nested array - * reference. - */ - -abstract class AbstractPrimitiveArray { - - static final MethodHandles.Lookup noLookup = null; - - private final long length; - - static A _newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - try { - return instantiate(lookup, length, arrayClass.getDeclaredConstructor(), (Object[]) null); - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } - - static A _newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return instantiate(length, arrayCtorAndArgs.getConstructor(), arrayCtorAndArgs.getArgs()); - } - - static A _newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return instantiate(length, arrayConstructor, arrayConstructorArgs); - } - - static A _copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - @SuppressWarnings("unchecked") - final Class sourceArrayClass = (Class) source.getClass(); - Constructor arrayConstructor = sourceArrayClass.getDeclaredConstructor(sourceArrayClass); - return instantiate(lookup, source._getLength(), arrayConstructor, source); - } - - /** - * create a fresh PrimitiveArray intended to occupy a a given intrinsic field in the containing object, - * at the field described by the supplied intrinsicObjectModel, using the supplied constructor and arguments. - */ - static A constructPrimitiveArrayWithin( - MethodHandles.Lookup lookup, - final Object containingObject, - final AbstractIntrinsicObjectModel intrinsicObjectModel, - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - A array = instantiate(lookup, length, arrayConstructor, arrayConstructorArgs); - intrinsicObjectModel.directlyInitializeTargetField(containingObject, array); - return array; - } - - private static A instantiate( - MethodHandles.Lookup lookup, - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - try { - if (lookup != null) { - if (!CtorAndArgs.belongsToThisPackage(arrayConstructor.getDeclaringClass())) { - lookup.unreflectConstructor(arrayConstructor); // May throw IllegalAccessException - arrayConstructor.setAccessible(true); - } - } - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } - return instantiate(length, arrayConstructor, arrayConstructorArgs); - } - - private static A instantiate( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - try { - preInstantiation(length, arrayConstructor, arrayConstructorArgs); - return arrayConstructor.newInstance(arrayConstructorArgs); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) { - throw new RuntimeException(ex); - } finally { - postInstantiation(); - } - } - - static void preInstantiation( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - ConstructorMagic constructorMagic = getConstructorMagic(); - constructorMagic.setArrayConstructorArgs(length); - constructorMagic.setActive(true); - } - - static void postInstantiation() { - ConstructorMagic constructorMagic = getConstructorMagic(); - constructorMagic.setActive(false); - } - - AbstractPrimitiveArray() { - checkConstructorMagic(); - ConstructorMagic constructorMagic = getConstructorMagic(); - length = constructorMagic.getLength(); - constructorMagic.setActive(false); - } - - AbstractPrimitiveArray(AbstractPrimitiveArray source) { - this(); - } - - final long _getLength() { - return length; - } - - // ConstructorMagic support: - - private static class ConstructorMagic { - private boolean isActive() { - return active; - } - - private void setActive(final boolean active) { - this.active = active; - } - - private void setArrayConstructorArgs(final long length) { - this.length = length; - } - - private long getLength() { - return length; - } - - private boolean active = false; - private long length = 0; - } - - private static final ThreadLocal threadLocalConstructorMagic = new ThreadLocal<>(); - - private static ConstructorMagic getConstructorMagic() { - ConstructorMagic constructorMagic = threadLocalConstructorMagic.get(); - if (constructorMagic == null) { - constructorMagic = new ConstructorMagic(); - threadLocalConstructorMagic.set(constructorMagic); - } - return constructorMagic; - } - - private static void checkConstructorMagic() { - final ConstructorMagic constructorMagic = threadLocalConstructorMagic.get(); - if ((constructorMagic == null) || !constructorMagic.isActive()) { - throw new IllegalArgumentException( - "PrimitiveArray must not be directly instantiated with a constructor." + - " Use newInstance(...) instead."); - } - } - - static final int MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT = 30; - static final int MAX_EXTRA_PARTITION_SIZE = 1 << MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT; - static final int PARTITION_MASK = MAX_EXTRA_PARTITION_SIZE - 1; - - final Object createIntAddressableElements(Class componentClass) { - long length = _getLength(); - // Size int-addressable sub arrays: - final int intLength = (int) Math.min(length, Integer.MAX_VALUE); - return Array.newInstance(componentClass, intLength); - } - - final Object createLongAddressableElements(Class componentClass) { - long length = _getLength(); - // Compute size of int-addressable sub array: - final int intLength = (int) Math.min(length, Integer.MAX_VALUE); - // Size Subsequent partitions hold long-addressable-only sub arrays: - final long extraLength = length - intLength; - final int numFullPartitions = (int) (extraLength >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int lastPartitionSize = (int) extraLength & PARTITION_MASK; - - Object lastPartition = Array.newInstance(componentClass, lastPartitionSize); - Class partitionClass = lastPartition.getClass(); - Object[] longAddressableElements = (Object[]) Array.newInstance(partitionClass, numFullPartitions + 1); - - // longAddressableElements = new long[numFullPartitions + 1][]; - - // full long-addressable-only partitions: - for (int i = 0; i < numFullPartitions; i++) { - longAddressableElements[i] = Array.newInstance(componentClass, MAX_EXTRA_PARTITION_SIZE); - } - - // Last partition with leftover long-addressable-only size: - longAddressableElements[numFullPartitions] = lastPartition; - - return longAddressableElements; - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveArrayModel.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveArrayModel.java deleted file mode 100644 index 90e36e1..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveArrayModel.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.ObjectLayout; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; - -/** - * A model that describes the structure of a StructuredArray or PrimitiveArray - * - * @param The class of the array modeled by the model - */ -abstract class AbstractPrimitiveArrayModel { - private final Class arrayClass; - private final long length; - - /** - * Create a model of an array instance with terminal (non StructuredArray) elements - * - * @param arrayClass The class of the array modeled by the model - * @param length The length of the StructuredArray modeled by the model - */ - AbstractPrimitiveArrayModel(final Class arrayClass, - final long length) { - this.arrayClass = arrayClass != null ? arrayClass : deriveArrayTypeParameter(); - this.length = length; - } - - /** - * Get the class of the array modeled by this model - * @return the class of the StructuredArray modeled by this model - */ - final Class _getArrayClass() { - return arrayClass; - } - - /** - * Get the length of the array modeled by the model - * @return The length of the StructuredArray modeled by the model - */ - final long _getLength() { - return length; - } - - private Class deriveArrayTypeParameter() { - ParameterizedType genericSuperclass = (ParameterizedType) this.getClass().getGenericSuperclass(); - @SuppressWarnings("unchecked") - Class derivedType = typeToClass(genericSuperclass.getActualTypeArguments()[0]); - return derivedType; - } - - static Class typeToClass(Type t) { - if (t instanceof Class) { - return (Class) t; - } else if (t instanceof ParameterizedType) { - return (Class) ((ParameterizedType)t).getRawType(); - } else { - throw new IllegalArgumentException(); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveByteArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveByteArray.java deleted file mode 100644 index 7018e61..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveByteArray.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -/** - * This class contains the intrinsifiable portions of PrimitiveByteArray behavior. JDK implementations - * that choose to intrinsify PrimitiveByteArray are expected to replace the implementation of this - * base class. - */ - -abstract class AbstractPrimitiveByteArray extends AbstractPrimitiveArray { - - private final byte[][] longAddressableElements; // Used to store elements at indexes above Integer.MAX_VALUE - private final byte[] intAddressableElements; - - final byte[] _asArray() { - if (_getLength() > Integer.MAX_VALUE) { - throw new IllegalStateException( - "Cannot make byte[] from array with more than Integer.MAX_VALUE elements (" + - _getLength() + ")"); - } - return intAddressableElements; - } - - byte _get(final int index) { - return intAddressableElements[index]; - } - - byte _get(final long index) { - if (index < Integer.MAX_VALUE) { - return _get((int) index); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - return longAddressableElements[partitionIndex][partitionOffset]; - } - - void _set(final int index, final byte value) { - intAddressableElements[index] = value; - } - - void _set(final long index, final byte value) { - if (index < Integer.MAX_VALUE) { - _set((int) index, value); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - longAddressableElements[partitionIndex][partitionOffset] = value; - } - - AbstractPrimitiveByteArray() { - intAddressableElements = (byte[]) createIntAddressableElements(byte.class); - longAddressableElements = (byte[][]) createLongAddressableElements(byte.class); - } - - AbstractPrimitiveByteArray(AbstractPrimitiveByteArray sourceArray) { - intAddressableElements = sourceArray.intAddressableElements.clone(); - int numLongAddressablePartitions = sourceArray.longAddressableElements.length; - longAddressableElements = new byte[numLongAddressablePartitions][]; - for (int i = 0; i < numLongAddressablePartitions; i++) { - longAddressableElements[i] = sourceArray.longAddressableElements[i].clone(); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveCharArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveCharArray.java deleted file mode 100644 index 21ef8c1..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveCharArray.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -/** - * This class contains the intrinsifiable portions of PrimitiveCharArray behavior. JDK implementations - * that choose to intrinsify PrimitiveCharArray are expected to replace the implementation of this - * base class. - */ - -abstract class AbstractPrimitiveCharArray extends AbstractPrimitiveArray { - - private final char[][] longAddressableElements; // Used to store elements at indexes above Integer.MAX_VALUE - private final char[] intAddressableElements; - - final char[] _asArray() { - if (_getLength() > Integer.MAX_VALUE) { - throw new IllegalStateException( - "Cannot make char[] from array with more than Integer.MAX_VALUE elements (" + - _getLength() + ")"); - } - return intAddressableElements; - } - - char _get(final int index) { - return intAddressableElements[index]; - } - - char _get(final long index) { - if (index < Integer.MAX_VALUE) { - return _get((int) index); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - return longAddressableElements[partitionIndex][partitionOffset]; - } - - void _set(final int index, final char value) { - intAddressableElements[index] = value; - } - - void _set(final long index, final char value) { - if (index < Integer.MAX_VALUE) { - _set((int) index, value); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - longAddressableElements[partitionIndex][partitionOffset] = value; - } - - AbstractPrimitiveCharArray() { - intAddressableElements = (char[]) createIntAddressableElements(char.class); - longAddressableElements = (char[][]) createLongAddressableElements(char.class); - } - - AbstractPrimitiveCharArray(AbstractPrimitiveCharArray sourceArray) { - intAddressableElements = sourceArray.intAddressableElements.clone(); - int numLongAddressablePartitions = sourceArray.longAddressableElements.length; - longAddressableElements = new char[numLongAddressablePartitions][]; - for (int i = 0; i < numLongAddressablePartitions; i++) { - longAddressableElements[i] = sourceArray.longAddressableElements[i].clone(); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveDoubleArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveDoubleArray.java deleted file mode 100644 index 7c6982a..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveDoubleArray.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -/** - * This class contains the intrinsifiable portions of PrimitiveDoubleArray behavior. JDK implementations - * that choose to intrinsify PrimitiveDoubleArray are expected to replace the implementation of this - * base class. - */ - -abstract class AbstractPrimitiveDoubleArray extends AbstractPrimitiveArray { - - private final double[][] longAddressableElements; // Used to store elements at indexes above Integer.MAX_VALUE - private final double[] intAddressableElements; - - final double[] _asArray() { - if (_getLength() > Integer.MAX_VALUE) { - throw new IllegalStateException( - "Cannot make double[] from array with more than Integer.MAX_VALUE elements (" + - _getLength() + ")"); - } - return intAddressableElements; - } - - double _get(final int index) { - return intAddressableElements[index]; - } - - double _get(final long index) { - if (index < Integer.MAX_VALUE) { - return _get((int) index); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - return longAddressableElements[partitionIndex][partitionOffset]; - } - - void _set(final int index, final double value) { - intAddressableElements[index] = value; - } - - void _set(final long index, final double value) { - if (index < Integer.MAX_VALUE) { - _set((int) index, value); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - longAddressableElements[partitionIndex][partitionOffset] = value; - } - - AbstractPrimitiveDoubleArray() { - intAddressableElements = (double[]) createIntAddressableElements(double.class); - longAddressableElements = (double[][]) createLongAddressableElements(double.class); - } - - AbstractPrimitiveDoubleArray(AbstractPrimitiveDoubleArray sourceArray) { - intAddressableElements = sourceArray.intAddressableElements.clone(); - int numLongAddressablePartitions = sourceArray.longAddressableElements.length; - longAddressableElements = new double[numLongAddressablePartitions][]; - for (int i = 0; i < numLongAddressablePartitions; i++) { - longAddressableElements[i] = sourceArray.longAddressableElements[i].clone(); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveFloatArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveFloatArray.java deleted file mode 100644 index c6407db..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveFloatArray.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -/** - * This class contains the intrinsifiable portions of PrimitiveFloatArray behavior. JDK implementations - * that choose to intrinsify PrimitiveFloatArray are expected to replace the implementation of this - * base class. - */ - -abstract class AbstractPrimitiveFloatArray extends AbstractPrimitiveArray { - - private final float[][] longAddressableElements; // Used to store elements at indexes above Integer.MAX_VALUE - private final float[] intAddressableElements; - - final float[] _asArray() { - if (_getLength() > Integer.MAX_VALUE) { - throw new IllegalStateException( - "Cannot make float[] from array with more than Integer.MAX_VALUE elements (" + - _getLength() + ")"); - } - return intAddressableElements; - } - - float _get(final int index) { - return intAddressableElements[index]; - } - - float _get(final long index) { - if (index < Integer.MAX_VALUE) { - return _get((int) index); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - return longAddressableElements[partitionIndex][partitionOffset]; - } - - void _set(final int index, final float value) { - intAddressableElements[index] = value; - } - - void _set(final long index, final float value) { - if (index < Integer.MAX_VALUE) { - _set((int) index, value); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - longAddressableElements[partitionIndex][partitionOffset] = value; - } - - AbstractPrimitiveFloatArray() { - intAddressableElements = (float[]) createIntAddressableElements(float.class); - longAddressableElements = (float[][]) createLongAddressableElements(float.class); - } - - AbstractPrimitiveFloatArray(AbstractPrimitiveFloatArray sourceArray) { - intAddressableElements = sourceArray.intAddressableElements.clone(); - int numLongAddressablePartitions = sourceArray.longAddressableElements.length; - longAddressableElements = new float[numLongAddressablePartitions][]; - for (int i = 0; i < numLongAddressablePartitions; i++) { - longAddressableElements[i] = sourceArray.longAddressableElements[i].clone(); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveIntArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveIntArray.java deleted file mode 100644 index ec7f769..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveIntArray.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -/** - * This class contains the intrinsifiable portions of PrimitiveIntArray behavior. JDK implementations - * that choose to intrinsify PrimitiveIntArray are expected to replace the implementation of this - * base class. - */ - -abstract class AbstractPrimitiveIntArray extends AbstractPrimitiveArray { - - private final int[][] longAddressableElements; // Used to store elements at indexes above Integer.MAX_VALUE - private final int[] intAddressableElements; - - final int[] _asArray() { - if (_getLength() > Integer.MAX_VALUE) { - throw new IllegalStateException( - "Cannot make int[] from array with more than Integer.MAX_VALUE elements (" + - _getLength() + ")"); - } - return intAddressableElements; - } - - int _get(final int index) { - return intAddressableElements[index]; - } - - int _get(final long index) { - if (index < Integer.MAX_VALUE) { - return _get((int) index); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - return longAddressableElements[partitionIndex][partitionOffset]; - } - - void _set(final int index, final int value) { - intAddressableElements[index] = value; - } - - void _set(final long index, final int value) { - if (index < Integer.MAX_VALUE) { - _set((int) index, value); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - longAddressableElements[partitionIndex][partitionOffset] = value; - } - - AbstractPrimitiveIntArray() { - intAddressableElements = (int[]) createIntAddressableElements(int.class); - longAddressableElements = (int[][]) createLongAddressableElements(int.class); - } - - AbstractPrimitiveIntArray(AbstractPrimitiveIntArray sourceArray) { - intAddressableElements = sourceArray.intAddressableElements.clone(); - int numLongAddressablePartitions = sourceArray.longAddressableElements.length; - longAddressableElements = new int[numLongAddressablePartitions][]; - for (int i = 0; i < numLongAddressablePartitions; i++) { - longAddressableElements[i] = sourceArray.longAddressableElements[i].clone(); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveLongArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveLongArray.java deleted file mode 100644 index 77819a9..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveLongArray.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -/** - * This class contains the intrinsifiable portions of PrimitiveLongArray behavior. JDK implementations - * that choose to intrinsify PrimitiveLongArray are expected to replace the implementation of this - * base class. - */ - -abstract class AbstractPrimitiveLongArray extends AbstractPrimitiveArray { - - private final long[][] longAddressableElements; // Used to store elements at indexes above Integer.MAX_VALUE - private final long[] intAddressableElements; - - final long[] _asArray() { - if (_getLength() > Integer.MAX_VALUE) { - throw new IllegalStateException( - "Cannot make long[] from array with more than Integer.MAX_VALUE elements (" + - _getLength() + ")"); - } - return intAddressableElements; - } - - long _get(final int index) { - return intAddressableElements[index]; - } - - long _get(final long index) { - if (index < Integer.MAX_VALUE) { - return _get((int) index); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - return longAddressableElements[partitionIndex][partitionOffset]; - } - - void _set(final int index, final long value) { - intAddressableElements[index] = value; - } - - void _set(final long index, final long value) { - if (index < Integer.MAX_VALUE) { - _set((int) index, value); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - longAddressableElements[partitionIndex][partitionOffset] = value; - } - - AbstractPrimitiveLongArray() { - intAddressableElements = (long[]) createIntAddressableElements(long.class); - longAddressableElements = (long[][]) createLongAddressableElements(long.class); - } - - AbstractPrimitiveLongArray(AbstractPrimitiveLongArray sourceArray) { - intAddressableElements = sourceArray.intAddressableElements.clone(); - int numLongAddressablePartitions = sourceArray.longAddressableElements.length; - longAddressableElements = new long[numLongAddressablePartitions][]; - for (int i = 0; i < numLongAddressablePartitions; i++) { - longAddressableElements[i] = sourceArray.longAddressableElements[i].clone(); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveShortArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveShortArray.java deleted file mode 100644 index 1fbbeb0..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractPrimitiveShortArray.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -/** - * This class contains the intrinsifiable portions of PrimitiveShortArray behavior. JDK implementations - * that choose to intrinsify PrimitiveShortArray are expected to replace the implementation of this - * base class. - */ - -abstract class AbstractPrimitiveShortArray extends AbstractPrimitiveArray { - - private final short[][] longAddressableElements; // Used to store elements at indexes above Integer.MAX_VALUE - private final short[] intAddressableElements; - - final short[] _asArray() { - if (_getLength() > Integer.MAX_VALUE) { - throw new IllegalStateException( - "Cannot make short[] from array with more than Integer.MAX_VALUE elements (" + - _getLength() + ")"); - } - return intAddressableElements; - } - - short _get(final int index) { - return intAddressableElements[index]; - } - - short _get(final long index) { - if (index < Integer.MAX_VALUE) { - return _get((int) index); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - return longAddressableElements[partitionIndex][partitionOffset]; - } - - void _set(final int index, final short value) { - intAddressableElements[index] = value; - } - - void _set(final long index, final short value) { - if (index < Integer.MAX_VALUE) { - _set((int) index, value); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - longAddressableElements[partitionIndex][partitionOffset] = value; - } - - AbstractPrimitiveShortArray() { - intAddressableElements = (short[]) createIntAddressableElements(short.class); - longAddressableElements = (short[][]) createLongAddressableElements(short.class); - } - - AbstractPrimitiveShortArray(AbstractPrimitiveShortArray sourceArray) { - intAddressableElements = sourceArray.intAddressableElements.clone(); - int numLongAddressablePartitions = sourceArray.longAddressableElements.length; - longAddressableElements = new short[numLongAddressablePartitions][]; - for (int i = 0; i < numLongAddressablePartitions; i++) { - longAddressableElements[i] = sourceArray.longAddressableElements[i].clone(); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractReferenceArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractReferenceArray.java deleted file mode 100644 index b039105..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractReferenceArray.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -/** - * This class contains the intrinsifiable portions of PrimitiveShortArray behavior. JDK implementations - * that choose to intrinsify PrimitiveShortArray are expected to replace the implementation of this - * base class. - */ - -abstract class AbstractReferenceArray extends AbstractPrimitiveArray { - - private final T[][] longAddressableElements; // Used to store elements at indexes above Integer.MAX_VALUE - private final T[] intAddressableElements; - - final T[] _asArray() { - if (_getLength() > Integer.MAX_VALUE) { - throw new IllegalStateException( - "Cannot make T[] from array with more than Integer.MAX_VALUE elements (" + - _getLength() + ")"); - } - return intAddressableElements; - } - - T _get(final int index) { - return intAddressableElements[index]; - } - - T _get(final long index) { - if (index < Integer.MAX_VALUE) { - return _get((int) index); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - return longAddressableElements[partitionIndex][partitionOffset]; - } - - void _set(final int index, final T value) { - intAddressableElements[index] = value; - } - - void _set(final long index, final T value) { - if (index < Integer.MAX_VALUE) { - _set((int) index, value); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - longAddressableElements[partitionIndex][partitionOffset] = value; - } - @SuppressWarnings("unchecked") - AbstractReferenceArray() { - intAddressableElements = (T[]) createIntAddressableElements(Object.class); - longAddressableElements = (T[][]) createLongAddressableElements(Object.class); - } - - @SuppressWarnings("unchecked") - AbstractReferenceArray(AbstractReferenceArray sourceArray) { - intAddressableElements = (T[]) sourceArray.intAddressableElements.clone(); - int numLongAddressablePartitions = sourceArray.longAddressableElements.length; - longAddressableElements = (T[][]) new Object[numLongAddressablePartitions][]; - for (int i = 0; i < numLongAddressablePartitions; i++) { - longAddressableElements[i] = (T[]) sourceArray.longAddressableElements[i].clone(); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArray.java deleted file mode 100644 index 3df5e36..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArray.java +++ /dev/null @@ -1,1062 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.util.Collection; -import java.util.Iterator; - -import static java.lang.reflect.Modifier.isFinal; -import static java.lang.reflect.Modifier.isStatic; - -/** - * An array of non-replaceable objects. - *

- * A structured array contains array element objects of a fixed (at creation time, per array instance) class, - * and can support elements of any class that provides accessible constructors. The elements in a StructuredArray - * are all allocated and constructed at array creation time, and individual elements cannot be removed or - * replaced after array creation. Array elements can be accessed using an index-based accessor methods in - * the form of {@link AbstractStructuredArray#get}() using either int or long indices. Individual element contents - * can then be accessed and manipulated using any and all operations supported by the member element's class. - *

- * While simple creation of default-constructed elements and fixed constructor parameters are available through - * the newInstance factory methods, supporting arbitrary member types requires a wider range of construction - * options. The {@link CtorAndArgsProvider} API provides for array creation with arbitrary, user-supplied - * constructors and arguments, the selection of which can take the element index and construction context - * into account. - *

- * StructuredArray is designed with semantics specifically chosen and restricted such that a "flat" memory - * layout of the implemented data structure would be possible on optimizing JVMs. Doing so provides for the - * possibility of matching access speed benefits that exist in data structures with similar semantics that - * are supported in other languages (e.g. an array of structs in C-like languages). While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates consistent stride - * based memory access and dead-reckoning (as opposed to de-referenced) access to elements - * - * @param The class of the array elements - */ -abstract class AbstractStructuredArray extends AbstractStructuredArrayBase { - - private static final Class[] EMPTY_ARG_TYPES = new Class[0]; - private static final Object[] EMPTY_ARGS = new Object[0]; - private static final MethodHandles.Lookup noLookup = null; - - final Field[] fields; - final boolean hasFinalFields; - - private final StructuredArrayModel, T> arrayModel; - - // Single-dimensional newInstance forms: - - /** - * Create an array of length elements, each containing an element object of - * type elementClass. Using the elementClass's default constructor. - * - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array elements - * @return The newly created array - */ - static AbstractStructuredArray _newInstance( - final Class elementClass, - final long length) { - @SuppressWarnings("unchecked") - AbstractStructuredArray instance = _newInstance(AbstractStructuredArray.class, elementClass, length); - return instance; - } - - /** - * Create an array of length elements, each containing an element object of - * type elementClass. Using the elementClass's default constructor. - * - * @param lookup The lookup object to use when resolving constructors - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array elements - * @return The newly created array - */ - static AbstractStructuredArray _newInstance( - MethodHandles.Lookup lookup, - final Class elementClass, - final long length) { - @SuppressWarnings("unchecked") - AbstractStructuredArray instance = _newInstance(lookup, AbstractStructuredArray.class, elementClass, length); - return instance; - } - - /** - * Create an arrayClass array of length elements of - * type elementClass. Using the elementClass's default constructor. - * - * @param arrayClass of the array to create - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - final Class arrayClass, - final Class elementClass, - final long length) { - return _newInstance(noLookup, arrayClass, elementClass, length); - } - - /** - * Create an arrayClass array of length elements of - * type elementClass. Using the elementClass's default constructor. - * - * @param lookup The lookup object to use when resolving constructors - * @param arrayClass of the array to create - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final long length) { - CtorAndArgs arrayCtorAndArgs = new CtorAndArgs<>(lookup, arrayClass, EMPTY_ARG_TYPES, EMPTY_ARGS); - return _newInstance(lookup, arrayCtorAndArgs, elementClass, length); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use elementClass's default constructor. - * - * @param arrayCtorAndArgs for creating the array - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - final CtorAndArgs arrayCtorAndArgs, - final Class elementClass, - final long length) { - return _newInstance(noLookup, arrayCtorAndArgs, elementClass, length); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use elementClass's default constructor. - * - * @param lookup The lookup object to use when resolving constructors - * @param arrayCtorAndArgs for creating the array - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - MethodHandles.Lookup lookup, - final CtorAndArgs arrayCtorAndArgs, - final Class elementClass, - final long length) { - AbstractStructuredArrayBuilder arrayBuilder = new AbstractStructuredArrayBuilder<>( - lookup, - arrayCtorAndArgs.getConstructor().getDeclaringClass(), - elementClass, - length). - arrayCtorAndArgs(arrayCtorAndArgs). - resolve(); - return instantiate(arrayBuilder); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use elementClass's default constructor. - * - * @param arrayCtorAndArgs for creating the array - * @param elementCtorAndArgs of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - final CtorAndArgs arrayCtorAndArgs, - final CtorAndArgs elementCtorAndArgs, - final long length) { - AbstractStructuredArrayBuilder arrayBuilder = new AbstractStructuredArrayBuilder<>( - arrayCtorAndArgs.getConstructor().getDeclaringClass(), - elementCtorAndArgs.getConstructor().getDeclaringClass(), - length). - arrayCtorAndArgs(arrayCtorAndArgs). - elementCtorAndArgs(elementCtorAndArgs). - resolve(); - return instantiate(arrayBuilder); - } - - /** - * Create an array of length elements of type elementClass. Use constructor and - * arguments supplied (on a potentially per element index basis) by the specified - * ctorAndArgsProvider to construct and initialize each element. - * - * @param elementClass of each element in the array - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param length of the array to create - * @param The class of the array elements - * @return The newly created array - */ - static AbstractStructuredArray _newInstance( - final Class elementClass, - final CtorAndArgsProvider ctorAndArgsProvider, - final long length) { - return instantiate(elementClass, length, ctorAndArgsProvider); - } - - /** - * Create an arrayClass array of length elements, each containing an element object of - * type elementClass. Use constructor and arguments supplied (on a potentially - * per element index basis) by the specified ctorAndArgsProvider to construct and initialize - * each element. - * - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param length of the array to create - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - final Class arrayClass, - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - return _newInstance(noLookup, arrayClass, elementClass, length, ctorAndArgsProvider); - } - - /** - * Create an arrayClass array of length elements, each containing an element object of - * type elementClass. Use constructor and arguments supplied (on a potentially - * per element index basis) by the specified ctorAndArgsProvider to construct and initialize - * each element. - * - * @param lookup The lookup object to use when resolving constructors - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param length of the array to create - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - CtorAndArgs arrayCtorAndArgs = new CtorAndArgs<>(lookup, arrayClass, EMPTY_ARG_TYPES, EMPTY_ARGS); - return instantiate(arrayCtorAndArgs, elementClass, length, ctorAndArgsProvider); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use constructor and arguments - * supplied (on a potentially per element index basis) by the specified ctorAndArgsProvider - * to construct and initialize each element. - * - * @param arrayCtorAndArgs of the array to create - * @param elementClass of each element in the array - * @param length of the array to create - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - final CtorAndArgs arrayCtorAndArgs, - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - return instantiate(arrayCtorAndArgs, elementClass, length, ctorAndArgsProvider); - } - - /** - * Create a <S extends StructuredArray<T>> array instance with elements copied from a source - * collection. - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param sourceCollection provides details for building the array - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - final Class arrayClass, - final Class elementClass, - final Collection sourceCollection) { - return _newInstance(noLookup, arrayClass, elementClass, sourceCollection); - } - - /** - * Create a <S extends StructuredArray<T>> array instance with elements copied from a source - * collection. - * @param lookup The lookup object to use when resolving constructors - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param sourceCollection provides details for building the array - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final Collection sourceCollection) { - - long length = sourceCollection.size(); - for (T element : sourceCollection) { - if (element.getClass() != elementClass) { - throw new IllegalArgumentException( - "Collection contains elements of type other than elementClass " + elementClass.getName()); - } - } - - final CtorAndArgs copyCtorAndArgs; - final Object[] args = new Object[1]; - try { - copyCtorAndArgs = new CtorAndArgs<>(lookup, elementClass, new Class[] {elementClass}, args); - } catch (RuntimeException ex) { - throw new IllegalArgumentException("Failed to locate copy constructor and args for elementClass " + - elementClass.getName() + ".", ex); - } - - final Iterator sourceIterator = sourceCollection.iterator(); - - AbstractStructuredArrayBuilder arrayBuilder = new AbstractStructuredArrayBuilder<>( - lookup, - arrayClass, - elementClass, - length). - elementCtorAndArgsProvider( - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext(ConstructionContext context) { - args[0] = sourceIterator.next(); - return copyCtorAndArgs.setArgs(args); - } - } - ); - - return instantiate(arrayBuilder); - } - - /** - * Create a <S extends StructuredArray<T>> array instance according to the details provided in the - * arrayBuilder. - * @param arrayBuilder provides details for building the array - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _newInstance( - final AbstractStructuredArrayBuilder arrayBuilder) { - return instantiate(arrayBuilder); - } - - /** - * Copy a given array of elements to a newly created array. Copying of individual elements is done by using - * the elementClass copy constructor to construct the individual member elements of the new - * array based on the corresponding elements of the source array. - * - * @param source The array to duplicate - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _copyInstance( - final S source) { - return _copyInstance(noLookup, source); - } - - /** - * Copy a given array of elements to a newly created array. Copying of individual elements is done by using - * the elementClass copy constructor to construct the individual member elements of the new - * array based on the corresponding elements of the source array. - * - * @param lookup The lookup object to use when resolving constructors - * @param source The array to duplicate - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _copyInstance( - MethodHandles.Lookup lookup, - final S source) { - return _copyInstance(lookup, source, 0, source.getLength()); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - * - * @param source The array to copy from - * @param sourceOffset offset index, indicating where the source region to be copied begins - * @param count the number of elements to copy - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _copyInstance( - final S source, - final long sourceOffset, - final long count) { - return _copyInstance(noLookup, source, sourceOffset, count); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - * - * @param lookup The lookup object to use when resolving constructors - * @param source The array to copy from - * @param sourceOffset offset index, indicating where the source region to be copied begins - * @param count the number of elements to copy - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - static , T> S _copyInstance( - MethodHandles.Lookup lookup, - final S source, - final long sourceOffset, - final long count) { - return _copyInstance(lookup, source, new long[]{sourceOffset}, new long[]{count}); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - *

- * This form is useful [only] for copying partial ranges from nested StructuredArrays. - *

- * @param source The array to copy from - * @param sourceOffsets offset indexes, indicating where the source region to be copied begins at each - * StructuredArray nesting depth - * @param counts the number of elements to copy at each StructuredArray nesting depth - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - @SuppressWarnings("unchecked") - static , T> S _copyInstance( - final S source, - final long[] sourceOffsets, - final long[] counts) { - return _copyInstance(noLookup, source, sourceOffsets, counts); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - *

- * This form is useful [only] for copying partial ranges from nested StructuredArrays. - *

- * @param lookup The lookup object to use when resolving constructors - * @param source The array to copy from - * @param sourceOffsets offset indexes, indicating where the source region to be copied begins at each - * StructuredArray nesting depth - * @param counts the number of elements to copy at each StructuredArray nesting depth - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - @SuppressWarnings("unchecked") - static , T> S _copyInstance( - MethodHandles.Lookup lookup, - final S source, - final long[] sourceOffsets, - final long[] counts) { - if (sourceOffsets.length != counts.length) { - throw new IllegalArgumentException("sourceOffsets.length must match counts.length"); - } - - // Verify source ranges fit in model: - int depth = 0; - StructuredArrayModel arrayModel = source.getArrayModel(); - while((depth < counts.length) && (arrayModel != null) && StructuredArrayModel.class.isInstance(arrayModel)) { - if (arrayModel.getLength() < sourceOffsets[depth] + counts[depth]) { - throw new ArrayIndexOutOfBoundsException( - "At nesting depth " + depth + ", source length (" + arrayModel.getLength() + - ") is smaller than sourceOffset (" + sourceOffsets[depth] + - ") + count (" + counts[depth] + ")" ); - } - arrayModel = (StructuredArrayModel) arrayModel.getStructuredSubArrayModel(); - depth++; - } - - // If we run out of model depth before we run out of sourceOffsets and counts, throw: - if (depth < counts.length) { - throw new IllegalArgumentException("sourceOffsets.length and counts.length (" + counts.length + - ") must not exceed StructuredArray nesting depth (" + depth + ")"); - } - - final StructuredArrayModel sourceArrayModel = (StructuredArrayModel) source.getArrayModel(); - final Class sourceArrayClass = sourceArrayModel.getArrayClass(); - CtorAndArgs arrayCtorAndArgs = - new CtorAndArgs<>(lookup, sourceArrayClass, new Class[] {sourceArrayClass}, source); - - final AbstractStructuredArrayBuilder arrayBuilder = - createCopyingArrayBuilder(lookup, sourceArrayModel, sourceOffsets, 0, counts, 0). - arrayCtorAndArgs(arrayCtorAndArgs). - contextCookie(source); - - return instantiate(arrayBuilder); - } - - private static , T> AbstractStructuredArrayBuilder createCopyingArrayBuilder( - MethodHandles.Lookup lookup, - final StructuredArrayModel sourceArrayModel, - final long[] sourceOffsets, final int offsetsIndex, - final long[] counts, final int countsIndex) { - final Class sourceArrayClass = sourceArrayModel.getArrayClass(); - final Class elementClass = sourceArrayModel.getElementClass(); - - long sourceOffset = (offsetsIndex < sourceOffsets.length) ? sourceOffsets[offsetsIndex] : 0; - long count = (countsIndex < counts.length) ? counts[countsIndex] : sourceArrayModel.getLength(); - - final CtorAndArgsProvider elementCopyCtorAndArgsProvider = - new CopyCtorAndArgsProvider<>(lookup, elementClass, sourceOffset); - - if (sourceArrayModel.getStructuredSubArrayModel() != null) { - // This array contains another array: - AbstractStructuredArrayBuilder subArrayBuilder = - createCopyingArrayBuilder(lookup, - (StructuredArrayModel)sourceArrayModel.getStructuredSubArrayModel(), - sourceOffsets, offsetsIndex + 1, - counts, countsIndex + 1); - @SuppressWarnings("unchecked") - AbstractStructuredArrayBuilder builder = - new AbstractStructuredArrayBuilder<>(lookup, sourceArrayClass, subArrayBuilder, count). - elementCtorAndArgsProvider(elementCopyCtorAndArgsProvider). - resolve(); - return builder; - } else if (sourceArrayModel.getPrimitiveSubArrayModel() != null) { - // This array contains elements that are PrimitiveArrays: - PrimitiveArrayModel model = (PrimitiveArrayModel) sourceArrayModel.getPrimitiveSubArrayModel(); - @SuppressWarnings("unchecked") - PrimitiveArrayBuilder subArrayBuilder = - new PrimitiveArrayBuilder(model.getArrayClass(), model.getLength()); - @SuppressWarnings("unchecked") - AbstractStructuredArrayBuilder builder = - new AbstractStructuredArrayBuilder<>(lookup, sourceArrayClass, subArrayBuilder, count). - elementCtorAndArgsProvider(elementCopyCtorAndArgsProvider). - resolve(); - return builder; - - } else { - // This is a leaf array (it's elements are regular objects): - return new AbstractStructuredArrayBuilder<>(lookup, sourceArrayClass, elementClass, count). - elementCtorAndArgsProvider(elementCopyCtorAndArgsProvider). - resolve(); - } - } - - private static AbstractStructuredArray instantiate( - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - @SuppressWarnings("unchecked") - AbstractStructuredArrayBuilder, T> arrayBuilder = - new AbstractStructuredArrayBuilder(AbstractStructuredArray.class, elementClass, length). - elementCtorAndArgsProvider(ctorAndArgsProvider).resolve(); - return instantiate(arrayBuilder); - } - - private static , T> S instantiate( - final CtorAndArgs arrayCtorAndArgs, - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - @SuppressWarnings("unchecked") - AbstractStructuredArrayBuilder arrayBuilder = - new AbstractStructuredArrayBuilder(arrayCtorAndArgs.getConstructor().getDeclaringClass(), elementClass, length). - arrayCtorAndArgs(arrayCtorAndArgs). - elementCtorAndArgsProvider(ctorAndArgsProvider). - resolve(); - return instantiate(arrayBuilder); - } - - private static , T> S instantiate( - final AbstractStructuredArrayBuilder arrayBuilder) { - ConstructionContext context = new ConstructionContext<>(arrayBuilder.getContextCookie()); - ConstructorMagic constructorMagic = getConstructorMagic(); - constructorMagic.setConstructionArgs(arrayBuilder, context); - try { - arrayBuilder.resolve(); - constructorMagic.setActive(true); - StructuredArrayModel arrayModel = arrayBuilder.getArrayModel(); - Constructor constructor = arrayBuilder.getArrayCtorAndArgs().getConstructor(); - Object[] args = arrayBuilder.getArrayCtorAndArgs().getArgs(); - return AbstractStructuredArrayBase.instantiateStructuredArray(arrayModel, constructor, args); - } finally { - constructorMagic.setActive(false); - } - } - - protected AbstractStructuredArray() { - checkConstructorMagic(); - // Extract locally needed args from constructor magic: - ConstructorMagic constructorMagic = getConstructorMagic(); - @SuppressWarnings("unchecked") - final ConstructionContext context = constructorMagic.getContext(); - @SuppressWarnings("unchecked") - final AbstractStructuredArrayBuilder, T> arrayBuilder = constructorMagic.getArrayBuilder(); - final CtorAndArgsProvider ctorAndArgsProvider = arrayBuilder.getElementCtorAndArgsProvider(); - - // Finish consuming constructMagic arguments: - constructorMagic.setActive(false); - - context.setArray(this); - this.arrayModel = arrayBuilder.getArrayModel(); - - final Field[] fields = removeStaticFields(getElementClass().getDeclaredFields()); - for (final Field field : fields) { - field.setAccessible(true); - } - this.fields = fields; - this.hasFinalFields = containsFinalQualifiedFields(fields); - - AbstractStructuredArrayBuilder structuredSubArrayBuilder = arrayBuilder.getStructuredSubArrayBuilder(); - PrimitiveArrayBuilder primitiveSubArrayBuilder = arrayBuilder.getPrimitiveSubArrayBuilder(); - - if (structuredSubArrayBuilder != null) { - populateStructuredSubArrays(ctorAndArgsProvider, structuredSubArrayBuilder, context); - } else if (primitiveSubArrayBuilder != null) { - populatePrimitiveSubArrays(ctorAndArgsProvider, primitiveSubArrayBuilder, context); - } else { - // This is a single dimension array. Populate it: - populateLeafElements(ctorAndArgsProvider, context); - } - } - - protected AbstractStructuredArray(AbstractStructuredArray sourceArray) { - // Support copy constructor. When we get here, everything is already set up for the regular - // (default) construction path to perform the required copy. - // Copying will actually be done according to the CtorAndArgsProvider and context already supplied, - // with top-most source array being (already) passed as the contextCookie in the builder's - // construction context, and copying proceeding using the context indices and the supplied - // contextCookie provided by each CtorAndArgsProvider to figure out individual sources. - this(); - } - - /** - * Get the length (number of elements) of the array. - * - * @return the number of elements in the array. - */ - long getLength() { - return super.getLength(); - } - - - /** - * Get the {@link Class} of elements stored in the array. - * - * @return the {@link Class} of elements stored in the array. - */ - Class getElementClass() { - return super.getElementClass(); - } - - /** - * Get the array model - * @return a model of this array - */ - StructuredArrayModel, T> getArrayModel() { - return arrayModel; - } - - /** - * Get a reference to an element in a single dimensional array, using a long index. - * - * @param index of the element to retrieve. - * @return a reference to the indexed element. - */ - T get(final long index) throws IllegalArgumentException { - return super.get(index); - } - - /** - * Get a reference to an element in a single dimensional array, using an int index. - * - * @param index of the element to retrieve. - * @return a reference to the indexed element. - */ - T get(final int index) throws IllegalArgumentException { - return super.get(index); - } - - // - // - // Populating array elements: - // - // - - private void populateLeafElement(final long index, - CtorAndArgs ctorAndArgs) { - // Instantiate: - constructElementAtIndex(index, ctorAndArgs.getConstructor(), ctorAndArgs.getArgs()); - } - - private void populatePrimitiveSubArray(final long index, - PrimitiveArrayBuilder subArrayBuilder, - final CtorAndArgs subArrayCtorAndArgs) { - // Instantiate: - constructPrimitiveSubArrayAtIndex( - index, - subArrayBuilder.getArrayModel(), - subArrayCtorAndArgs.getConstructor(), - subArrayCtorAndArgs.getArgs()); - } - - private void populateStructuredSubArray(final ConstructionContext context, - AbstractStructuredArrayBuilder subArrayBuilder, - final CtorAndArgs subArrayCtorAndArgs) { - ConstructionContext subArrayContext = new ConstructionContext<>(subArrayCtorAndArgs.getContextCookie()); - subArrayContext.setContainingContext(context); - ConstructorMagic constructorMagic = getConstructorMagic(); - constructorMagic.setConstructionArgs(subArrayBuilder, subArrayContext); - try { - constructorMagic.setActive(true); - // Instantiate: - constructSubArrayAtIndex( - context.getIndex(), - subArrayBuilder.getArrayModel(), - subArrayCtorAndArgs.getConstructor(), - subArrayCtorAndArgs.getArgs()); - } finally { - constructorMagic.setActive(false); - } - } - - private void populateLeafElements(final CtorAndArgsProvider ctorAndArgsProvider, - final ConstructionContext context) { - long length = getLength(); - - try { - for (long index = 0; index < length; index++) { - final CtorAndArgs ctorAndArgs; - - context.setIndex(index); - ctorAndArgs = ctorAndArgsProvider.getForContext(context); - - if (ctorAndArgs.getConstructor().getDeclaringClass() != getElementClass()) { - throw new IllegalArgumentException("ElementClass (" + getElementClass() + - ") does not match ctorAndArgs.getConstructor().getDeclaringClass() (" + - ctorAndArgs.getConstructor().getDeclaringClass() + ")"); - } - - populateLeafElement(index, ctorAndArgs); - } - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } - - private void populatePrimitiveSubArrays(final CtorAndArgsProvider subArrayCtorAndArgsProvider, - final PrimitiveArrayBuilder subArrayBuilder, - final ConstructionContext context) { - long length = getLength(); - - try { - for (long index = 0; index < length; index++) { - final CtorAndArgs ctorAndArgs; - - context.setIndex(index); - ctorAndArgs = subArrayCtorAndArgsProvider.getForContext(context); - - if (ctorAndArgs.getConstructor().getDeclaringClass() != getElementClass()) { - throw new IllegalArgumentException("ElementClass (" + getElementClass() + - ") does not match ctorAndArgs.getConstructor().getDeclaringClass() (" + - ctorAndArgs.getConstructor().getDeclaringClass() + ")"); - } - - populatePrimitiveSubArray(index, subArrayBuilder, ctorAndArgs); - } - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } - - private void populateStructuredSubArrays(final CtorAndArgsProvider subArrayCtorAndArgsProvider, - final AbstractStructuredArrayBuilder subArrayBuilder, - final ConstructionContext context) { - long length = getLength(); - - try { - for (long index = 0; index < length; index++) { - final CtorAndArgs ctorAndArgs; - - context.setIndex(index); - ctorAndArgs = subArrayCtorAndArgsProvider.getForContext(context); - - if (ctorAndArgs.getConstructor().getDeclaringClass() != getElementClass()) { - throw new IllegalArgumentException("ElementClass (" + getElementClass() + - ") does not match ctorAndArgs.getConstructor().getDeclaringClass() (" + - ctorAndArgs.getConstructor().getDeclaringClass() + ")"); - } - - populateStructuredSubArray(context, subArrayBuilder, ctorAndArgs); - } - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } - - /** - * create a fresh StructuredArray intended to occupy a a given intrinsic field in the containing object, - * at the field described by the supplied intrinsicObjectModel, using the supplied constructor and arguments. - */ - static > A constructStructuredArrayWithin( - final Object containingObject, - final AbstractIntrinsicObjectModel
intrinsicObjectModel, - AbstractStructuredArrayBuilder arrayBuilder) - throws InstantiationException, IllegalAccessException, InvocationTargetException { - ConstructionContext context = new ConstructionContext(arrayBuilder.getContextCookie()); - ConstructorMagic constructorMagic = getConstructorMagic(); - constructorMagic.setConstructionArgs(arrayBuilder, context); - try { - constructorMagic.setActive(true); - return AbstractStructuredArray.constructStructuredArrayWithin( - containingObject, - intrinsicObjectModel, - arrayBuilder.getArrayModel(), - arrayBuilder.getArrayCtorAndArgs().getConstructor(), - arrayBuilder.getArrayCtorAndArgs().getArgs()); - } finally { - constructorMagic.setActive(false); - } - } - - // - // - // Shallow copy support: - // - // - - private static Field[] removeStaticFields(final Field[] declaredFields) { - int staticFieldCount = 0; - for (final Field field : declaredFields) { - if (isStatic(field.getModifiers())) { - staticFieldCount++; - } - } - - final Field[] instanceFields = new Field[declaredFields.length - staticFieldCount]; - int i = 0; - for (final Field field : declaredFields) { - if (!isStatic(field.getModifiers())) { - instanceFields[i++] = field; - } - } - - return instanceFields; - } - - private boolean containsFinalQualifiedFields(final Field[] fields) { - for (final Field field : fields) { - if (isFinal(field.getModifiers())) { - return true; - } - } - - return false; - } - - private static void shallowCopy(final Object src, final Object dst, final Field[] fields) { - try { - for (final Field field : fields) { - field.set(dst, field.get(src)); - } - } catch (final IllegalAccessException shouldNotHappen) { - throw new RuntimeException(shouldNotHappen); - } - } - - private static void reverseShallowCopy(final Object src, final Object dst, final Field[] fields) { - try { - for (int i = fields.length - 1; i >= 0; i--) { - final Field field = fields[i]; - field.set(dst, field.get(src)); - } - } catch (final IllegalAccessException shouldNotHappen) { - throw new RuntimeException(shouldNotHappen); - } - } - - /** - * Shallow copy a region of element object contents from one array to the other. - *

- * shallowCopy will copy all fields from each of the source elements to the corresponding fields in each - * of the corresponding destination elements. If the same array is both the src and dst then the copy will - * happen as if a temporary intermediate array was used. - * - * @param src array to copy - * @param srcOffset offset index in src where the region begins - * @param dst array into which the copy should occur - * @param dstOffset offset index in the dst where the region begins - * @param count of structure elements to copy - * @param The class of the arrays - * @param The class of the array elements - * @throws IllegalArgumentException if the source and destination array element types are not identical, or if - * the source or destination arrays have nested StructuredArrays within them, or if final fields are discovered - * and all allowFinalFieldOverwrite is not true. - */ - static , T> void _shallowCopy( - final S src, - final long srcOffset, - final S dst, - final long dstOffset, - final long count) { - _shallowCopy(src, srcOffset, dst, dstOffset, count, false); - } - - /** - * Shallow copy a region of element object contents from one array to the other. - *

- * shallowCopy will copy all fields from each of the source elements to the corresponding fields in each - * of the corresponding destination elements. If the same array is both the src and dst then the copy will - * happen as if a temporary intermediate array was used. - * - * If allowFinalFieldOverwrite is specified as true, even final fields will be copied. - * - * @param src array to copy - * @param srcOffset offset index in src where the region begins - * @param dst array into which the copy should occur - * @param dstOffset offset index in the dst where the region begins - * @param count of structure elements to copy. - * @param allowFinalFieldOverwrite allow final fields to be overwritten during a copy operation. - * @param The class of the arrays - * @param The class of the array elements - * @throws IllegalArgumentException if the source and destination array element types are not identical, or if - * the source or destination arrays have nested StructuredArrays within them, or if final fields are discovered - * and all allowFinalFieldOverwrite is not true. - */ - static , T> void _shallowCopy( - final S src, - final long srcOffset, - final S dst, - final long dstOffset, - final long count, - final boolean allowFinalFieldOverwrite) { - if (src.getElementClass() != dst.getElementClass()) { - String msg = String.format("Only objects of the same class can be copied: %s != %s", - src.getClass(), dst.getClass()); - throw new IllegalArgumentException(msg); - } - - if ((AbstractStructuredArray.class.isAssignableFrom(src.getElementClass()) || - (AbstractStructuredArray.class.isAssignableFrom(dst.getElementClass())))) { - throw new IllegalArgumentException("shallowCopy only supported for single dimension arrays (with no nested StructuredArrays)"); - } - - final Field[] fields = src.fields; - if (!allowFinalFieldOverwrite && dst.hasFinalFields) { - throw new IllegalArgumentException("Cannot shallow copy onto final fields"); - } - - if (((srcOffset + count) < Integer.MAX_VALUE) && ((dstOffset + count) < Integer.MAX_VALUE)) { - // use the (faster) int based get - if (dst == src && (dstOffset >= srcOffset && (dstOffset + count) >= srcOffset)) { - int srcIdx = (int)(srcOffset + count) - 1; - int dstIdx = (int)(dstOffset + count) - 1; - int limit = (int)(srcOffset - 1); - for (; srcIdx > limit; srcIdx--, dstIdx--) { - reverseShallowCopy(src.get(srcIdx), dst.get(dstIdx), fields); - } - } else { - for (int srcIdx = (int)srcOffset, dstIdx = (int)dstOffset, limit = (int)(srcOffset + count); - srcIdx < limit; srcIdx++, dstIdx++) { - shallowCopy(src.get(srcIdx), dst.get(dstIdx), fields); - } - } - } else { - // use the (slower) long based getL - if (dst == src && (dstOffset >= srcOffset && (dstOffset + count) >= srcOffset)) { - for (long srcIdx = srcOffset + count, dstIdx = dstOffset + count, limit = srcOffset - 1; - srcIdx > limit; srcIdx--, dstIdx--) { - reverseShallowCopy(src.get(srcIdx), dst.get(dstIdx), fields); - } - } else { - for (long srcIdx = srcOffset, dstIdx = dstOffset, limit = srcOffset + count; - srcIdx < limit; srcIdx++, dstIdx++) { - shallowCopy(src.get(srcIdx), dst.get(dstIdx), fields); - } - } - } - } - - // - // - // ConstructorMagic support: - // - // - - private static class ConstructorMagic { - private boolean isActive() { - return active; - } - - private void setActive(boolean active) { - this.active = active; - } - - private void setConstructionArgs(final AbstractStructuredArrayBuilder arrayBuilder, final ConstructionContext context) { - this.arrayBuilder = arrayBuilder; - this.context = context; - } - - private AbstractStructuredArrayBuilder getArrayBuilder() { - return arrayBuilder; - } - - private ConstructionContext getContext() { - return context; - } - - private boolean active = false; - - private AbstractStructuredArrayBuilder arrayBuilder; - private ConstructionContext context; - } - - private static final ThreadLocal threadLocalConstructorMagic = - new ThreadLocal() { - @Override protected ConstructorMagic initialValue() { - return new ConstructorMagic(); - } - }; - - private static ConstructorMagic getConstructorMagic() { - return threadLocalConstructorMagic.get(); - } - - private static void checkConstructorMagic() { - if (!getConstructorMagic().isActive()) { - throw new IllegalArgumentException( - "StructuredArray<> must not be directly instantiated with a constructor." + - " Use newInstance(...) or a builder instead."); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArrayBase.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArrayBase.java deleted file mode 100644 index 1d9e50c..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArrayBase.java +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -/** - * This class contains the intrinsifiable portions of StructuredArray behavior. JDK implementations - * that choose to intrinsify StructuredArray are expected to replace the implementation of this - * base class. - * - * @param the element type in the array - */ -abstract class AbstractStructuredArrayBase { - - // - // - // Constructor: - // - // - - /** - * Optimization NOTE: Optimized JDK implementations may choose to replace the logic of this - * constructor, along with the way some of the internal fields are represented (see note - * in "Internal fields" section farther below. - */ - - AbstractStructuredArrayBase() { - checkConstructorMagic(); - ConstructorMagic constructorMagic = getConstructorMagic(); - - @SuppressWarnings("unchecked") - final AbstractStructuredArrayModel, T> arrayModel = - constructorMagic.getArrayModel(); - final Class elementClass = arrayModel._getElementClass(); - final long length = arrayModel._getLength(); - - // Finish consuming constructMagic arguments: - constructorMagic.setActive(false); - - if (length < 0) { - throw new IllegalArgumentException("length cannot be negative"); - } - - this.length = length; - this.elementClass = elementClass; - - allocateInternalStorage(length); - } - - /** - * Instantiate a StructuredArray of arrayClass with the given array model, and the supplied - * array constructor and arguments. - * - * OPTIMIZATION NOTE: Optimized JDK implementations may replace this implementation with one that - * allocates room for the entire StructuredArray and all it's elements. - */ - static , T> S instantiateStructuredArray( - AbstractStructuredArrayModel arrayModel, Constructor arrayConstructor, Object... args) { - - // For implementations that need the array class and the element class, - // this is how - // how to get them: - // - // Class> arrayClass = - // arrayConstructor.getDeclaringClass(); - // Class elementClass = arrayModel.getElementClass(); - - ConstructorMagic constructorMagic = getConstructorMagic(); - constructorMagic.setConstructionArgs(arrayModel); - - try { - constructorMagic.setActive(true); - return arrayConstructor.newInstance(args); - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex); - } finally { - constructorMagic.setActive(false); - } - } - - /** - * Construct a fresh element intended to occupy a given index in the given array, using the - * supplied constructor and arguments. - * - * OPTIMIZATION NOTE: Optimized JDK implementations may replace this implementation with a - * construction-in-place call on a previously allocated memory location associated with the given index. - */ - void constructElementAtIndex( - final long index, - final Constructor constructor, - final Object... args) { - try { - T element = constructor.newInstance(args); - storeElementInLocalStorageAtIndex(element, index); - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex); - } - } - - /** - * Construct a fresh primitive sub-array intended to occupy a given index in the given array, using the - * supplied constructor and arguments. - * - * OPTIMIZATION NOTE: Optimized JDK implementations may replace this implementation with a - * construction-in-place call on a previously allocated memory location associated with the given index. - */ - void constructPrimitiveSubArrayAtIndex( - final long index, - AbstractPrimitiveArrayModel primitiveSubArrayModel, - final Constructor constructor, - final Object... args) { - int length = (int) primitiveSubArrayModel._getLength(); - @SuppressWarnings("unchecked") - Constructor c = (Constructor) constructor; - @SuppressWarnings("unchecked") - T element = (T) AbstractPrimitiveArray._newInstance(length, c, args); - storeElementInLocalStorageAtIndex(element, index); - } - - /** - * Construct a fresh sub-array intended to occupy a given index in the given array, using the - * supplied constructor. - * - * OPTIMIZATION NOTE: Optimized JDK implementations may replace this implementation with a - * construction-in-place call on a previously allocated memory location associated with the given index. - */ - void constructSubArrayAtIndex( - long index, - AbstractStructuredArrayModel subArrayModel, - final Constructor subArrayConstructor, - final Object... args) { - ConstructorMagic constructorMagic = getConstructorMagic(); - constructorMagic.setConstructionArgs(subArrayModel); - try { - constructorMagic.setActive(true); - T subArray = subArrayConstructor.newInstance(args); - storeElementInLocalStorageAtIndex(subArray, index); - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex); - } finally { - constructorMagic.setActive(false); - } - } - - /** - * Construct a fresh StructuredArray intended to occupy a a given intrinsic field in the containing object, - * at the field described by the supplied intrinsicObjectModel, using the supplied constructor and arguments. - * - * OPTIMIZATION NOTE: Optimized JDK implementations may replace this implementation with a - * construction-in-place call on a previously allocated memory location associated with the given index. - */ - static T constructStructuredArrayWithin( - final Object containingObject, - final AbstractIntrinsicObjectModel intrinsicObjectModel, - AbstractStructuredArrayModel subArrayModel, - final Constructor subArrayConstructor, - final Object... args) { - ConstructorMagic constructorMagic = getConstructorMagic(); - constructorMagic.setConstructionArgs(subArrayModel); - try { - constructorMagic.setActive(true); - T array = subArrayConstructor.newInstance(args); - intrinsicObjectModel.directlyInitializeTargetField(containingObject, array); - return array; - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex); - } finally { - constructorMagic.setActive(false); - } - } - - /** - * Get an element at a supplied [index] in a StructuredArray - * - * OPTIMIZATION NOTE: Optimized JDK implementations may replace this implementation with a - * faster access form (e.g. they may be able to derive the element reference directly from the - * structuredArray reference without requiring a de-reference). - * - * @param index of the element to retrieve. - * @return a reference to the indexed element. - * */ - T get(final int index) { - return intAddressableElements[index]; - } - - /** - * Get an element at a supplied [index] in a StructuredArray - * - * OPTIMIZATION NOTE: Optimized JDK implementations may replace this implementation with a - * faster access form (e.g. they may be able to derive the element reference directly from the - * structuredArray reference without requiring a de-reference). - * - * @param index of the element to retrieve. - * @return a reference to the indexed element. - */ - T get(final long index) { - if (index < Integer.MAX_VALUE) { - return get((int) index); - } - - // Calculate index into long-addressable-only partitions: - final long longIndex = (index - Integer.MAX_VALUE); - final int partitionIndex = (int)(longIndex >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int)longIndex & PARTITION_MASK; - - return longAddressableElements[partitionIndex][partitionOffset]; - } - - // - // - // Accessor methods for instance state: - // - // - - Class getElementClass() { - return elementClass; - } - - long getLength() { - return length; - } - - // - // - // Internal fields: - // - // - - /** - * OPTIMIZATION NOTE: Optimized JDK implementations may choose to hide these fields in non-Java-accessible - * internal instance fields (much like array.length is hidden), in order to ensure that no uncontrolled - * modification of the fields can be made by any Java program (not even via reflection getting at private - * fields and bypassing their finality). This is an important security concern because optimization - * may need to make strong assumptions about the true finality of some of these fields. - */ - - private final Class elementClass; - - private final long length; - - // - // - // Internal Storage support: - // - // - - /** - * OPTIMIZATION NOTE: Optimized JDK implementations may choose to replace this vanilla-Java internal - * storage representation with one that is more intrinsically understood by the JDK and JVM. - */ - - static final int MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT = 30; - static final int MAX_EXTRA_PARTITION_SIZE = 1 << MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT; - static final int PARTITION_MASK = MAX_EXTRA_PARTITION_SIZE - 1; - - private T[][] longAddressableElements; // Used to store elements at indexes above Integer.MAX_VALUE - private T[] intAddressableElements; - - - @SuppressWarnings("unchecked") - private void allocateInternalStorage(final long length) { - // Allocate internal storage: - - // Size int-addressable sub arrays: - final int intLength = (int) Math.min(length, Integer.MAX_VALUE); - // Size Subsequent partitions hold long-addressable-only sub arrays: - final long extraLength = length - intLength; - final int numFullPartitions = (int) (extraLength >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int lastPartitionSize = (int) extraLength & PARTITION_MASK; - - intAddressableElements = (T[]) new Object[intLength]; - longAddressableElements = (T[][]) new Object[numFullPartitions + 1][]; - // full long-addressable-only partitions: - for (int i = 0; i < numFullPartitions; i++) { - longAddressableElements[i] = (T[]) new Object[MAX_EXTRA_PARTITION_SIZE]; - } - // Last partition with leftover long-addressable-only size: - longAddressableElements[numFullPartitions] = (T[]) new Object[lastPartitionSize]; - } - - private void storeElementInLocalStorageAtIndex(T element, long index0) { - // place in proper internal storage location: - if (index0 < Integer.MAX_VALUE) { - intAddressableElements[(int) index0] = element; - return; - } - - // Calculate index into long-addressable-only partitions: - final long longIndex0 = (index0 - Integer.MAX_VALUE); - final int partitionIndex = (int) (longIndex0 >>> MAX_EXTRA_PARTITION_SIZE_POW2_EXPONENT); - final int partitionOffset = (int) longIndex0 & PARTITION_MASK; - - longAddressableElements[partitionIndex][partitionOffset] = element; - } - - // - // - // ConstructorMagic support: - // - // - - /** - * OPTIMIZATION NOTE: The ConstructorMagic will likely not need to be modified in any way even for - * optimized JDK implementations. It resides in this class for scoping reasons. - */ - - private static class ConstructorMagic { - private boolean isActive() { - return active; - } - - private void setActive(boolean active) { - this.active = active; - } - - private void setConstructionArgs(AbstractStructuredArrayModel arrayModel) { - this.arrayModel = arrayModel; - } - - private AbstractStructuredArrayModel getArrayModel() { - return arrayModel; - } - - private boolean active = false; - AbstractStructuredArrayModel arrayModel; - } - - private static final ThreadLocal threadLocalConstructorMagic = - new ThreadLocal() { - @Override protected ConstructorMagic initialValue() { - return new ConstructorMagic(); - } - }; - - private static ConstructorMagic getConstructorMagic() { - return threadLocalConstructorMagic.get(); - } - - private static void checkConstructorMagic() { - if (!getConstructorMagic().isActive()) { - throw new IllegalArgumentException( - "StructuredArray<> must not be directly instantiated with a constructor. Use newInstance(...) instead."); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArrayBuilder.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArrayBuilder.java deleted file mode 100644 index f58acb7..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArrayBuilder.java +++ /dev/null @@ -1,508 +0,0 @@ -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A builder used for instantiating a {@link StructuredArray}<T> - *

- * {@link AbstractStructuredArrayBuilder} follows the commonly used builder pattern, and is useful for - * capturing the instantiation parameters of {@link StructuredArray}s. - *

- *

- * {@link AbstractStructuredArrayBuilder}s can be created for "flat" and "nested" {@link StructuredArray} - * constructs, and can range from the simplest forms used when default constructors are employed, to forms that - * supply customized per-element construction arguments that can take construction context (such as index, - * containing array, and arbitrary data passed in a contextCookie) into account. - *

- * A simple example of using a {@link AbstractStructuredArrayBuilder} to instantiate a StructuredArray is: - *
- * StructuredArray<MyElementClass> array =
- *      new StructuredArrayBuilder(StructuredArray.class, MyElementClass.class, length).
- *          build();
- * 
- *

- * An example of passing specific (but identical) construction arguments to element constructors is: - *

- * Constructor<MyElementClass> constructor = MyElementClass.class.getConstructor(int.Class, int.Class);
- *
- * StructuredArray<MyElementClass> array =
- *      new StructuredArrayBuilder(
- *          StructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgs(constructor, initArg1, initArg2).
- *          build();
- * 
- * Some examples of providing per-element construction parameters that depend on construction context include: - *
- * Constructor<MyElementClass> constructor = MyElementClass.class.getConstructor(long.Class, long.Class);
- *
- * // Using a pre-constructed elementCtorAndArgsProvider:
- * StructuredArray<MyElementClass> array =
- *      new StructuredArrayBuilder(
- *          StructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgsProvider(myCtorAndArgsProvider).
- *          build();
- *
- * // Using a Lambda expression for elementCtorAndArgsProvider:
- * StructuredArray<MyElementClass> array2 =
- *      new StructuredArrayBuilder(
- *          StructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgsProvider(
- *              context -> new CtorAndArgs<MyElementClass>(
- *                  constructor, context.getIndex(), context.getIndex() * 2)
- *          ).
- *          build();
- *
- * // Using an anonymous class for elementCtorAndArgsProvider:
- * StructuredArray<MyElementClass> array3 =
- *      new StructuredArrayBuilder(
- *          StructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgsProvider(
- *              new CtorAndArgsProvider() {
- *                  {@literal @}Override
- *                  public CtorAndArgs getForContext(ConstructionContext context) throws NoSuchMethodException {
- *                      return new CtorAndArgs(constructor, context.getIndex(), context.getIndex() * 2);
- *                  }
- *              }
- *          ).
- *          build();
- * 
- * - * @param The class of the StructuredArray that is to be instantiated by the builder - * @param The class of the elements in the StructuredArray that is to be instantiated the builder - */ -class AbstractStructuredArrayBuilder, T> { - private static final Class[] EMPTY_ARG_TYPES = new Class[0]; - private static final Object[] EMPTY_ARGS = new Object[0]; - - private static final MethodHandles.Lookup noLookup = null; - - private MethodHandles.Lookup lookup = null; - - private CtorAndArgs arrayCtorAndArgs; - private final StructuredArrayModel arrayModel; - - private final AbstractStructuredArrayBuilder structuredSubArrayBuilder; - private final PrimitiveArrayBuilder primitiveSubArrayBuilder; - - private CtorAndArgsProvider elementCtorAndArgsProvider; - private Object contextCookie; - - /** - * Constructs a new {@link AbstractStructuredArrayBuilder} object for creating arrays of type S with - * elements of type T, and the given length. - * - * Note: This constructor form cannot be used with an element type T that extends StructuredArray. Use the - * constructor form {@link AbstractStructuredArrayBuilder#AbstractStructuredArrayBuilder(Class, AbstractStructuredArrayBuilder, long)} - * to create builders that instantiate nested StructuredArrays. - * - * @param arrayClass The class of the array to be built by this builder - * @param elementClass The class of elements in the array to be built by this builder - * @param length The length of the array to be build by this builder - */ - public AbstractStructuredArrayBuilder(final Class arrayClass, - final Class elementClass, - final long length) { - this(noLookup, arrayClass, elementClass, length); - } - - /** - * Constructs a new {@link AbstractStructuredArrayBuilder} object for creating arrays of type S with - * elements of type T, and the given length. - * - * Note: This constructor form cannot be used with an element type T that extends StructuredArray. Use the - * constructor form {@link AbstractStructuredArrayBuilder#AbstractStructuredArrayBuilder(Class, AbstractStructuredArrayBuilder, long)} - * to create builders that instantiate nested StructuredArrays. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayClass The class of the array to be built by this builder - * @param elementClass The class of elements in the array to be built by this builder - * @param length The length of the array to be build by this builder - */ - public AbstractStructuredArrayBuilder(MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final long length) { - if (AbstractStructuredArray.class.isAssignableFrom(elementClass) || - AbstractPrimitiveArray.class.isAssignableFrom(elementClass)) { - throw new IllegalArgumentException("Cannot use this constructor form for nested " + - "StructuredArrays or PrimitiveArrays. " + - "Use the StructuredArrayBuilder(arrayClass, subArrayBuilder, length) form instead."); - } - this.lookup = lookup; - this.arrayModel = new StructuredArrayModel(arrayClass, elementClass, length){}; - this.structuredSubArrayBuilder = null; - this.primitiveSubArrayBuilder = null; - } - - /** - * Constructs a new {@link AbstractStructuredArrayBuilder} object for creating arrays of the given array model. - * - * @param arrayModel The model of the array to be built by this builder - */ - public AbstractStructuredArrayBuilder(final StructuredArrayModel arrayModel) { - this(noLookup, arrayModel); - } - - /** - * Constructs a new {@link AbstractStructuredArrayBuilder} object for creating arrays of the given array model. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayModel The model of the array to be built by this builder - */ - public AbstractStructuredArrayBuilder(MethodHandles.Lookup lookup, - final StructuredArrayModel arrayModel) { - this.lookup = lookup; - this.arrayModel = arrayModel; - this.structuredSubArrayBuilder = null; - this.primitiveSubArrayBuilder = null; - } - - /** - * Constructs a new {@link AbstractStructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends StructuredArray, such that the - * arrays instantiated by this builder would include nested StructuredArrays. - * - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * StructuredArrays) - * @param length The length of the array to be build by this builder - * @param
The class or the subArray (should match T for the StructuredArrayBuilder) - * @param The element class in the subArray. - */ - public , E> AbstractStructuredArrayBuilder(final Class arrayClass, - final AbstractStructuredArrayBuilder subArrayBuilder, - final long length) { - this(noLookup, arrayClass, subArrayBuilder, length); - } - - /** - * Constructs a new {@link AbstractStructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends StructuredArray, such that the - * arrays instantiated by this builder would include nested StructuredArrays. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * StructuredArrays) - * @param length The length of the array to be build by this builder - * @param The class or the subArray (should match T for the StructuredArrayBuilder) - * @param The element class in the subArray. - */ - public , E> AbstractStructuredArrayBuilder( - MethodHandles.Lookup lookup, - final Class arrayClass, - final AbstractStructuredArrayBuilder subArrayBuilder, - final long length) { - this.lookup = lookup; - this.arrayModel = - new StructuredArrayModel<>( - arrayClass, - subArrayBuilder.getArrayModel(), - length - ); - this.structuredSubArrayBuilder = subArrayBuilder; - this.primitiveSubArrayBuilder = null; - } - - /** - * Constructs a new {@link AbstractStructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends AbstractPrimitiveArray, such that the - * arrays instantiated by this builder would include elements that are PrimitiveArrays. - * - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * subclassable PrimitiveArrays) - * @param length The length of the array to be build by this builder - * @param The class in the subArray (should match T for the StructuredArrayBuilder) - */ - public AbstractStructuredArrayBuilder(final Class arrayClass, - final PrimitiveArrayBuilder - subArrayBuilder, - final long length) { - this(noLookup, arrayClass, subArrayBuilder, length); - } - - /** - * Constructs a new {@link AbstractStructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends AbstractPrimitiveArray, such that the - * arrays instantiated by this builder would include elements that are PrimitiveArrays. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * subclassable PrimitiveArrays) - * @param length The length of the array to be build by this builder - * @param The class in the subArray (should match T for the StructuredArrayBuilder) - */ - public AbstractStructuredArrayBuilder( - MethodHandles.Lookup lookup, - final Class arrayClass, - final PrimitiveArrayBuilder subArrayBuilder, - final long length) { - this.lookup = lookup; - this.arrayModel = - new StructuredArrayModel<>( - arrayClass, - subArrayBuilder.getArrayModel(), - length - ); - this.structuredSubArrayBuilder = null; - this.primitiveSubArrayBuilder = subArrayBuilder; - } - - /** - * Set the {@link CtorAndArgsProvider} used for determining the constructor and construction - * arguments used for each element in the array. The provider may use the specific element's - * construction context in determining the construction parameters. - * - * Note: This method overlaps in purpose with the alternate methods for controlling element - * construction. Namely {@link AbstractStructuredArrayBuilder#elementCtorAndArgs(CtorAndArgs)} and - * {@link AbstractStructuredArrayBuilder#elementCtorAndArgs(Constructor, Object...)}. - * - * @param ctorAndArgsProvider The provider used for determining the constructor and construction - * arguments used for each element in instantiated arrays - * @return The builder - */ - public AbstractStructuredArrayBuilder elementCtorAndArgsProvider(final CtorAndArgsProvider ctorAndArgsProvider) { - this.elementCtorAndArgsProvider = ctorAndArgsProvider; - return this; - } - - /** - * Set the {@link CtorAndArgs} to be used for all elements in the array. All elements will be constructed with - * the same constructor and the same arguments. - * - * Note: This method overlaps in purpose with the alternate methods for controlling element - * construction. Namely {@link AbstractStructuredArrayBuilder#elementCtorAndArgsProvider(CtorAndArgsProvider)} and - * {@link AbstractStructuredArrayBuilder#elementCtorAndArgs(Constructor, Object...)}. - * - * @param ctorAndArgs The constructor and arguments used for all elements in arrays - * @return The builder - */ - public AbstractStructuredArrayBuilder elementCtorAndArgs(final CtorAndArgs ctorAndArgs) { - if ((structuredSubArrayBuilder != null) || (primitiveSubArrayBuilder != null)) { - throw new IllegalArgumentException( - "ctoAndArgs for constructing subArray elements should be supplied in subArrayBuilder"); - } - return elementCtorAndArgsProvider( - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext(ConstructionContext context) throws NoSuchMethodException { - return ctorAndArgs; - } - } - ); - } - - /** - * Set the {@link Constructor} and construction arguments to be used for all elements in the array. - * All elements will be constructed with the same constructor and the same arguments. - * - * Note: This method overlaps in purpose with the alternate methods for controlling element - * construction. Namely {@link AbstractStructuredArrayBuilder#elementCtorAndArgsProvider(CtorAndArgsProvider)} and - * {@link AbstractStructuredArrayBuilder#elementCtorAndArgs(CtorAndArgs)}. - * - * @param constructor The constructor used for all elements in arrays - * @param args The construction arguments supplied for the constructor, used for all elements in the array - * @return The builder - */ - public AbstractStructuredArrayBuilder elementCtorAndArgs(final Constructor constructor, final Object... args) { - return elementCtorAndArgs(new CtorAndArgs<>(constructor, args)); - } - - /** - * Set the {@link CtorAndArgs} to be used in constructing arrays. - * Setting the means for array construction is Required if the array class (S) does not support a - * default constructor, or if a non-default construction of the array instance is needed. - * - * @param arrayCtorAndArgs The constructor and arguments used for constructing arrays - * @return The builder - */ - public AbstractStructuredArrayBuilder arrayCtorAndArgs(final CtorAndArgs arrayCtorAndArgs) { - this.arrayCtorAndArgs = arrayCtorAndArgs; - return this; - } - - /** - * Set the {@link Constructor} and construction arguments to be used in constructing arrays. - * Setting the means for array construction is Required if the array class (S) does not support a - * default constructor, or if a non-default construction of the array instance is needed. - * - * @param constructor The constructor used for constructing arrays - * @param args The construction arguments supplied for the constructor - * @return The builder - */ - public AbstractStructuredArrayBuilder arrayCtorAndArgs(final Constructor constructor, final Object... args) { - this.arrayCtorAndArgs = new CtorAndArgs<>(constructor, args); - return this; - } - - /** - * Set the (opaque) contextCookie object associated with this builder. This contextCookie object will be - * set in {@link ConstructionContext} object passed to the element - * {@link CtorAndArgsProvider} provider for each element in instantiated arrays. - * - * @param contextCookie the contextCookie object - * @return The builder - */ - public AbstractStructuredArrayBuilder contextCookie(final Object contextCookie) { - this.contextCookie = contextCookie; - return this; - } - - private void resolve(boolean resolveArrayCtorAndArgs) { - if ((arrayCtorAndArgs == null) && resolveArrayCtorAndArgs) { - this.arrayCtorAndArgs = - new CtorAndArgs<>(lookup, arrayModel.getArrayClass(), EMPTY_ARG_TYPES, EMPTY_ARGS); - } - - if (elementCtorAndArgsProvider == null) { - if ((structuredSubArrayBuilder != null) && - (structuredSubArrayBuilder.arrayCtorAndArgs != null)) { - // Use the CtorAndArgs provided for subArray elements: - @SuppressWarnings("unchecked") - CtorAndArgsProvider subArrayCtorAndArgsProvider = - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return structuredSubArrayBuilder.arrayCtorAndArgs; - } - }; - elementCtorAndArgsProvider = subArrayCtorAndArgsProvider; - } else if ((primitiveSubArrayBuilder != null) && - (primitiveSubArrayBuilder.getArrayCtorAndArgs() != null)) { - // Use the CtorAndArgs provided for subArray elements: - @SuppressWarnings("unchecked") - CtorAndArgsProvider subArrayCtorAndArgsProvider = - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return primitiveSubArrayBuilder.getArrayCtorAndArgs(); - } - }; - elementCtorAndArgsProvider = subArrayCtorAndArgsProvider; - } else { - // Use the default constructor: - final CtorAndArgs constantCtorAndArgs = new CtorAndArgs<>(lookup, arrayModel.getElementClass()); - elementCtorAndArgsProvider = - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return constantCtorAndArgs; - } - }; - } - } - - if (structuredSubArrayBuilder != null) { - // recurse through subArray builders and resolve them too: - structuredSubArrayBuilder.resolve(false); - } - } - - /** - * Resolve any not-yet-resolved constructor information needed by this builder. Calling resolve() is not - * necessary ahead of building, but it is useful for ensuring resolution works ahead of actual building - * attempts. - * - * @return This builder - * @throws IllegalArgumentException if the array constructor or element constructor fail to resolve given - * the current information in the builder - */ - public AbstractStructuredArrayBuilder resolve() { - resolve(true); - return this; - } - - /** - * Build a {@link StructuredArray} according to the information captured in this builder - * @return A newly instantiated {@link StructuredArray} - * - * @throws IllegalArgumentException if the array constructor or element constructor fail to resolve given - * the current information in the builder - */ - public S build() throws IllegalArgumentException { - resolve(); - return AbstractStructuredArray._newInstance(this); - } - - /** - * Get the {@link StructuredArrayModel} that describes the arrays built by this builder - * - * @return The {@link StructuredArrayModel} that describes the arrays built by this builder - */ - public StructuredArrayModel getArrayModel() { - return arrayModel; - } - - /** - * Get the {@link AbstractStructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null - * - * @return The {@link AbstractStructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null if the array element type T does not extend {@link StructuredArray}. - */ - public AbstractStructuredArrayBuilder getStructuredSubArrayBuilder() { - return structuredSubArrayBuilder; - } - - /** - * Get the {@link AbstractStructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null - * - * @return The {@link AbstractStructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null if the array element type T does not extend {@link StructuredArray}. - */ - public PrimitiveArrayBuilder getPrimitiveSubArrayBuilder() { - return primitiveSubArrayBuilder; - } - - /** - * Get the {@link CtorAndArgs} describing the constructor and arguments used to instantiate arrays with - * this builder. May be null if non of {@link AbstractStructuredArrayBuilder#arrayCtorAndArgs}, - * {@link AbstractStructuredArrayBuilder#resolve()} or - * {@link AbstractStructuredArrayBuilder#build()} have been called yet. - * @return The {@link CtorAndArgs} describing the constructor and arguments used to instantiate arrays with - * this builder. - */ - public CtorAndArgs getArrayCtorAndArgs() { - return arrayCtorAndArgs; - } - - /** - * Get the {@link CtorAndArgsProvider} which provides the constructor and arguments used to construct - * individual elements of arrays instantiated with this builder. May be null if non of - * {@link AbstractStructuredArrayBuilder#elementCtorAndArgsProvider}, - * {@link AbstractStructuredArrayBuilder#elementCtorAndArgs}, - * {@link AbstractStructuredArrayBuilder#resolve} or - * {@link AbstractStructuredArrayBuilder#build} have been called yet. - * @return The {@link CtorAndArgsProvider} which provides the constructor and arguments used to construct - * individual elements of arrays instantiated with this builder - */ - public CtorAndArgsProvider getElementCtorAndArgsProvider() { - return elementCtorAndArgsProvider; - } - - /** - * Get the (opaque) contextCookie object associated with this builder. This contextCookie object will be - * set in {@link ConstructionContext} object passed to the element - * {@link CtorAndArgsProvider} provider for each element in instantiated arrays. - * @return The (opaque) contextCookie object associated with this builder - */ - public Object getContextCookie() { - return contextCookie; - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArrayModel.java b/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArrayModel.java deleted file mode 100644 index bf46dcd..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/AbstractStructuredArrayModel.java +++ /dev/null @@ -1,138 +0,0 @@ -package org.ObjectLayout; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; - -/** - * A model that describes the structure of a AbstractStructuredArray - * - * @param The class of the AbstractStructuredArray modeled by the model - * @param The class of the elements in the StructuredArray modeled by the model - */ -abstract class AbstractStructuredArrayModel, T> { - private final Class arrayClass; - private final long length; - private final StructuredArrayModel structuredSubArrayModel; - private final PrimitiveArrayModel primitiveSubArrayModel; - private final Class elementClass; - - /** - * Create a model of a StructuredArray instance with terminal (non StructuredArray) elements - * - * @param arrayClass The class of the StructuredArray modeled by the model - * @param elementClass The class of the elements in the StructuredArray modeled by the model - * @param length The length of the StructuredArray modeled by the model - */ - AbstractStructuredArrayModel(final Class arrayClass, - final Class elementClass, - final long length) { - this.arrayClass = arrayClass != null ? arrayClass : deriveArrayTypeParameter(); - this.length = length; - this.structuredSubArrayModel = null; - this.primitiveSubArrayModel = null; - this.elementClass = elementClass != null ? elementClass : deriveElementTypeParameter(); - } - - /** - * Create a model of a StructuredArray instance with elements that are PrimitiveArrays - * - * @param arrayClass The class of the StructuredArray modeled by the model - * @param primitiveSubArrayModel The model describing the structure of the elements of the array being modeled - * @param length The length of the StructuredArray modeled by the model - */ - @SuppressWarnings("unchecked") - AbstractStructuredArrayModel(final Class arrayClass, - final PrimitiveArrayModel primitiveSubArrayModel, - final long length) { - this.arrayClass = arrayClass != null ? arrayClass : deriveArrayTypeParameter(); - this.length = length; - this.structuredSubArrayModel = null; - this.primitiveSubArrayModel = primitiveSubArrayModel; - this.elementClass = (Class) primitiveSubArrayModel._getArrayClass(); - } - - /** - * Create a model of a StructuredArray instance with elements that are themselves StructuredArrays - * - * @param arrayClass The class of the StructuredArray modeled by the model - * @param structuredSubArrayModel The model describing the structure of the elements of the array being modeled - * @param length The length of the StructuredArray modeled by the model - */ - @SuppressWarnings("unchecked") - AbstractStructuredArrayModel(final Class arrayClass, - final StructuredArrayModel structuredSubArrayModel, - final long length) { - this.arrayClass = arrayClass != null ? arrayClass : deriveArrayTypeParameter(); - this.length = length; - this.structuredSubArrayModel = structuredSubArrayModel; - this.primitiveSubArrayModel = null; - this.elementClass = (Class) structuredSubArrayModel._getArrayClass(); - } - - /** - * Get the class of the array modeled by this model - * @return the class of the StructuredArray modeled by this model - */ - final Class _getArrayClass() { - return arrayClass; - } - - /** - * Get the length of the array modeled by the model - * @return The length of the StructuredArray modeled by the model - */ - final long _getLength() { - return length; - } - - - /** - * Get the model describing the structure of the elements of the array being modeled (when those - * elements are structured arrays). - * @return the model describing the structure of the elements of the array being modeled - */ - final StructuredArrayModel _getStructuredSubArrayModel() { - return structuredSubArrayModel; - } - - /** - * Get the model describing the structure of the elements of the array being modeled (when those - * elements are primitive arrays). - * @return the model describing the structure of the elements of the array being modeled - */ - final PrimitiveArrayModel _getPrimitiveSubArrayModel() { - return primitiveSubArrayModel; - } - - /** - * Get the class of the elements in the StructuredArray modeled by the model - * @return the class of the elements in the StructuredArray modeled by the model - */ - final Class _getElementClass() { - return elementClass; - } - - private Class deriveElementTypeParameter() { - ParameterizedType genericSuperclass = (ParameterizedType) this.getClass().getGenericSuperclass(); - @SuppressWarnings("unchecked") - Class derivedType = typeToClass(genericSuperclass.getActualTypeArguments()[1]); - return derivedType; - } - - private Class deriveArrayTypeParameter() { - ParameterizedType genericSuperclass = (ParameterizedType) this.getClass().getGenericSuperclass(); - @SuppressWarnings("unchecked") - Class derivedType = typeToClass(genericSuperclass.getActualTypeArguments()[0]); - return derivedType; - } - - static Class typeToClass(Type t) { - if (t instanceof Class) { - return (Class) t; - } else if (t instanceof ParameterizedType) { - return (Class) ((ParameterizedType)t).getRawType(); - } else { - throw new IllegalArgumentException(); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ConstructionContext.java b/ObjectLayout/src/main/java/org/ObjectLayout/ConstructionContext.java deleted file mode 100644 index a3e931a..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ConstructionContext.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.ObjectLayout; - -/** - * The construction context for object instantiated within a StructuredArray - * - * - */ -public class ConstructionContext { - private long index; - private AbstractStructuredArray array; - private ConstructionContext containingContext; - private Object contextCookie; - - public ConstructionContext(final Object cookie) { - this.contextCookie = cookie; - } - - // Getters (public): - - /** - * Get the index (of the element being constructed) in the immediately containing StructuredArray. - * - * @return The index in the immediately containing StructuredArray - */ - public long getIndex() { - return index; - } - - /** - * Get the immediately containing StructuredArray. - * - * @return the immediately containing StructuredArray - */ - public AbstractStructuredArray getArray() { - return array; - } - - /** - * Get the containing context. The containing context will be non-null if the array this context - * relates to is nested in another StructuredArray. - * - * @return the containing context - */ - public ConstructionContext> getContainingContext() { - @SuppressWarnings("unchecked") - ConstructionContext> c = containingContext; - return c; - } - - /** - * Get the construction context cookie object.The construction context cookie of the outermost - * array is taken from the (optionally supplied) StructuredArrayBuilder used in instantiating - * the array (via {@link org.ObjectLayout.StructuredArrayBuilder#getContextCookie()}). The - * construction context cookie for nested arrays (if those exist) is taken from the {@link CtorAndArgs} - * used to construct the nested array, such that a {@link CtorAndArgsProvider} can receive - * and propagate an appropriate contextCookie. A good example of context cookie in use can be found in the - * implementation of {@link CopyCtorAndArgsProvider}. - * - * @return the construction context cookie - */ - public Object getContextCookie() { - return contextCookie; - } - - // Setters (package local): - - void setIndex(long index) { - this.index = index; - } - - void setArray(AbstractStructuredArray array) { - this.array = array; - } - - void setContainingContext(ConstructionContext containingContext) { - this.containingContext = containingContext; - } - - void setContextCookie(Object contextCookie) { - this.contextCookie = contextCookie; - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/CopyCtorAndArgsProvider.java b/ObjectLayout/src/main/java/org/ObjectLayout/CopyCtorAndArgsProvider.java deleted file mode 100644 index fb9c8e0..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/CopyCtorAndArgsProvider.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * Supports the construction of a {@link StructuredArray}'s individual elements using a - * copy constructor, copying a source array's individual elements. - *

- * Expects the source {@link StructuredArray} to be provided as an opaque (Object) cookie - * in the {@link ConstructionContext} parameter passed to the - * {@link org.ObjectLayout.CopyCtorAndArgsProvider#getForContext(ConstructionContext)} method. - *

- * If the source element being copied is itself an instance of {@link StructuredArray}, the - * source element will be passed through as a contextCookie in the outgoing {@link org.ObjectLayout.CtorAndArgs}, - * and will become the source array (the context cookie) in the next {@link StructuredArray} - * nesting level and it's calls to {@link CopyCtorAndArgsProvider#getForContext(ConstructionContext)}. - *

- * {@link CopyCtorAndArgsProvider} will attempt to efficiently recycle {@link org.ObjectLayout.CtorAndArgs} - * instances and to avoid per-element allocation of new {@link org.ObjectLayout.CtorAndArgs} instances by caching - * and recycling discarded instances. - * - * @param type of the element occupying each array slot - */ -class CopyCtorAndArgsProvider implements CtorAndArgsProvider { - private static final MethodHandles.Lookup noLookup = null; - - private final long sourceOffset; - private final Constructor copyConstructor; - private final CtorAndArgs ctorAndArgs; - - /** - * Used to apply a copy constructor to a target array's elements, copying corresponding elements from a - * source array - */ - public CopyCtorAndArgsProvider( - final Class elementClass) throws NoSuchMethodException { - this(noLookup, elementClass); - } - - /** - * Used to apply a copy constructor to a target array's elements, copying corresponding elements from a - * source array - */ - public CopyCtorAndArgsProvider( - MethodHandles.Lookup lookup, - final Class elementClass) { - this(lookup, elementClass, 0); - } - - /** - * Used to apply a copy constructor to a target array's elements, copying corresponding elements from a - * source array, starting at a given offset - * - * @param sourceOffset The beginning index in the source from which to start copying - */ - public CopyCtorAndArgsProvider( - final Class elementClass, - final long sourceOffset) { - this(noLookup, elementClass, sourceOffset); - } - - /** - * Used to apply a copy constructor to a target array's elements, copying corresponding elements from a - * source array, starting at a given offset - * - * @param lookup The lookup object to use when resolving constructors - * @param elementClass The element class to which the copy constructor belongs - * @param sourceOffset The beginning index in the source from which to start copying - */ - public CopyCtorAndArgsProvider( - MethodHandles.Lookup lookup, - final Class elementClass, - final long sourceOffset) { - this.sourceOffset = sourceOffset; - this.ctorAndArgs = new CtorAndArgs<>(lookup, elementClass, new Class[] {elementClass}, new Object[1]); - this.copyConstructor = ctorAndArgs.getConstructor(); // Remember it so we can overwrite back each time. - } - - /** - * Get a {@link CtorAndArgs} instance to be used in copy-constructing a given element index in - * a {@link StructuredArray}. . - * - * @param context The construction context (index, containing array, etc.) of the element to be constructed. - * @return {@link CtorAndArgs} instance to used in element construction - */ - @Override - public CtorAndArgs getForContext(final ConstructionContext context) { - - // Find source array for this context: - @SuppressWarnings("unchecked") - StructuredArray sourceArray = (StructuredArray) context.getContextCookie(); - - long index = context.getIndex() + sourceOffset; - - T sourceElement = sourceArray.get(index); - - ctorAndArgs.setConstructor(copyConstructor); - // Set the source object for the copy constructor: - ctorAndArgs.getArgs()[0] = sourceElement; - - // Set the cookie object to the source element. Will be passed on as the cookie object in the - // next context level if the sourceElement is a StructuredArray. - ctorAndArgs.setContextCookie(sourceElement); - - return ctorAndArgs; - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/CtorAndArgs.java b/ObjectLayout/src/main/java/org/ObjectLayout/CtorAndArgs.java deleted file mode 100644 index 109b08f..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/CtorAndArgs.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * Captures a specific constructor and arguments to be passed to it. Useful for providing - * fully customizable, per-element construction behavior for iterative constructors (such as those - * used for elements in {@link StructuredArray}) - * - * @param type of the element occupying each array slot. - */ -public class CtorAndArgs { - private static final Class[] EMPTY_ARG_TYPES = new Class[0]; - private static final Object[] EMPTY_ARGS = new Object[0]; - private static final MethodHandles.Lookup noLookup = null; - - private Constructor constructor; - private Object[] args; - private Object contextCookie; - - /** - * Create a {@link CtorAndArgs} instance. The presumption is that types in args - * match those expected by constructor. Obviously exceptions may be generated at construction time if - * this is not the case. - * - * @param constructor Constructor to be indicated in this {@link CtorAndArgs} - * @param args constructor arguments to be indicated in this {@link CtorAndArgs} - */ - public CtorAndArgs(final Constructor constructor, final Object... args) { - setConstructor(constructor); - setArgs(args); - } - - /** - * Create a {@link CtorAndArgs} instance for the given instanceClass, with a constructor - * identified by the constructorArgTypes, and using the args provides. The presumption is - * that types in args match those expected by constructor. Obviously exceptions may be - * generated at construction time if this is not the case. - * - * @param instanceClass The class which the constructor in this {@link CtorAndArgs} will instantiate - * @param constructorArgTypes The argument types expected by the constructor - * @param args constructor arguments to be indicated in this {@link CtorAndArgs} - */ - public CtorAndArgs( - final Class instanceClass, - final Class[] constructorArgTypes, - final Object... args) { - this(noLookup, instanceClass, constructorArgTypes, args); - } - - /** - * Create a {@link CtorAndArgs} instance for the given instanceClass, with a constructor - * identified by the constructorArgTypes, and using the args provides. The presumption is - * that types in args match those expected by constructor. Obviously exceptions may be - * generated at construction time if this is not the case. - * - * @param lookup The lookup object to use when resolving constructors - * @param instanceClass The class which the constructor in this {@link CtorAndArgs} will instantiate - * @param constructorArgTypes The argument types expected by the constructor - * @param args constructor arguments to be indicated in this {@link CtorAndArgs} - */ - public CtorAndArgs( - MethodHandles.Lookup lookup, - final Class instanceClass, - final Class[] constructorArgTypes, - final Object... args) { - try { - if (constructorArgTypes.length != args.length) { - throw new IllegalArgumentException("argument types and values must be the same length"); - } - @SuppressWarnings("unchecked") - Constructor ctor = instanceClass.getDeclaredConstructor(constructorArgTypes); - if (lookup != null) { - if (!belongsToThisPackage(ctor.getDeclaringClass())) { - lookup.unreflectConstructor(ctor); // May throw IllegalAccessException. - // The fact the the provided lookup Proves we may setAccessible. - ctor.setAccessible(true); - } - } - setConstructor(ctor); - setArgs(args); - } catch (NoSuchMethodException | IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - /** - * Create a {@link CtorAndArgs} instance for the given instanceClass, using the default constructor (and no args) - * - * @param instanceClass The class which the constructor in this {@link CtorAndArgs} will instantiate - */ - public CtorAndArgs(final Class instanceClass) { - this(instanceClass, EMPTY_ARG_TYPES, EMPTY_ARGS); - } - - /** - * Create a {@link CtorAndArgs} instance for the given instanceClass, using the default constructor (and no args) - * - * @param lookup The lookup object to use when resolving constructors - * @param instanceClass The class which the constructor in this {@link CtorAndArgs} will instantiate - */ - public CtorAndArgs( - MethodHandles.Lookup lookup, - final Class instanceClass) { - this(lookup, instanceClass, EMPTY_ARG_TYPES, EMPTY_ARGS); - } - - /** - * @return the Constructor indicated in this CtorAndArgs - */ - public final Constructor getConstructor() { - return constructor; - } - - /** - * Set the constructor to be indicated in this {@link CtorAndArgs}. Enables recycling of - * {@link CtorAndArgs} objects to avoid re-allocation. E.g. in copy construction loops. - * - * @param constructor Constructor to be indicated in this CtorAndArgs - * @return the {@link CtorAndArgs} instance operated on - */ - public final CtorAndArgs setConstructor(final Constructor constructor) { - if (null == constructor) { - throw new NullPointerException("constructor cannot be null"); - } - this.constructor = constructor; - return this; - } - - /** - * @return the constructor arguments indicated in this CtorAndArgs - */ - public final Object[] getArgs() { - return args; - } - - /** - * Set the constructor arguments to be indicated in this CtorAndArgs. Enables recycling of - * {@link CtorAndArgs} objects to avoid re-allocation. E.g. in copy construction loops. - * - * @param args constructor arguments to be indicated in this {@link CtorAndArgs} - * @return the {@link CtorAndArgs} instance operated on - */ - public final CtorAndArgs setArgs(final Object... args) { - this.args = args; - return this; - } - - /** - * Get the value of the opaque contextCookie object - * @return opaque contextCookie object (may be null) - */ - public Object getContextCookie() { - return contextCookie; - } - - /** - * Set the value of the opaque contextCookie object - * @param contextCookie carries an opaque object - */ - public void setContextCookie(final Object contextCookie) { - this.contextCookie = contextCookie; - } - - - private static final ClassLoader thisClassLoader = - CtorAndArgs.class.getClassLoader(); - private static final int indexOfLastPeriodInThisPackageName = - CtorAndArgs.class.getName().lastIndexOf('.'); - private static final String thisPackageName = - CtorAndArgs.class.getName().substring(0, indexOfLastPeriodInThisPackageName); - - static boolean belongsToThisPackage(Class cls) { - if (cls.getClassLoader() != thisClassLoader) { - return false; - } - if (cls.isArray()) { - return false; // Arrays are not in this class. - } - String className = cls.getName(); - // See if length of package name differs: - if (className.lastIndexOf('.') != indexOfLastPeriodInThisPackageName) { - return false; - } - return className.startsWith(thisPackageName); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/CtorAndArgsProvider.java b/ObjectLayout/src/main/java/org/ObjectLayout/CtorAndArgsProvider.java deleted file mode 100644 index e97c72f..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/CtorAndArgsProvider.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -/** - * A functional interface for providing a constructor and arguments given a construction context (index, etc.). - * Used for providing element construction information in StructuredArrays. - * - * @param type of the element occupying each array slot. - */ -public interface CtorAndArgsProvider { - - /** - * Get a {@link CtorAndArgs} instance to be used in constructing a given element index in - * a {@link StructuredArray} - * - * @param context The construction context (index, containing array, etc.) of the element to be constructed - * @return {@link CtorAndArgs} instance to used in element construction - * @throws NoSuchMethodException if expected constructor is not found in element class - */ - public CtorAndArgs getForContext(final ConstructionContext context) throws NoSuchMethodException; - -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/Intrinsic.java b/ObjectLayout/src/main/java/org/ObjectLayout/Intrinsic.java deleted file mode 100644 index 51faff4..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/Intrinsic.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.lang.invoke.MethodHandles; - - -/** - * The {@link org.ObjectLayout.Intrinsic @Intrinsic} annotation defines a declared object field to be - * intrinsic to the class it is declared in. Intrinsic objects may have their layout within the - * containing object instance optimized by JDK implementations, such that access to their content is - * faster, and avoids certain de-referencing steps. {@link org.ObjectLayout.Intrinsic @Intrinsic} fields - * must be declared private and final. - *

- * Fields annotated with {@link org.ObjectLayout.Intrinsic @Intrinsic} SHOULD be initialized using - * one of the {@link IntrinsicObjects#constructWithin(MethodHandles.Lookup, String, Object) - * IntrinsicObjects.constructWithin()} - * variants. - *

- * An {@link org.ObjectLayout.Intrinsic @Intrinsic} field that is NOT initialized using one of - * the {@link IntrinsicObjects#constructWithin(MethodHandles.Lookup, String, Object) - * IntrinsicObjects.constructWithin()} variants may not be treated as intrinsic, may result in slower - * access behaviors, and may generate compile-time warnings. - * - *

- * An example of declaring an intrinsic object is: - *

- * public class Line {
- *     //
- *     // Simple intrinsic object declaration and initialization:
- *     //
- *     {@literal @}Intrinsic
- *     private final Point endPoint1 = IntrinsicObjects.constructWithin("endPoint1", this);
- *     {@literal @}Intrinsic
- *     private final Point endPoint2 = IntrinsicObjects.constructWithin("endPoint2", this);
- *     ...
- * }
- * 
- * - */ - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Intrinsic { - /** - * The length applied to the Intrinsic array object annotated with this annotation (optional, and - * applicable only when annotating fields that are declared as {@link StructuredArray}, - * {@link ReferenceArray}} or one of the primitive array variants. E.g. {@link PrimitiveLongArray}, - * {@link PrimitiveDoubleArray}, etc. - * - * @return the length of the Intrinsic array objects annotated (StructuredArray, ReferenceArray, - * and Primitive Array variants) - */ - long length() default NO_LENGTH; - - /** - * The class of the elements of the Intrinsic {@link StructuredArray} object annotated with this - * annotation (optional, and applicable only when annotating {@link StructuredArray} fields, required - * only when it cannot be automatically derived from generic fields declarations. - * - * @return The class of the elements of the Intrinsic StructuredArray object annotated - */ - Class elementClass() default NO_DECLARED_CLASS.class; - - /** - * A no-op class used to indicate no value set for the {@link Intrinsic#elementClass()} element. - */ - static final class NO_DECLARED_CLASS {} - static final long NO_LENGTH = -1; -} - diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/IntrinsicObjectModel.java b/ObjectLayout/src/main/java/org/ObjectLayout/IntrinsicObjectModel.java deleted file mode 100644 index dc7ee87..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/IntrinsicObjectModel.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; - -/** - * An {@link IntrinsicObjectModel} models the information needed to make a specific instance field of a - * containing class intrinsic to the instances of that containing class. Intrinsic objects may have their - * layout within the containing object instance optimized by JDK implementations, such that access to - * their content is faster, and avoids certain de-referencing steps. - * - * @param The type of the intrinsic object - */ -final class IntrinsicObjectModel extends AbstractIntrinsicObjectModel { - - IntrinsicObjectModel( - MethodHandles.Lookup lookup, - Field field, - final PrimitiveArrayModel primitiveArrayModel, - final StructuredArrayModel structuredArrayModel) { - super(lookup, field, primitiveArrayModel, structuredArrayModel); - } - - /** - * Construct an intrinsic object within the containing object, using a default constructor. - * - * @param containingObject The object instance that will contain this intrinsic object - * @return A reference to the the newly constructed intrinsic object - */ - final T constructWithin(final Object containingObject) { - try { - return instantiate( - containingObject, - getObjectClass().getDeclaredConstructor(), - (Object[]) null - ); - } catch (NoSuchMethodException ex) { - throw new IllegalArgumentException(ex); - } - } - - /** - * Construct an intrinsic object within the containing object, using the given constructor and arguments. - * - * @param containingObject The object instance that will contain this intrinsic object - * @param objectConstructor The constructor to be used in constructing the intrinsic object instance - * @param args the arguments to be used with the objectConstructor - * @return A reference to the the newly constructed intrinsic object - */ - final T constructWithin( - final Object containingObject, - final Constructor objectConstructor, - final Object... args) { - if (getObjectClass() != objectConstructor.getDeclaringClass()) { - throw new IllegalArgumentException( - "The declaring class of the constructor (" + - objectConstructor.getDeclaringClass().getName() + - ") does not match the intrinsic object class declared in the model (" + - getObjectClass().getName() + - ")"); - } - return instantiate( - containingObject, - objectConstructor, - args - ); - } - - /** - * Construct an intrinsic object within the containing object, using the constructor and arguments - * supplied in the given objectCtorAndArgs argument. - * - * @param containingObject The object instance that will contain this intrinsic object - * @param objectCtorAndArgs The constructor and arguments to be used in constructing the - * intrinsic object instance - * @return A reference to the the newly constructed intrinsic object - */ - final T constructWithin( - final Object containingObject, - final CtorAndArgs objectCtorAndArgs) { - if (getObjectClass() != objectCtorAndArgs.getConstructor().getDeclaringClass()) { - throw new IllegalArgumentException( - "The declaring class of the constructor (" + - objectCtorAndArgs.getConstructor().getDeclaringClass().getName() + - ") does not match the intrinsic object class declared in the model (" + - getObjectClass().getName() + - ")"); - } - return instantiate( - containingObject, - objectCtorAndArgs.getConstructor(), - objectCtorAndArgs.getArgs() - ); - } - - /** - * Construct an intrinsic object within the containing object, using the supplied {@link StructuredArrayBuilder}. - * This form of constructWithin() can only be used to construct intrinsic objects that derive from - * StructuredArray. - * - * @param containingObject The object instance that will contain this intrinsic object - * @param arrayBuilder The {@link StructuredArrayBuilder} instance to be used in constructing the array - * @return A reference to the the newly constructed intrinsic object - */ - final T constructWithin( - final Object containingObject, - final StructuredArrayBuilder arrayBuilder) { - if (!_isStructuredArray()) { - throw new IllegalArgumentException( - "The StructuredArrayBuilder argument cannot be used on IntrinsicObjectModel" + - " that do not model StructuredArray intrinsic objects" - ); - } - if (getObjectClass() != arrayBuilder.getArrayModel().getArrayClass()) { - throw new IllegalArgumentException( - "The class in the array builder (" + - arrayBuilder.getArrayModel().getArrayClass().getName() + - ") does not match the intrinsic object class declared in the model (" + - getObjectClass().getName() + - ")"); - } - if (!arrayBuilder.getArrayModel().equals(_getStructuredArrayModel())) { - throw new IllegalArgumentException( - "The array model in supplied array builder does not match the array model used" + - " to create this IntrinsicObjectModel instance." - ); - } - return instantiate(containingObject, arrayBuilder); - } - - /** - * Construct an intrinsic object within the containing object, using the supplied {@link PrimitiveArrayBuilder}. - * This form of constructWithin() can only be used to construct intrinsic objects that derive from - * StructuredArray. - * - * @param containingObject The object instance that will contain this intrinsic object - * @param arrayBuilder The {@link PrimitiveArrayBuilder} instance to be used in constructing the array - * @return A reference to the the newly constructed intrinsic object - */ - final T constructWithin( - final Object containingObject, - final PrimitiveArrayBuilder arrayBuilder) { - if (!_isPrimitiveArray()) { - throw new IllegalArgumentException( - "The PrimitiveArrayBuilder argument cannot be used on IntrinsicObjectModel" + - " that do not model PrimitiveArrayBuilder intrinsic objects" - ); - } - if (getObjectClass() != arrayBuilder.getArrayModel().getArrayClass()) { - throw new IllegalArgumentException( - "The class in the array builder (" + - arrayBuilder.getArrayModel().getArrayClass().getName() + - ") does not match the intrinsic object class declared in the model (" + - getObjectClass().getName() + - ")"); - } - if (!arrayBuilder.getArrayModel().equals(_getPrimitiveArrayModel())) { - throw new IllegalArgumentException( - "The array model in supplied array builder does not match the array model used" + - " to create this IntrinsicObjectModel instance." - ); - } - return instantiate(containingObject, arrayBuilder); - } - - private T instantiate( - final Object containingObject, - final Constructor objectConstructor, - final Object... args) { - try { - _sanityCheckInstantiation(containingObject); - T intrinsicInstance; - if (_isPrimitiveArray()) { - intrinsicInstance = - constructPrimitiveArrayWithin(containingObject, objectConstructor, args); - } else if (_isStructuredArray()) { - @SuppressWarnings("unchecked") - AbstractStructuredArrayBuilder, E> arrayBuilder = - new StructuredArrayBuilder((StructuredArrayModel)_getStructuredArrayModel()). - arrayCtorAndArgs(objectConstructor, args).resolve(); - @SuppressWarnings("unchecked") - IntrinsicObjectModel> model = - (IntrinsicObjectModel>) this; - @SuppressWarnings("unchecked") - T array = (T) AbstractStructuredArray.constructStructuredArrayWithin(containingObject, model, - arrayBuilder); - intrinsicInstance = array; - } else { - intrinsicInstance = - constructElementWithin(containingObject, objectConstructor, args); - } - return intrinsicInstance; - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex); - } - } - - private T instantiate( - final Object containingObject, - final StructuredArrayBuilder arrayBuilder) { - try { - _sanityCheckInstantiation(containingObject); - @SuppressWarnings("unchecked") - AbstractStructuredArrayBuilder, E> builder = arrayBuilder; - @SuppressWarnings("unchecked") - IntrinsicObjectModel> model = - (IntrinsicObjectModel>) this; - @SuppressWarnings("unchecked") - T intrinsicInstance = - (T) AbstractStructuredArray.constructStructuredArrayWithin(containingObject, model, builder); - return intrinsicInstance; - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex); - } - } - - - private T instantiate( - final Object containingObject, - final PrimitiveArrayBuilder arrayBuilder) { - try { - _sanityCheckInstantiation(containingObject); - @SuppressWarnings("unchecked") - PrimitiveArrayBuilder builder = arrayBuilder; - @SuppressWarnings("unchecked") - IntrinsicObjectModel model = (IntrinsicObjectModel) this; - @SuppressWarnings("unchecked") - T intrinsicInstance = - (T) PrimitiveArrayBuilder.constructPrimitiveArrayWithin(lookup, containingObject, model, builder); - return intrinsicInstance; - } catch (InstantiationException ex) { - throw new RuntimeException(ex); - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); - } catch (InvocationTargetException ex) { - throw new RuntimeException(ex); - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/IntrinsicObjects.java b/ObjectLayout/src/main/java/org/ObjectLayout/IntrinsicObjects.java deleted file mode 100644 index 4e51cca..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/IntrinsicObjects.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Intrinsic objects (declared with the {@link org.ObjectLayout.Intrinsic @Intrinsic} annotation) may have - * their layout within the containing object instance optimized by JDK implementations, such that access - * to their content is faster, and avoids certain de-referencing steps. - *

- * The {@link org.ObjectLayout.IntrinsicObjects} class provides static methods for constructing objects - * that are {@link org.ObjectLayout.Intrinsic @Intrinsic} to their containing class. Calls to - * {@link org.ObjectLayout.IntrinsicObjects#constructWithin - * constructWithin(String fieldName, Object containingObject)} (and variants) are used to construct and - * initialize intrinsic objects associated with specific instance fields that are declared as - * {@link org.ObjectLayout.Intrinsic @Intrinsic} in their containing class. - *

- * Some example of declaring an intrinsic object include: - *

- * public class Line {
- *     private static final MethodHandles.Lookup lookup = MethodHandles.lookup();
- *     //
- *     // Simple intrinsic object declaration and initialization:
- *     //
- *     {@literal @}Intrinsic
- *     private final Point endPoint1 = IntrinsicObjects.constructWithin(lookup, "endPoint1", this);
- *     {@literal @}Intrinsic
- *     private final Point endPoint2 = IntrinsicObjects.constructWithin(lookup, "endPoint2", this);
- *     ...
- * }
- *
- * public class Octagon {
- *     private static final MethodHandles.Lookup lookup = MethodHandles.lookup();
- *     //
- *     // Intrinsic object declaration and initialization for a StructuredArray member:
- *     //
- *     {@literal @}Intrinsic(length = 8)
- *     private final StructuredArray<Point> points = IntrinsicObjects.constructWithin(lookup, "points", this);
- *     ...
- * }
- * 
- * - */ -public final class IntrinsicObjects { - - // Prevent construction: - private IntrinsicObjects() { - } - - /** - * Construct an intrinsic object at the given field within the containing object, using a default constructor. - *

- * The field specified in {@code fieldName} must be annotated with {@link org.ObjectLayout.Intrinsic @Intrinsic}, - * and must be declared private and final. - * - * @param lookup The lookup object to use for accessing the field - * @param fieldName The name of the field within the containing object - * @param containingObject The object instance that will contain this intrinsic object - * @param The type of the intrinsic object being constructed - * @return A reference to the the newly constructed intrinsic object - */ - public static T constructWithin( - MethodHandles.Lookup lookup, - final String fieldName, - final Object containingObject) { - IntrinsicObjectModel model = lookupModelFor(lookup, fieldName, containingObject); - return model.constructWithin(containingObject); - } - - /** - * Construct an intrinsic object at the given field within the containing object, using the given - * constructor and arguments. - *

- * The field specified in {@code fieldName} must be annotated with {@link org.ObjectLayout.Intrinsic @Intrinsic}, - * and must be declared private and final. - * - * @param lookup The lookup object to use for accessing the field - * @param fieldName The name of the field within the containing object - * @param containingObject The object instance that will contain this intrinsic object - * @param objectConstructor The constructor to be used in constructing the intrinsic object instance - * @param args the arguments to be used with the objectConstructor - * @param The type of the intrinsic object being constructed - * @return A reference to the the newly constructed intrinsic object - */ - public static T constructWithin( - MethodHandles.Lookup lookup, - final String fieldName, - final Object containingObject, - final Constructor objectConstructor, - final Object... args) { - IntrinsicObjectModel model = lookupModelFor(lookup, fieldName, containingObject); - return model.constructWithin(containingObject, objectConstructor, args); - } - - /** - * Construct an intrinsic object at the given field within the containing object, using the - * constructor and arguments supplied in the given objectCtorAndArgs argument. - *

- * The field specified in {@code fieldName} must be annotated with {@link org.ObjectLayout.Intrinsic @Intrinsic}, - * and must be declared private and final. - * - * @param lookup The lookup object to use for accessing the field - * @param fieldName The name of the field within the containing object - * @param containingObject The object instance that will contain this intrinsic object - * @param objectCtorAndArgs The constructor and arguments to be used in constructing the - * intrinsic object instance - * @param The type of the intrinsic object being constructed - * @return A reference to the the newly constructed intrinsic object - */ - public static T constructWithin( - MethodHandles.Lookup lookup, - final String fieldName, - final Object containingObject, - final CtorAndArgs objectCtorAndArgs) { - IntrinsicObjectModel model = lookupModelFor(lookup, fieldName, containingObject); - return model.constructWithin(containingObject, objectCtorAndArgs); - } - - /** - * Construct an intrinsic object at the given field within the containing object, using the - * supplied {@link StructuredArrayBuilder}. This form of constructWithin() can only be used - * to construct intrinsic objects that derive from {@link org.ObjectLayout.StructuredArray}. - *

- * The field specified in {@code fieldName} must be annotated with {@link org.ObjectLayout.Intrinsic @Intrinsic}, - * and must be declared private and final. - * - * @param lookup The lookup object to use for accessing the field - * @param fieldName The name of the field within the containing object - * @param containingObject The object instance that will contain this intrinsic object - * @param arrayBuilder The {@link StructuredArrayBuilder} instance to be used in constructing the array - * @param The type of the intrinsic object being constructed - * @return A reference to the the newly constructed intrinsic object - */ - public static T constructWithin( - MethodHandles.Lookup lookup, - final String fieldName, - final Object containingObject, - final StructuredArrayBuilder arrayBuilder) { - IntrinsicObjectModel model = lookupModelFor(lookup, fieldName, containingObject); - return model.constructWithin(containingObject, arrayBuilder); - } - - /** - * Construct an intrinsic object at the given field within the containing object, using the - * supplied {@link PrimitiveArrayBuilder}. This form of constructWithin() can only be used - * to construct intrinsic objects that derive from {@link org.ObjectLayout.AbstractPrimitiveArray}. - *

- * The field specified in {@code fieldName} must be annotated with {@link org.ObjectLayout.Intrinsic @Intrinsic}, - * and must be declared private and final. - * - * @param lookup The lookup object to use for accessing the field - * @param fieldName The name of the field within the containing object - * @param containingObject The object instance that will contain this intrinsic object - * @param arrayBuilder The {@link PrimitiveArrayBuilder} instance to be used in constructing the array - * @param The type of the intrinsic object being constructed - * @return A reference to the the newly constructed intrinsic object - */ - public static T constructWithin( - MethodHandles.Lookup lookup, - final String fieldName, - final Object containingObject, - final PrimitiveArrayBuilder arrayBuilder) { - IntrinsicObjectModel model = lookupModelFor(lookup, fieldName, containingObject); - return model.constructWithin(containingObject, arrayBuilder); - } - - private static final - ConcurrentHashMap> modelsByClass = - new ConcurrentHashMap>(); - - private static - HashMap lookupModelsByFieldNameForClass( - MethodHandles.Lookup lookup, - Object containingObject) { - Class c = containingObject.getClass(); - HashMap modelsByFieldName = - modelsByClass.get(c); - if (modelsByFieldName == null) { - modelsByFieldName = new HashMap(); - // Populate modelsByString hash map with all @Intrinsic fields found in the class: - populateWithClassIntrinsicModels(lookup, containingObject, modelsByFieldName); - modelsByClass.put(c, modelsByFieldName); - } - return modelsByFieldName; - } - - private static void populateWithClassIntrinsicModels( - MethodHandles.Lookup lookup, - Object containingObject, - HashMap modelsByFieldName) { - Class c = containingObject.getClass(); - for (Field field : c.getDeclaredFields()) { - if (field.getAnnotation(Intrinsic.class) != null) { - IntrinsicObjectModel objectModel = createModel(lookup, field); - modelsByFieldName.put(field.getName(), objectModel); - } - } - } - - private static IntrinsicObjectModel lookupModelFor( - MethodHandles.Lookup lookup, - String fieldName, - Object containingObject) { - HashMap modelsByFieldName = - lookupModelsByFieldNameForClass(lookup, containingObject); - @SuppressWarnings("unchecked") - IntrinsicObjectModel objectModel = - (IntrinsicObjectModel) modelsByFieldName.get(fieldName); - if (objectModel == null) { - throw new IllegalArgumentException( - "No @Intrinsic field named \"" + fieldName + "\" found in " + containingObject.getClass()); - } - return objectModel; - } - - private static IntrinsicObjectModel createModel(MethodHandles.Lookup lookup, Field field) { - @SuppressWarnings("unchecked") - Class objectClass = (Class) field.getType(); - Class containingClass = field.getDeclaringClass(); - - // Verify that the field has an @Intrinsic annotation: - Intrinsic intrinsicAnnotation = field.getAnnotation(Intrinsic.class); - if (intrinsicAnnotation == null) { - throw new IllegalArgumentException("Field \"" + field.getName() + "\" in class " + - containingClass.getSimpleName() + " does not have an @Intrinsic annotation"); - } - - // Verify the the field is of a type derived from Object: - if (!Object.class.isAssignableFrom(objectClass)) { - throw new IllegalArgumentException("@Intrinsic annotations cannot be applied to primitive types"); - } - - PrimitiveArrayModel primitiveArrayModel = getPrimitiveArrayModel(field, intrinsicAnnotation); - - StructuredArrayModel structuredArrayModel = getStructuredArrayModel(field, intrinsicAnnotation); - - sanityCheckAnnotation(intrinsicAnnotation, objectClass); - - IntrinsicObjectModel objectModel = - new IntrinsicObjectModel( - lookup, - field, - primitiveArrayModel, - structuredArrayModel - ); - return objectModel; - } - - private static long getLengthFromAnnotation(Intrinsic intrinsicAnnotation, Class objectClass) { - long length = intrinsicAnnotation.length(); - if (length == Intrinsic.NO_LENGTH) { - throw new IllegalArgumentException("length not specified. @Intrinsic annotations of " + - objectClass.getSimpleName() + " must specify length (via length = ...)"); - } - if (length < 0) { - throw new IllegalArgumentException("specified length must be positive."); - } - return length; - } - - private static PrimitiveArrayModel getPrimitiveArrayModel( - Field field, Intrinsic intrinsicAnnotation) { - if (!(AbstractPrimitiveArray.class.isAssignableFrom(field.getType()))) { - return null; - } - @SuppressWarnings("unchecked") - Class objectClass = (Class) field.getType(); - long length = getLengthFromAnnotation(intrinsicAnnotation, objectClass); - return new PrimitiveArrayModel(objectClass, length); - } - - private static > StructuredArrayModel - getStructuredArrayModel(Field field, Intrinsic intrinsicAnnotation) { - if (!StructuredArray.class.isAssignableFrom(field.getType())) { - return null; - } - - @SuppressWarnings("unchecked") - Class objectClass = (Class) field.getType(); - - long length = getLengthFromAnnotation(intrinsicAnnotation, objectClass); - - Class elementClass = deriveElementClass(field, intrinsicAnnotation); - - return new StructuredArrayModel(objectClass, elementClass, length){}; - } - - private static Class deriveElementClass(Field field, Intrinsic intrinsicAnnotation) { - - @SuppressWarnings("unchecked") - Class elementClass = intrinsicAnnotation.elementClass(); - Class objectClass = field.getType(); - - if (!Object.class.isAssignableFrom(elementClass)) { - throw new IllegalArgumentException("specified elementClass cannot be a primitive type"); - } - - // Try to infer elementClass from field: - - Type structuredArrayGenericType; - - if (objectClass.equals(StructuredArray.class)) { - // objectClass is StructuredArray, see if we can infer the generic type: - structuredArrayGenericType = field.getGenericType(); - } else { - // objectClass is a subclass of StructuredArray, see if it establishes a concrete type: - Class directSubClass = objectClass; - while (!directSubClass.getSuperclass().equals(StructuredArray.class)) { - directSubClass = directSubClass.getSuperclass(); - } - structuredArrayGenericType = directSubClass.getGenericSuperclass(); - } - - try { - ParameterizedType p = (ParameterizedType) structuredArrayGenericType; - Type t = p.getActualTypeArguments()[0]; - if (t instanceof Class) { - @SuppressWarnings("unchecked") - Class inferredElementClass = (Class) t; - if ((elementClass != Intrinsic.NO_DECLARED_CLASS.class) && - (elementClass != inferredElementClass)) { - throw new IllegalArgumentException("Specified @Intrinsic elementClass (" + elementClass.getName() + - ") does not match inferred element class (" + inferredElementClass.getName() + - ") for field \"" + field.getName() + "\" (of type " + field.getGenericType() + - ") in " + field.getDeclaringClass()); - } - elementClass = inferredElementClass; - } - } catch (ClassCastException ex) { - // structuredArrayGenericType was not a ParameterizedType. Nothing to see here. Move along. - } - - if (elementClass == Intrinsic.NO_DECLARED_CLASS.class) { - throw new IllegalArgumentException( - "elementClass not specified. @Intrinsic annotations of " + - objectClass.getSimpleName() + - " must specify elementClass (via elementClass = ...)"); - } - - return elementClass; - - } - - private static void sanityCheckAnnotation(Intrinsic intrinsicAnnotation, Class objectClass) { - - boolean isPrimitiveArray = AbstractPrimitiveArray.class.isAssignableFrom(objectClass); - boolean isStructuredArray = StructuredArray.class.isAssignableFrom(objectClass); - - if (!isPrimitiveArray && !isStructuredArray) { - if (intrinsicAnnotation.length() != Intrinsic.NO_LENGTH) { - throw new IllegalArgumentException( - "@Intrinsic annotations can only specify length for array types"); - } - } - - if (!isStructuredArray) { - if (intrinsicAnnotation.elementClass() != Intrinsic.NO_DECLARED_CLASS.class) { - throw new IllegalArgumentException( - "@Intrinsic annotations can only specify elementClass for StructuredArray types"); - } - } - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/IntrinsicProcessor.java b/ObjectLayout/src/main/java/org/ObjectLayout/IntrinsicProcessor.java deleted file mode 100644 index b2ae9ad..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/IntrinsicProcessor.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.ObjectLayout; - -import static javax.lang.model.SourceVersion.RELEASE_6; - -import java.util.Set; - -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedSourceVersion; - -import javax.lang.model.SourceVersion; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.Modifier; - -import javax.tools.Diagnostic; - -/** - * A javac annotation processor for the @Intrinsic annotation. - */ -@SupportedAnnotationTypes("org.ObjectLayout.Intrinsic") -@SupportedSourceVersion(RELEASE_6) -public class IntrinsicProcessor extends AbstractProcessor { - @Override - public boolean process(Set annotations, - RoundEnvironment roundEnv) { - if (!roundEnv.processingOver()) { - Set elements = roundEnv.getElementsAnnotatedWith(Intrinsic.class); - for (Element element : elements) { - - if (element.getKind() != ElementKind.FIELD) { - reportError("@Intrinsic must prefix a field -- " + element + - " is not a field", element); - continue; - } - - Set modifiers = element.getModifiers(); - - if (!(modifiers.contains(Modifier.FINAL) && modifiers.contains(Modifier.PRIVATE))) { - reportError("@Intrinsic object annotations can only be declared " + - "for private final fields", element); - } - - // We'd like to do a lot more sanity checking here: - // E.g. : element type must be derived from Object, and must not be a Java array. - // E.g. : length should only be specified for array (structured and primitive) types. - // E.g. : elementClass should only be specified for StructuredArrays - // E.g. : element must only be assigned directly from IntrinsicObjectModel factories. - - // reportInfo("Good @Intrinsic field " + element.getSimpleName(), element); - } - } - - return true; - } - - void reportError(String errorMessage, Element e) { - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, errorMessage, e); - } - - void reportInfo(String infoMessage, Element e) { - processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, infoMessage, e); - } - - @Override - public SourceVersion getSupportedSourceVersion() { - return SourceVersion.latest(); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveArrayBuilder.java b/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveArrayBuilder.java deleted file mode 100644 index 6c5277e..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveArrayBuilder.java +++ /dev/null @@ -1,157 +0,0 @@ -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -/** - * A builder used for instantiating a {@link AbstractPrimitiveArray}<T> - *

- * {@link org.ObjectLayout.PrimitiveArrayBuilder} follows the commonly used builder pattern, and is useful for - * capturing the instantiation parameters of {@link StructuredArray}s. - *

- *

- * {@link org.ObjectLayout.PrimitiveArrayBuilder}s can be created for "flat" and "nested" {@link StructuredArray} - * constructs, and can range from the simplest forms used when default constructors are employed, to forms that - * supply customized per-element construction arguments that can take construction context (such as index, - * containing array, and arbitrary data passed in a contextCookie) into account. - *

- * A simple example of using a {@link org.ObjectLayout.PrimitiveArrayBuilder} to instantiate a PrimitiveLongArray is: - *
- * StructuredArray<MyElementClass> array =
- *      new PrimitiveArrayBuilder(PrimitiveLongArray.class, length).
- *          build();
- * 
- *

- * An example of passing specific construction arguments to the array constructor is: - *

- * Constructor<MyArrayClass> constructor = MyArrayClass.class.getConstructor(int.Class, int.Class);
- *
- * StructuredArray<MyElementClass> array =
- *      new PrimitiveArrayBuilder(
- *          MyArrayClass.class,
- *          length).
- *          arrayCtorAndArgs(constructor, initArg1, initArg2).
- *          build();
- * 
- * - * @param The class of the PrimitiveArray that is to be instantiated by the builder - */ -public class PrimitiveArrayBuilder { - private static final Class[] EMPTY_ARG_TYPES = new Class[0]; - - private final PrimitiveArrayModel arrayModel; - private CtorAndArgs arrayCtorAndArgs; - - /** - * Constructs a new {@link org.ObjectLayout.PrimitiveArrayBuilder} object for creating arrays of - * type S with the given length. - * - * @param arrayClass The class of the array to be built by this builder - * @param length The length of the array to be build by this builder - */ - public PrimitiveArrayBuilder(final Class arrayClass, - final long length) { - this.arrayModel = new PrimitiveArrayModel(arrayClass, length); - if ((length < 0) || (length > Integer.MAX_VALUE)) { - throw new IllegalArgumentException("Cannot model PrimitiveArrays with length > Integer.MAX_VALUE"); - } - } - - /** - * Set the {@link org.ObjectLayout.CtorAndArgs} to be used in constructing arrays. - * Setting the means for array construction is Required if the array class (S) does not support a - * default constructor, or if a non-default construction of the array instance is needed. - * - * @param arrayCtorAndArgs The constructor and arguments used for constructing arrays - * @return The builder - */ - public PrimitiveArrayBuilder arrayCtorAndArgs(final CtorAndArgs arrayCtorAndArgs) { - this.arrayCtorAndArgs = arrayCtorAndArgs; - return this; - } - - /** - * Set the {@link java.lang.reflect.Constructor} and construction arguments to be used in constructing arrays. - * Setting the means for array construction is Required if the array class (S) does not support a - * default constructor, or if a non-default construction of the array instance is needed. - * - * @param constructor The constructor used for constructing arrays - * @param args The construction arguments supplied for the constructor - * @return The builder - */ - public PrimitiveArrayBuilder arrayCtorAndArgs(final Constructor constructor, final Object... args) { - this.arrayCtorAndArgs = new CtorAndArgs(constructor, args); - return this; - } - - /** - * Resolve any not-yet-resolved constructor information needed by this builder. Calling resolve() is not - * necessary ahead of building, but it is useful for ensuring resolution works ahead of actual building - * attempts. - * - * @return This builder - * @throws NoSuchMethodException if the array constructor or element constructor fail to resolve given - * the current information in the builder - */ - public PrimitiveArrayBuilder resolve() throws NoSuchMethodException { - if (arrayCtorAndArgs == null) { - arrayCtorAndArgs = new CtorAndArgs(arrayModel.getArrayClass(), EMPTY_ARG_TYPES, (Object[]) null); - } - - return this; - } - - /** - * Build a {@link AbstractPrimitiveArray} according to the information captured in this builder - * @return A newly instantiated {@link AbstractPrimitiveArray} - * - * @throws NoSuchMethodException if the array constructor or element constructor fail to resolve given - * the current information in the builder - */ - public S build() throws NoSuchMethodException { - resolve(); - int length = (int) arrayModel.getLength(); // Already verified range at instantiation - return AbstractPrimitiveArray._newInstance(length, arrayCtorAndArgs.getConstructor(), arrayCtorAndArgs.getArgs()); - } - - /** - * Get the {@link PrimitiveArrayModel} that describes the arrays built by this builder - * - * @return The {@link PrimitiveArrayModel} that describes the arrays built by this builder - */ - public PrimitiveArrayModel getArrayModel() { - return arrayModel; - } - - /** - * Get the {@link CtorAndArgs} describing the constructor and arguments used to instantiate arrays with - * this builder. May be null if non of {@link PrimitiveArrayBuilder#arrayCtorAndArgs}, - * {@link PrimitiveArrayBuilder#resolve()} or - * {@link PrimitiveArrayBuilder#build()} have been called yet. - * @return The {@link CtorAndArgs} describing the constructor and arguments used to instantiate arrays with - * this builder. - */ - public CtorAndArgs getArrayCtorAndArgs() { - return arrayCtorAndArgs; - } - - /** - * create a fresh PrimitiveArray intended to occupy a a given intrinsic field in the containing object, - * at the field described by the supplied intrinsicObjectModel, using the supplied constructor and arguments. - */ - static T constructPrimitiveArrayWithin( - MethodHandles.Lookup lookup, - final Object containingObject, - final AbstractIntrinsicObjectModel intrinsicObjectModel, - PrimitiveArrayBuilder arrayBuilder) - throws InstantiationException, IllegalAccessException, InvocationTargetException { - return AbstractPrimitiveArray.constructPrimitiveArrayWithin( - lookup, - containingObject, intrinsicObjectModel, - arrayBuilder.getArrayModel().getLength(), - arrayBuilder.getArrayCtorAndArgs().getConstructor(), - arrayBuilder.getArrayCtorAndArgs().getArgs() - ); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveArrayModel.java b/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveArrayModel.java deleted file mode 100644 index cc81fed..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveArrayModel.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.ObjectLayout; - -/** - * A model that describes the structure of a PrimitiveArray - * - * @param The class of the PrimitiveArray modeled by the model - */ -public class PrimitiveArrayModel extends AbstractPrimitiveArrayModel { - - /** - * Create a model of a PrimitiveArray instance - * - * @param arrayClass The class of the PrimitiveArray modeled by the model - * @param length The length of the PrimitiveArray modeled by the model - */ - public PrimitiveArrayModel(final Class arrayClass, - final long length) { - super(arrayClass, length); - } - - /** - * Determine if this model is equal to another object. If the other object is not a model, they are - * not equal. If the other object is a model, the two are equal if all details, (arrayClass, elementClass, - * length) are identical. - * - * @param other the other object - * @return true is the other object is a model that is equal to this one, false otherwise. - */ - @Override - public boolean equals(Object other) { - if (!(other instanceof PrimitiveArrayModel)) { - return false; - } - @SuppressWarnings("unchecked") - PrimitiveArrayModel otherArray = (PrimitiveArrayModel) other; - if ((getArrayClass() != otherArray.getArrayClass()) || - (getLength() != otherArray.getLength())) { - return false; - } - return true; - } - - @Override - public int hashCode() { - return getArrayClass().hashCode() ^ ((int)(getLength()^(getLength()>>>32))); - } - - /** - * Get the class of the PrimitiveArray modeled by this model - * @return the class of the PrimitiveArray modeled by this model - */ - public final Class getArrayClass() { - return super._getArrayClass(); - } - - /** - * Get the length of the PrimitiveArray modeled by the model - * @return The length of the PrimitiveArray modeled by the model - */ - public final long getLength() { - return super._getLength(); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveByteArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveByteArray.java deleted file mode 100644 index 346fef3..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveByteArray.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of bytes. - * - * {@link PrimitiveByteArray} is designed with semantics specifically chosen and restricted such that a "flat" - * memory layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class PrimitiveByteArray extends AbstractPrimitiveByteArray { - - /** - * Get a reference to a byte[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a byte[]. - * - * @return a reference to a byte[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a byte[] - */ - public byte[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - public long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public byte get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public byte get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final int index, final byte value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final long index, final byte value) { - _set(index, value); - } - - /** - * Default constructor - */ - public PrimitiveByteArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - public PrimitiveByteArray(PrimitiveByteArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link PrimitiveByteArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link PrimitiveByteArray} with the given length - */ - public static PrimitiveByteArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, PrimitiveByteArray.class, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveByteArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveByteArray) - * @param length the length of the array. - * @param
The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link PrimitiveByteArray}> with a given length - */ - public static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveByteArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveByteArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link PrimitiveByteArray}> with a given length - */ - public static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveByteArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link PrimitiveByteArray}> - */ - public static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveByteArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link PrimitiveByteArray}> - */ - public static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link PrimitiveByteArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link PrimitiveByteArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link PrimitiveByteArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link PrimitiveByteArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveCharArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveCharArray.java deleted file mode 100644 index 540828e..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveCharArray.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of chars. - * - * {@link PrimitiveCharArray} is designed with semantics specifically chosen and restricted such that a "flat" memory - * layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class PrimitiveCharArray extends AbstractPrimitiveCharArray { - - /** - * Get a reference to a char[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a char[]. - * - * @return a reference to a char[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a char[] - */ - public char[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - public long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public char get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public char get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final int index, final char value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final long index, final char value) { - _set(index, value); - } - - /** - * Default constructor - */ - public PrimitiveCharArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - public PrimitiveCharArray(PrimitiveCharArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link PrimitiveCharArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link PrimitiveCharArray} with the given length - */ - public static PrimitiveCharArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, PrimitiveCharArray.class, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveCharArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveCharArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link PrimitiveCharArray}> with a given length - */ - public static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveCharArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the arrayClass constructor - * @param arrayClass The class of the array to be created (extends PrimitiveCharArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link PrimitiveCharArray}> with a given length - */ - public static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveCharArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link PrimitiveCharArray}> - */ - public static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveCharArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link PrimitiveCharArray}> - */ - public static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link PrimitiveCharArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link PrimitiveCharArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link PrimitiveCharArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link PrimitiveCharArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveDoubleArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveDoubleArray.java deleted file mode 100644 index 331311b..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveDoubleArray.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of doubles. - * - * {@link PrimitiveDoubleArray} is designed with semantics specifically chosen and restricted such that a "flat" memory - * layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class PrimitiveDoubleArray extends AbstractPrimitiveDoubleArray { - - /** - * Get a reference to a double[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a double[]. - * - * @return a reference to a double[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a double[] - */ - public double[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - public long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public double get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public double get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final int index, final double value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final long index, final double value) { - _set(index, value); - } - - /** - * Default constructor - */ - public PrimitiveDoubleArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - public PrimitiveDoubleArray(PrimitiveDoubleArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link PrimitiveDoubleArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link PrimitiveDoubleArray} with the given length - */ - public static PrimitiveDoubleArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, PrimitiveDoubleArray.class, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveDoubleArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveDoubleArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link PrimitiveDoubleArray}> with a given length - */ - public static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveDoubleArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveDoubleArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link PrimitiveDoubleArray}> with a given length - */ - public static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveDoubleArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link PrimitiveDoubleArray}> - */ - public static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveDoubleArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link PrimitiveDoubleArray}> - */ - public static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link PrimitiveDoubleArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link PrimitiveDoubleArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link PrimitiveDoubleArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link PrimitiveDoubleArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveFloatArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveFloatArray.java deleted file mode 100644 index 7eea639..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveFloatArray.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of floats. - * - * {@link PrimitiveFloatArray} is designed with semantics specifically chosen and restricted such that a "flat" memory - * layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class PrimitiveFloatArray extends AbstractPrimitiveFloatArray { - - /** - * Get a reference to a float[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a float[]. - * - * @return a reference to a float[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a float[] - */ - public float[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - public long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public float get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public float get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final int index, final float value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final long index, final float value) { - _set(index, value); - } - - /** - * Default constructor - */ - public PrimitiveFloatArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - public PrimitiveFloatArray(PrimitiveFloatArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link PrimitiveFloatArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link PrimitiveFloatArray} with the given length - */ - public static PrimitiveFloatArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, PrimitiveFloatArray.class, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveFloatArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveFloatArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link PrimitiveFloatArray}> with a given length - */ - public static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveFloatArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveFloatArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link PrimitiveFloatArray}> with a given length - */ - public static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveFloatArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link PrimitiveFloatArray}> - */ - public static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveFloatArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link PrimitiveFloatArray}> - */ - public static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link PrimitiveFloatArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link PrimitiveFloatArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link PrimitiveFloatArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link PrimitiveFloatArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveIntArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveIntArray.java deleted file mode 100644 index d5c3935..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveIntArray.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of ints. - * - * {@link PrimitiveIntArray} is designed with semantics specifically chosen and restricted such that a "flat" memory - * layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class PrimitiveIntArray extends AbstractPrimitiveIntArray { - - /** - * Get a reference to a int[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a int[]. - * - * @return a reference to a int[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a int[] - */ - public int[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - public long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public int get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public int get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final int index, final int value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final long index, final int value) { - _set(index, value); - } - - /** - * Default constructor - */ - public PrimitiveIntArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - public PrimitiveIntArray(PrimitiveIntArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link PrimitiveIntArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link PrimitiveIntArray} with the given length - */ - public static PrimitiveIntArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, PrimitiveIntArray.class, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveIntArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveIntArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link PrimitiveIntArray}> with a given length - */ - public static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveIntArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveIntArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link PrimitiveIntArray}> with a given length - */ - public static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveIntArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link PrimitiveIntArray}> - */ - public static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveIntArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link PrimitiveIntArray}> - */ - public static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link PrimitiveIntArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link PrimitiveIntArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link PrimitiveIntArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link PrimitiveIntArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveLongArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveLongArray.java deleted file mode 100644 index 70c449c..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveLongArray.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of longs. - * - * {@link PrimitiveLongArray} is designed with semantics specifically chosen and restricted such that a "flat" memory - * layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class PrimitiveLongArray extends AbstractPrimitiveLongArray { - - /** - * Get a reference to a long[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a long[]. - * - * @return a reference to a long[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a long[] - */ - public long[] asArray() { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - public long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public long get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public long get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final int index, final long value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final long index, final long value) { - _set(index, value); - } - - /** - * Default constructor - */ - public PrimitiveLongArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - public PrimitiveLongArray(PrimitiveLongArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link PrimitiveLongArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link PrimitiveLongArray} with the given length - */ - public static PrimitiveLongArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, PrimitiveLongArray.class, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveLongArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveLongArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link PrimitiveLongArray}> with a given length - */ - public static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveLongArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveLongArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link PrimitiveLongArray}> with a given length - */ - public static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveLongArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link PrimitiveLongArray}> - */ - public static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveLongArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link PrimitiveLongArray}> - */ - public static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link PrimitiveLongArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link PrimitiveLongArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link PrimitiveLongArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link PrimitiveLongArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveShortArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveShortArray.java deleted file mode 100644 index 211f059..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/PrimitiveShortArray.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of shorts. - * - * {@link PrimitiveShortArray} is designed with semantics specifically chosen and restricted such that a "flat" memory - * layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class PrimitiveShortArray extends AbstractPrimitiveShortArray { - - /** - * Get a reference to a short[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a short[]. - * - * @return a reference to a short[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a short[] - */ - public short[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - public long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public short get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public short get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final int index, final short value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final long index, final short value) { - _set(index, value); - } - - /** - * Default constructor - */ - public PrimitiveShortArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - public PrimitiveShortArray(PrimitiveShortArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link PrimitiveShortArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link PrimitiveShortArray} with the given length - */ - public static PrimitiveShortArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, PrimitiveShortArray.class, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveShortArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveShortArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link PrimitiveShortArray}> with a given length - */ - public static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveShortArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveShortArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link PrimitiveShortArray}> with a given length - */ - public static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveShortArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link PrimitiveShortArray}> - */ - public static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link PrimitiveShortArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link PrimitiveShortArray}> - */ - public static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link PrimitiveShortArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link PrimitiveShortArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link PrimitiveShortArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link PrimitiveShortArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveByteArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveByteArray.java deleted file mode 100644 index 5a76223..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveByteArray.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of bytes. This protected variant keeps access to the subclassed array protected - * such that inheriting classes can avoid unintentional exposure of the array and its contents to their users. - * - * {@link ProtectedPrimitiveByteArray} is designed with semantics specifically chosen and restricted such that a "flat" - * memory layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class ProtectedPrimitiveByteArray extends AbstractPrimitiveByteArray { - - /** - * Get a reference to a byte[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a byte[]. - * - * @return a reference to a byte[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a byte[] - */ - protected byte[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - protected long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected byte get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected byte get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final int index, final byte value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final long index, final byte value) { - _set(index, value); - } - - /** - * Default constructor - */ - protected ProtectedPrimitiveByteArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - protected ProtectedPrimitiveByteArray(ProtectedPrimitiveByteArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link ProtectedPrimitiveByteArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link ProtectedPrimitiveByteArray} with the given length - */ - protected static ProtectedPrimitiveByteArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, ProtectedPrimitiveByteArray.class, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveByteArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveByteArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveByteArray}> with a given length - */ - protected static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveByteArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveByteArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveByteArray}> with a given length - */ - protected static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveByteArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveByteArray}> - */ - protected static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveByteArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveByteArray}> - */ - protected static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveByteArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveByteArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveByteArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveByteArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveByteArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveCharArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveCharArray.java deleted file mode 100644 index 3ba4476..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveCharArray.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of chars. This protected variant keeps access to the subclassed array protected - * such that inheriting classes can avoid unintentional exposure of the array and its contents to their users. - * - * {@link ProtectedPrimitiveCharArray} is designed with semantics specifically chosen and restricted such that a - * "flat" memory layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class ProtectedPrimitiveCharArray extends AbstractPrimitiveCharArray { - - /** - * Get a reference to a char[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a char[]. - * - * @return a reference to a char[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a char[] - */ - protected char[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - protected long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected char get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected char get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final int index, final char value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final long index, final char value) { - _set(index, value); - } - - /** - * Default constructor - */ - protected ProtectedPrimitiveCharArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - protected ProtectedPrimitiveCharArray(ProtectedPrimitiveCharArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link ProtectedPrimitiveCharArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link ProtectedPrimitiveCharArray} with the given length - */ - protected static ProtectedPrimitiveCharArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, ProtectedPrimitiveCharArray.class, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveCharArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveCharArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveCharArray}> with a given length - */ - protected static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveCharArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the arrayClass constructor - * @param arrayClass The class of the array to be created (extends PrimitiveCharArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveCharArray}> with a given length - */ - protected static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveCharArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveCharArray}> - */ - protected static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveCharArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveCharArray}> - */ - protected static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveCharArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveCharArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveCharArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveCharArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveCharArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveDoubleArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveDoubleArray.java deleted file mode 100644 index 5d48eb7..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveDoubleArray.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of doubles. This protected variant keeps access to the subclassed array protected - * such that inheriting classes can avoid unintentional exposure of the array and its contents to their users. - * - * {@link ProtectedPrimitiveDoubleArray} is designed with semantics specifically chosen and restricted such that - * a "flat" memory layout of the implemented data structure would be possible on optimizing JVMs. While fully - * functional on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class ProtectedPrimitiveDoubleArray extends AbstractPrimitiveDoubleArray { - - /** - * Get a reference to a double[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a double[]. - * - * @return a reference to a double[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a double[] - */ - protected double[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - protected long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected double get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected double get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final int index, final double value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final long index, final double value) { - _set(index, value); - } - - /** - * Default constructor - */ - protected ProtectedPrimitiveDoubleArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - protected ProtectedPrimitiveDoubleArray(ProtectedPrimitiveDoubleArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link ProtectedPrimitiveDoubleArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link ProtectedPrimitiveDoubleArray} with the given length - */ - protected static ProtectedPrimitiveDoubleArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, ProtectedPrimitiveDoubleArray.class, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveDoubleArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveDoubleArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveDoubleArray}> with a given length - */ - protected static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveDoubleArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveDoubleArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveDoubleArray}> with a given length - */ - protected static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveDoubleArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveDoubleArray}> - */ - protected static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveDoubleArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveDoubleArray}> - */ - protected static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveDoubleArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveDoubleArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveDoubleArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveDoubleArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveDoubleArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveFloatArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveFloatArray.java deleted file mode 100644 index 1e12986..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveFloatArray.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of floats. This protected variant keeps access to the subclassed array protected - * such that inheriting classes can avoid unintentional exposure of the array and its contents to their users. - * - * {@link ProtectedPrimitiveFloatArray} is designed with semantics specifically chosen and restricted such that a - * "flat" memory layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class ProtectedPrimitiveFloatArray extends AbstractPrimitiveFloatArray { - - /** - * Get a reference to a float[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a float[]. - * - * @return a reference to a float[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a float[] - */ - protected float[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - protected long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected float get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected float get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final int index, final float value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final long index, final float value) { - _set(index, value); - } - - /** - * Default constructor - */ - protected ProtectedPrimitiveFloatArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - protected ProtectedPrimitiveFloatArray(ProtectedPrimitiveFloatArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link ProtectedPrimitiveFloatArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link ProtectedPrimitiveFloatArray} with the given length - */ - protected static ProtectedPrimitiveFloatArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, ProtectedPrimitiveFloatArray.class, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveFloatArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveFloatArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveFloatArray}> with a given length - */ - protected static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveFloatArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveFloatArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveFloatArray}> with a given length - */ - protected static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveFloatArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveFloatArray}> - */ - protected static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveFloatArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveFloatArray}> - */ - protected static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveFloatArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveFloatArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveFloatArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveFloatArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveFloatArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveIntArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveIntArray.java deleted file mode 100644 index 587ba3b..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveIntArray.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of ints. This protected variant keeps access to the subclassed array protected - * such that inheriting classes can avoid unintentional exposure of the array and its contents to their users. - * - * {@link ProtectedPrimitiveIntArray} is designed with semantics specifically chosen and restricted such that a - * "flat" memory layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class ProtectedPrimitiveIntArray extends AbstractPrimitiveIntArray { - - /** - * Get a reference to a int[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a int[]. - * - * @return a reference to a int[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a int[] - */ - protected int[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - protected long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected int get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected int get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final int index, final int value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final long index, final int value) { - _set(index, value); - } - - /** - * Default constructor - */ - protected ProtectedPrimitiveIntArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - protected ProtectedPrimitiveIntArray(ProtectedPrimitiveIntArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link ProtectedPrimitiveIntArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link ProtectedPrimitiveIntArray} with the given length - */ - protected static ProtectedPrimitiveIntArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, ProtectedPrimitiveIntArray.class, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveIntArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveIntArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveIntArray}> with a given length - */ - protected static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveIntArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveIntArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveIntArray}> with a given length - */ - protected static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveIntArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveIntArray}> - */ - protected static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveIntArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveIntArray}> - */ - protected static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveIntArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveIntArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveIntArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveIntArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveIntArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveLongArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveLongArray.java deleted file mode 100644 index 18774ed..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveLongArray.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of longs. This protected variant keeps access to the subclassed array protected - * such that inheriting classes can avoid unintentional exposure of the array and its contents to their users. - * - * {@link ProtectedPrimitiveLongArray} is designed with semantics specifically chosen and restricted such that a - * "flat" memory layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class ProtectedPrimitiveLongArray extends AbstractPrimitiveLongArray { - - /** - * Get a reference to a long[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a long[]. - * - * @return a reference to a long[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a long[] - */ - protected long[] asArray() { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - protected long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected long get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected long get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final int index, final long value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final long index, final long value) { - _set(index, value); - } - - /** - * Default constructor - */ - protected ProtectedPrimitiveLongArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - protected ProtectedPrimitiveLongArray(ProtectedPrimitiveLongArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link ProtectedPrimitiveLongArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link ProtectedPrimitiveLongArray} with the given length - */ - protected static ProtectedPrimitiveLongArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, ProtectedPrimitiveLongArray.class, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveLongArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveLongArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveLongArray}> with a given length - */ - protected static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveLongArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveLongArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveLongArray}> with a given length - */ - protected static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveLongArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveLongArray}> - */ - protected static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveLongArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveLongArray}> - */ - protected static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveLongArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveLongArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveLongArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveLongArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveLongArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveShortArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveShortArray.java deleted file mode 100644 index 6cf49b5..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedPrimitiveShortArray.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of shorts. This protected variant keeps access to the subclassed array protected - * such that inheriting classes can avoid unintentional exposure of the array and its contents to their users. - * - * {@link ProtectedPrimitiveShortArray} is designed with semantics specifically chosen and restricted such that a - * "flat" memory layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - */ - -public class ProtectedPrimitiveShortArray extends AbstractPrimitiveShortArray { - - /** - * Get a reference to a short[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a short[]. - * - * @return a reference to a short[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a short[] - */ - protected short[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - protected long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected short get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected short get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final int index, final short value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final long index, final short value) { - _set(index, value); - } - - /** - * Default constructor - */ - protected ProtectedPrimitiveShortArray() { - super(); - } - - /** - * Copying constructor - * - * @param sourceArray the array to copy - */ - protected ProtectedPrimitiveShortArray(ProtectedPrimitiveShortArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of {@link ProtectedPrimitiveShortArray} with a given length. - * - * @param length the length of the array. - * @return a new instance of {@link ProtectedPrimitiveShortArray} with the given length - */ - protected static ProtectedPrimitiveShortArray newInstance(final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, ProtectedPrimitiveShortArray.class, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveShortArray}> with a given length. - * - * @param arrayClass The class of the array to be created (extends PrimitiveShortArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveShortArray}> with a given length - */ - protected static A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveShortArray}> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends PrimitiveShortArray) - * @param length the length of the array. - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveShortArray}> with a given length - */ - protected static A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveShortArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveShortArray}> - */ - protected static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedPrimitiveShortArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveShortArray}> - */ - protected static A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveShortArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveShortArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link ProtectedPrimitiveShortArray}> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends PrimitiveShortArray) - * @return a new instance of <A extends {@link ProtectedPrimitiveShortArray}> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedReferenceArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedReferenceArray.java deleted file mode 100644 index eff40e0..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedReferenceArray.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of object references. This protected variant keeps access to the subclassed array protected - * such that inheriting classes can avoid unintentional exposure of the array and its contents to their users. - * - * {@link ProtectedReferenceArray} is designed with semantics specifically chosen and restricted such that a - * "flat" memory layout of the implemented data structure would be possible on optimizing JVMs. While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - * - * @param The reference type - */ - -public class ProtectedReferenceArray extends AbstractReferenceArray { - - /** - * Get a reference to a T[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a T[]. - * - * @return a reference to a T[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a T[] - */ - protected T[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - protected long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected T get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - protected T get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final int index, final T value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - protected void set(final long index, final T value) { - _set(index, value); - } - - /** - * Default constructor - */ - protected ProtectedReferenceArray() { - super(); - } - - /** - * Copy constructor - * - * @param sourceArray the array to copy - */ - protected ProtectedReferenceArray(ProtectedReferenceArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of ReferenceArray<T> with a given length. - * - * @param length the length of the array - * @param the reference type - * @return A newly created ReferenceArray<T> - */ - protected static ProtectedReferenceArray newInstance(final long length) { - @SuppressWarnings("unchecked") - ProtectedReferenceArray referenceArray = _newInstance(noLookup, ProtectedReferenceArray.class, length); - return referenceArray; - } - - /** - * Create a new instance of <A extends {@link ProtectedReferenceArray}<T>> with a given length. - * - * @param arrayClass The class of the array to be created (extends ReferenceArray<T>) - * @param length the length of the array. - * @param the reference type - * @param The class of the array to be created (extends ReferenceArray<T>) - * @return a new instance of <A extends {@link ProtectedReferenceArray}<T>> with a given length - */ - protected static > A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedReferenceArray}<T>> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends ReferenceArray<T>) - * @param length the length of the array. - * @param the reference type - * @param The class of the array to be created (extends ReferenceArray<T>) - * @return a new instance of <A extends {@link ProtectedReferenceArray}<T>> with a given length - */ - protected static > A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedReferenceArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends ReferenceArray) - * @return a new instance of <A extends {@link ProtectedReferenceArray}> - */ - protected static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link ProtectedReferenceArray}<T>> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param the reference type - * @param The class of the array to be created (extends ReferenceArray<T>) - * @return a new instance of <A extends {@link ProtectedReferenceArray}<T>> - */ - protected static > A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link ProtectedReferenceArray}<T>> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends ReferenceArray<T>) - * @param The class of the element in the array to be created - * @return a new instance of <A extends {@link ProtectedReferenceArray}<T>> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static > A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link ProtectedReferenceArray}<T>> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends ReferenceArray<T>) - * @param The class of the element in the array to be created - * @return a new instance of <A extends {@link ProtectedReferenceArray}<T>> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - protected static > A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedStructuredArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedStructuredArray.java deleted file mode 100644 index 3666303..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedStructuredArray.java +++ /dev/null @@ -1,555 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.util.Collection; - -/** - * An array of non-replaceable objects. This protected variant keeps access to the subclassed array protected - * such that inheriting classes can avoid unintentional exposure of the array and its contents to their users. - *

- * A structured array contains array element objects of a fixed (at creation time, per array instance) class, - * and can support elements of any class that provides accessible constructors. The elements in a StructuredArray - * are all allocated and constructed at array creation time, and individual elements cannot be removed or - * replaced after array creation. Array elements can be accessed using an index-based accessor methods in - * the form of {@link ProtectedStructuredArray#get}() using either int or long indices. Individual element contents - * can then be accessed and manipulated using any and all operations supported by the member element's class. - *

- * While simple creation of default-constructed elements and fixed constructor parameters are available through - * the newInstance factory methods, supporting arbitrary member types requires a wider range of construction - * options. The {@link CtorAndArgsProvider} API provides for array creation with arbitrary, user-supplied - * constructors and arguments, the selection of which can take the element index and construction context - * into account. - *

- * StructuredArray is designed with semantics specifically chosen and restricted such that a "flat" memory - * layout of the implemented data structure would be possible on optimizing JVMs. Doing so provides for the - * possibility of matching access speed benefits that exist in data structures with similar semantics that - * are supported in other languages (e.g. an array of structs in C-like languages). While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates consistent stride - * based memory access and dead-reckoning (as opposed to de-referenced) access to elements - * - * @param The class of the array elements - */ -public class ProtectedStructuredArray extends AbstractStructuredArray { - - // Single-dimensional newInstance forms: - - /** - * Create an array of length elements, each containing an element object of - * type elementClass. Using the elementClass's default constructor. - * - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array elements - * @return The newly created array - */ - protected static ProtectedStructuredArray newInstance( - final Class elementClass, - final long length) { - @SuppressWarnings("unchecked") - ProtectedStructuredArray instance = _newInstance(ProtectedStructuredArray.class, elementClass, length); - return instance; - } - - /** - * Create an array of length elements, each containing an element object of - * type elementClass. Using the elementClass's default constructor. - * - * @param lookup The lookup object to use when resolving constructors - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array elements - * @return The newly created array - */ - protected static ProtectedStructuredArray newInstance( - MethodHandles.Lookup lookup, - final Class elementClass, - final long length) { - @SuppressWarnings("unchecked") - ProtectedStructuredArray instance = _newInstance(lookup, ProtectedStructuredArray.class, elementClass, length); - return instance; - } - - /** - * Create an arrayClass array of length elements of - * type elementClass. Using the elementClass's default constructor. - * - * @param arrayClass of the array to create - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - final Class arrayClass, - final Class elementClass, - final long length) { - return _newInstance(arrayClass, elementClass, length); - } - - /** - * Create an arrayClass array of length elements of - * type elementClass. Using the elementClass's default constructor. - * - * @param lookup The lookup object to use when resolving constructors - * @param arrayClass of the array to create - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final long length) { - return _newInstance(lookup, arrayClass, elementClass, length); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use elementClass's default constructor. - * - * @param arrayCtorAndArgs for creating the array - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - final CtorAndArgs arrayCtorAndArgs, - final Class elementClass, - final long length) { - return _newInstance(arrayCtorAndArgs, elementClass, length); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use elementClass's default constructor. - * - * @param lookup The lookup object to use when resolving constructors - * @param arrayCtorAndArgs for creating the array - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - MethodHandles.Lookup lookup, - final CtorAndArgs arrayCtorAndArgs, - final Class elementClass, - final long length) { - return _newInstance(lookup, arrayCtorAndArgs, elementClass, length); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use elementClass's default constructor. - * - * @param arrayCtorAndArgs for creating the array - * @param elementCtorAndArgs of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - final CtorAndArgs arrayCtorAndArgs, - final CtorAndArgs elementCtorAndArgs, - final long length) { - return _newInstance(arrayCtorAndArgs, elementCtorAndArgs, length); - } - - /** - * Create an array of length elements of type elementClass. Use constructor and - * arguments supplied (on a potentially per element index basis) by the specified - * ctorAndArgsProvider to construct and initialize each element. - * - * @param elementClass of each element in the array - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param length of the array to create - * @param The class of the array elements - * @return The newly created array - */ - protected static ProtectedStructuredArray newInstance( - final Class elementClass, - final CtorAndArgsProvider ctorAndArgsProvider, - final long length) { - @SuppressWarnings("unchecked") - ProtectedStructuredArray instance = _newInstance(ProtectedStructuredArray.class, elementClass, length, ctorAndArgsProvider); - return instance; - } - - /** - * Create an arrayClass array of length elements, each containing an element object of - * type elementClass. Use constructor and arguments supplied (on a potentially - * per element index basis) by the specified ctorAndArgsProvider to construct and initialize - * each element. - * - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param length of the array to create - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - final Class arrayClass, - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - return _newInstance(arrayClass, elementClass, length, ctorAndArgsProvider); - } - - /** - * Create an arrayClass array of length elements, each containing an element object of - * type elementClass. Use constructor and arguments supplied (on a potentially - * per element index basis) by the specified ctorAndArgsProvider to construct and initialize - * each element. - * - * @param lookup The lookup object to use when resolving constructors - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param length of the array to create - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - return _newInstance(lookup, arrayClass, elementClass, length, ctorAndArgsProvider); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use constructor and arguments - * supplied (on a potentially per element index basis) by the specified ctorAndArgsProvider - * to construct and initialize each element. - * - * @param arrayCtorAndArgs of the array to create - * @param elementClass of each element in the array - * @param length of the array to create - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - final CtorAndArgs arrayCtorAndArgs, - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - return _newInstance(arrayCtorAndArgs, elementClass, length, ctorAndArgsProvider); - } - - /** - * Create a <S extends StructuredArray<T>> array instance with elements copied from a source - * collection. - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param sourceCollection provides details for building the array - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - final Class arrayClass, - final Class elementClass, - final Collection sourceCollection) { - return _newInstance(arrayClass, elementClass, sourceCollection); - } - - /** - * Create a <S extends StructuredArray<T>> array instance with elements copied from a source - * collection. - * @param lookup The lookup object to use when resolving constructors - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param sourceCollection provides details for building the array - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final Collection sourceCollection) { - return _newInstance(lookup, arrayClass, elementClass, sourceCollection); - } - - /** - * Create a <S extends StructuredArray<T>> array instance according to the details provided in the - * arrayBuilder. - * @param arrayBuilder provides details for building the array - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S newInstance( - final StructuredArrayBuilder arrayBuilder) { - return _newInstance(arrayBuilder); - } - - /** - * Copy a given array of elements to a newly created array. Copying of individual elements is done by using - * the elementClass copy constructor to construct the individual member elements of the new - * array based on the corresponding elements of the source array. - * - * @param source The array to duplicate - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S copyInstance( - final S source) { - return _copyInstance(source); - } - - /** - * Copy a given array of elements to a newly created array. Copying of individual elements is done by using - * the elementClass copy constructor to construct the individual member elements of the new - * array based on the corresponding elements of the source array. - * - * @param lookup The lookup object to use when resolving constructors - * @param source The array to duplicate - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S copyInstance( - MethodHandles.Lookup lookup, - final S source) { - return _copyInstance(lookup, source, 0, source.getLength()); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - * - * @param source The array to copy from - * @param sourceOffset offset index, indicating where the source region to be copied begins - * @param count the number of elements to copy - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S copyInstance( - final S source, - final long sourceOffset, - final long count) { - return _copyInstance(source, sourceOffset, count); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - * - * @param lookup The lookup object to use when resolving constructors - * @param source The array to copy from - * @param sourceOffset offset index, indicating where the source region to be copied begins - * @param count the number of elements to copy - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - protected static , T> S copyInstance( - MethodHandles.Lookup lookup, - final S source, - final long sourceOffset, - final long count) { - return _copyInstance(lookup, source, new long[]{sourceOffset}, new long[]{count}); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - *

- * This form is useful [only] for copying partial ranges from nested StructuredArrays. - *

- * @param source The array to copy from - * @param sourceOffsets offset indexes, indicating where the source region to be copied begins at each - * StructuredArray nesting depth - * @param counts the number of elements to copy at each StructuredArray nesting depth - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - @SuppressWarnings("unchecked") - protected static , T> S copyInstance( - final S source, - final long[] sourceOffsets, - final long[] counts) { - return _copyInstance(source, sourceOffsets, counts); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - *

- * This form is useful [only] for copying partial ranges from nested StructuredArrays. - *

- * @param lookup The lookup object to use when resolving constructors - * @param source The array to copy from - * @param sourceOffsets offset indexes, indicating where the source region to be copied begins at each - * StructuredArray nesting depth - * @param counts the number of elements to copy at each StructuredArray nesting depth - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - @SuppressWarnings("unchecked") - protected static , T> S copyInstance( - MethodHandles.Lookup lookup, - final S source, - final long[] sourceOffsets, - final long[] counts) { - return _copyInstance(lookup, source, sourceOffsets, counts); - } - - protected ProtectedStructuredArray() { - } - - protected ProtectedStructuredArray(ProtectedStructuredArray sourceArray) { - // Support copy constructor. When we get here, everything is already set up for the regular - // (default) construction path to perform the required copy. - // Copying will actually be done according to the CtorAndArgsProvider and context already supplied, - // with top-most source array being (already) passed as the contextCookie in the builder's - // construction context, and copying proceeding using the context indices and the supplied - // contextCookie provided by each CtorAndArgsProvider to figure out individual sources. - super(sourceArray); - } - - /** - * Get the length (number of elements) of the array. - * - * @return the number of elements in the array. - */ - protected long getLength() { - return super.getLength(); - } - - - /** - * Get the {@link Class} of elements stored in the array. - * - * @return the {@link Class} of elements stored in the array. - */ - protected Class getElementClass() { - return super.getElementClass(); - } - - /** - * Get the array model - * @return a model of this array - */ - protected StructuredArrayModel, T> getArrayModel() { - @SuppressWarnings("unchecked") - StructuredArrayModel, T> model = - (StructuredArrayModel, T>) super.getArrayModel(); - return model; - } - - /** - * Get a reference to an element in a single dimensional array, using a long index. - * - * @param index of the element to retrieve. - * @return a reference to the indexed element. - */ - protected T get(final long index) throws IllegalArgumentException { - return super.get(index); - } - - /** - * Get a reference to an element in a single dimensional array, using an int index. - * - * @param index of the element to retrieve. - * @return a reference to the indexed element. - */ - protected T get(final int index) throws IllegalArgumentException { - return super.get(index); - } - - // - // - // Shallow copy support: - // - // - - /** - * Shallow copy a region of element object contents from one array to the other. - *

- * shallowCopy will copy all fields from each of the source elements to the corresponding fields in each - * of the corresponding destination elements. If the same array is both the src and dst then the copy will - * happen as if a temporary intermediate array was used. - * - * @param src array to copy - * @param srcOffset offset index in src where the region begins - * @param dst array into which the copy should occur - * @param dstOffset offset index in the dst where the region begins - * @param count of structure elements to copy - * @param The class of the arrays - * @param The class of the array elements - * @throws IllegalArgumentException if the source and destination array element types are not identical, or if - * the source or destination arrays have nested StructuredArrays within them, or if final fields are discovered - * and all allowFinalFieldOverwrite is not true. - */ - protected static , T> void shallowCopy( - final S src, - final long srcOffset, - final S dst, - final long dstOffset, - final long count) { - _shallowCopy(src, srcOffset, dst, dstOffset, count); - } - - /** - * Shallow copy a region of element object contents from one array to the other. - *

- * shallowCopy will copy all fields from each of the source elements to the corresponding fields in each - * of the corresponding destination elements. If the same array is both the src and dst then the copy will - * happen as if a temporary intermediate array was used. - * - * If allowFinalFieldOverwrite is specified as true, even final fields will be copied. - * - * @param src array to copy - * @param srcOffset offset index in src where the region begins - * @param dst array into which the copy should occur - * @param dstOffset offset index in the dst where the region begins - * @param count of structure elements to copy. - * @param allowFinalFieldOverwrite allow final fields to be overwritten during a copy operation. - * @param The class of the arrays - * @param The class of the array elements - * @throws IllegalArgumentException if the source and destination array element types are not identical, or if - * the source or destination arrays have nested StructuredArrays within them, or if final fields are discovered - * and all allowFinalFieldOverwrite is not true. - */ - protected static , T> void shallowCopy( - final S src, - final long srcOffset, - final S dst, - final long dstOffset, - final long count, - final boolean allowFinalFieldOverwrite) { - _shallowCopy(src, srcOffset, dst, dstOffset, count, allowFinalFieldOverwrite); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedStructuredArrayBuilder.java b/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedStructuredArrayBuilder.java deleted file mode 100644 index c74543a..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ProtectedStructuredArrayBuilder.java +++ /dev/null @@ -1,395 +0,0 @@ -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A builder used for instantiating a {@link ProtectedStructuredArray}<T> - *

- * {@link ProtectedStructuredArrayBuilder} follows the commonly used builder pattern, and is useful for - * capturing the instantiation parameters of {@link ProtectedStructuredArray}s. - *

- *

- * {@link ProtectedStructuredArrayBuilder}s can be created for "flat" and "nested" {@link ProtectedStructuredArray} - * constructs, and can range from the simplest forms used when default constructors are employed, to forms that - * supply customized per-element construction arguments that can take construction context (such as index, - * containing array, and arbitrary data passed in a contextCookie) into account. - *

- * A simple example of using a {@link ProtectedStructuredArrayBuilder} to instantiate a ProtectedStructuredArray is: - *
- * ProtectedStructuredArray<MyElementClass> array =
- *      new StructuredArrayBuilder(ProtectedStructuredArray.class, MyElementClass.class, length).
- *          build();
- * 
- *

- * An example of passing specific (but identical) construction arguments to element constructors is: - *

- * Constructor<MyElementClass> constructor = MyElementClass.class.getConstructor(int.Class, int.Class);
- *
- * ProtectedStructuredArray<MyElementClass> array =
- *      new StructuredArrayBuilder(
- *          ProtectedStructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgs(constructor, initArg1, initArg2).
- *          build();
- * 
- * Some examples of providing per-element construction parameters that depend on construction context include: - *
- * Constructor<MyElementClass> constructor = MyElementClass.class.getConstructor(long.Class, long.Class);
- *
- * // Using a pre-constructed elementCtorAndArgsProvider:
- * ProtectedStructuredArray<MyElementClass> array =
- *      new StructuredArrayBuilder(
- *          ProtectedStructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgsProvider(myCtorAndArgsProvider).
- *          build();
- *
- * // Using a Lambda expression for elementCtorAndArgsProvider:
- * ProtectedStructuredArray<MyElementClass> array2 =
- *      new StructuredArrayBuilder(
- *          ProtectedStructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgsProvider(
- *              context -> new CtorAndArgs<MyElementClass>(
- *                  constructor, context.getIndex(), context.getIndex() * 2)
- *          ).
- *          build();
- *
- * // Using an anonymous class for elementCtorAndArgsProvider:
- * ProtectedStructuredArray<MyElementClass> array3 =
- *      new StructuredArrayBuilder(
- *          ProtectedStructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgsProvider(
- *              new CtorAndArgsProvider() {
- *                  {@literal @}Override
- *                  public CtorAndArgs getForContext(ConstructionContext context) throws NoSuchMethodException {
- *                      return new CtorAndArgs(constructor, context.getIndex(), context.getIndex() * 2);
- *                  }
- *              }
- *          ).
- *          build();
- * 
- * - * @param The class of the ProtectedStructuredArray that is to be instantiated by the builder - * @param The class of the elements in the ProtectedStructuredArray that is to be instantiated the builder - */ -public class ProtectedStructuredArrayBuilder, T> - extends AbstractStructuredArrayBuilder { - - /** - * Constructs a new {@link ProtectedStructuredArrayBuilder} object for creating arrays of type S with - * elements of type T, and the given length. - * - * Note: This constructor form cannot be used with an element type T that extends ProtectedStructuredArray. Use the - * constructor form {@link ProtectedStructuredArrayBuilder#ProtectedStructuredArrayBuilder(Class, ProtectedStructuredArrayBuilder, long)} - * to create builders that instantiate nested StructuredArrays. - * - * @param arrayClass The class of the array to be built by this builder - * @param elementClass The class of elements in the array to be built by this builder - * @param length The length of the array to be build by this builder - */ - public ProtectedStructuredArrayBuilder(final Class arrayClass, - final Class elementClass, - final long length) { - super(arrayClass, elementClass, length); - } - - /** - * Constructs a new {@link ProtectedStructuredArrayBuilder} object for creating arrays of type S with - * elements of type T, and the given length. - * - * Note: This constructor form cannot be used with an element type T that extends ProtectedStructuredArray. Use the - * constructor form {@link ProtectedStructuredArrayBuilder#ProtectedStructuredArrayBuilder(Class, ProtectedStructuredArrayBuilder, long)} - * to create builders that instantiate nested StructuredArrays. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayClass The class of the array to be built by this builder - * @param elementClass The class of elements in the array to be built by this builder - * @param length The length of the array to be build by this builder - */ - public ProtectedStructuredArrayBuilder(MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final long length) { - super(lookup, arrayClass, elementClass, length); - } - - /** - * Constructs a new {@link ProtectedStructuredArrayBuilder} object for creating arrays of the given array model. - * - * @param arrayModel The model of the array to be built by this builder - */ - public ProtectedStructuredArrayBuilder(final StructuredArrayModel arrayModel) { - super(arrayModel); - } - - /** - * Constructs a new {@link ProtectedStructuredArrayBuilder} object for creating arrays of the given array model. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayModel The model of the array to be built by this builder - */ - public ProtectedStructuredArrayBuilder(MethodHandles.Lookup lookup, - final StructuredArrayModel arrayModel) { - super(lookup, arrayModel); - } - - /** - * Constructs a new {@link ProtectedStructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends ProtectedStructuredArray, such that the - * arrays instantiated by this builder would include nested StructuredArrays. - * - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * StructuredArrays) - * @param length The length of the array to be build by this builder - * @param
The class or the subArray (should match T for the StructuredArrayBuilder) - * @param The element class in the subArray. - */ - public , E> ProtectedStructuredArrayBuilder(final Class arrayClass, - final ProtectedStructuredArrayBuilder subArrayBuilder, - final long length) { - super(arrayClass, subArrayBuilder, length); - } - - /** - * Constructs a new {@link ProtectedStructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends ProtectedStructuredArray, such that the - * arrays instantiated by this builder would include nested StructuredArrays. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * StructuredArrays) - * @param length The length of the array to be build by this builder - * @param The class or the subArray (should match T for the StructuredArrayBuilder) - * @param The element class in the subArray. - */ - public , E> ProtectedStructuredArrayBuilder( - MethodHandles.Lookup lookup, - final Class arrayClass, - final ProtectedStructuredArrayBuilder subArrayBuilder, - final long length) { - super(lookup, arrayClass, subArrayBuilder, length); - } - - /** - * Constructs a new {@link ProtectedStructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends AbstractPrimitiveArray, such that the - * arrays instantiated by this builder would include elements that are PrimitiveArrays. - * - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * subclassable PrimitiveArrays) - * @param length The length of the array to be build by this builder - * @param The class in the subArray (should match T for the StructuredArrayBuilder) - */ - public ProtectedStructuredArrayBuilder(final Class arrayClass, - final PrimitiveArrayBuilder subArrayBuilder, - final long length) { - super(arrayClass, subArrayBuilder, length); - } - - /** - * Constructs a new {@link ProtectedStructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends AbstractPrimitiveArray, such that the - * arrays instantiated by this builder would include elements that are PrimitiveArrays. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * subclassable PrimitiveArrays) - * @param length The length of the array to be build by this builder - * @param The class in the subArray (should match T for the StructuredArrayBuilder) - */ - public ProtectedStructuredArrayBuilder( - MethodHandles.Lookup lookup, - final Class arrayClass, - final PrimitiveArrayBuilder subArrayBuilder, - final long length) { - super(lookup, arrayClass, subArrayBuilder, length); - } - - /** - * Set the {@link CtorAndArgsProvider} used for determining the constructor and construction - * arguments used for each element in the array. The provider may use the specific element's - * construction context in determining the construction parameters. - * - * Note: This method overlaps in purpose with the alternate methods for controlling element - * construction. Namely {@link ProtectedStructuredArrayBuilder#elementCtorAndArgs(CtorAndArgs)} and - * {@link ProtectedStructuredArrayBuilder#elementCtorAndArgs(Constructor, Object...)}. - * - * @param ctorAndArgsProvider The provider used for determining the constructor and construction - * arguments used for each element in instantiated arrays - * @return The builder - */ - public ProtectedStructuredArrayBuilder elementCtorAndArgsProvider(final CtorAndArgsProvider ctorAndArgsProvider) { - return (ProtectedStructuredArrayBuilder) super.elementCtorAndArgsProvider(ctorAndArgsProvider); - } - - /** - * Set the {@link CtorAndArgs} to be used for all elements in the array. All elements will be constructed with - * the same constructor and the same arguments. - * - * Note: This method overlaps in purpose with the alternate methods for controlling element - * construction. Namely {@link ProtectedStructuredArrayBuilder#elementCtorAndArgsProvider(CtorAndArgsProvider)} and - * {@link ProtectedStructuredArrayBuilder#elementCtorAndArgs(Constructor, Object...)}. - * - * @param ctorAndArgs The constructor and arguments used for all elements in arrays - * @return The builder - */ - public ProtectedStructuredArrayBuilder elementCtorAndArgs(final CtorAndArgs ctorAndArgs) { - return (ProtectedStructuredArrayBuilder) super.elementCtorAndArgs(ctorAndArgs); - } - - /** - * Set the {@link Constructor} and construction arguments to be used for all elements in the array. - * All elements will be constructed with the same constructor and the same arguments. - * - * Note: This method overlaps in purpose with the alternate methods for controlling element - * construction. Namely {@link ProtectedStructuredArrayBuilder#elementCtorAndArgsProvider(CtorAndArgsProvider)} and - * {@link ProtectedStructuredArrayBuilder#elementCtorAndArgs(CtorAndArgs)}. - * - * @param constructor The constructor used for all elements in arrays - * @param args The construction arguments supplied for the constructor, used for all elements in the array - * @return The builder - */ - public ProtectedStructuredArrayBuilder elementCtorAndArgs(final Constructor constructor, final Object... args) { - return (ProtectedStructuredArrayBuilder) super.elementCtorAndArgs(constructor, args); - } - - /** - * Set the {@link CtorAndArgs} to be used in constructing arrays. - * Setting the means for array construction is Required if the array class (S) does not support a - * default constructor, or if a non-default construction of the array instance is needed. - * - * @param arrayCtorAndArgs The constructor and arguments used for constructing arrays - * @return The builder - */ - public ProtectedStructuredArrayBuilder arrayCtorAndArgs(final CtorAndArgs arrayCtorAndArgs) { - return (ProtectedStructuredArrayBuilder) super.arrayCtorAndArgs(arrayCtorAndArgs); - } - - /** - * Set the {@link Constructor} and construction arguments to be used in constructing arrays. - * Setting the means for array construction is Required if the array class (S) does not support a - * default constructor, or if a non-default construction of the array instance is needed. - * - * @param constructor The constructor used for constructing arrays - * @param args The construction arguments supplied for the constructor - * @return The builder - */ - public ProtectedStructuredArrayBuilder arrayCtorAndArgs(final Constructor constructor, final Object... args) { - return (ProtectedStructuredArrayBuilder) super.arrayCtorAndArgs(constructor, args); - } - - /** - * Set the (opaque) contextCookie object associated with this builder. This contextCookie object will be - * set in {@link ConstructionContext} object passed to the element - * {@link CtorAndArgsProvider} provider for each element in instantiated arrays. - * - * @param contextCookie the contextCookie object - * @return The builder - */ - public ProtectedStructuredArrayBuilder contextCookie(final Object contextCookie) { - return (ProtectedStructuredArrayBuilder) super.contextCookie(contextCookie); - } - - /** - * Resolve any not-yet-resolved constructor information needed by this builder. Calling resolve() is not - * necessary ahead of building, but it is useful for ensuring resolution works ahead of actual building - * attempts. - * - * @return This builder - * @throws IllegalArgumentException if the array constructor or element constructor fail to resolve given - * the current information in the builder - */ - public ProtectedStructuredArrayBuilder resolve() { - return (ProtectedStructuredArrayBuilder) super.resolve(); - } - - /** - * Build a {@link ProtectedStructuredArray} according to the information captured in this builder - * @return A newly instantiated {@link ProtectedStructuredArray} - * - * @throws IllegalArgumentException if the array constructor or element constructor fail to resolve given - * the current information in the builder - */ - public S build() throws IllegalArgumentException { - return super.build(); - } - - /** - * Get the {@link StructuredArrayModel} that describes the arrays built by this builder - * - * @return The {@link StructuredArrayModel} that describes the arrays built by this builder - */ - public StructuredArrayModel getArrayModel() { - return super.getArrayModel(); - } - - /** - * Get the {@link ProtectedStructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null - * - * @return The {@link ProtectedStructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null if the array element type T does not extend {@link ProtectedStructuredArray}. - */ - public ProtectedStructuredArrayBuilder getStructuredSubArrayBuilder() { - return (ProtectedStructuredArrayBuilder) super.getStructuredSubArrayBuilder(); - } - - /** - * Get the {@link ProtectedStructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null - * - * @return The {@link ProtectedStructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null if the array element type T does not extend {@link ProtectedStructuredArray}. - */ - public PrimitiveArrayBuilder getPrimitiveSubArrayBuilder() { - return super.getPrimitiveSubArrayBuilder(); - } - - /** - * Get the {@link CtorAndArgs} describing the constructor and arguments used to instantiate arrays with - * this builder. May be null if non of {@link ProtectedStructuredArrayBuilder#arrayCtorAndArgs}, - * {@link ProtectedStructuredArrayBuilder#resolve()} or - * {@link ProtectedStructuredArrayBuilder#build()} have been called yet. - * @return The {@link CtorAndArgs} describing the constructor and arguments used to instantiate arrays with - * this builder. - */ - public CtorAndArgs getArrayCtorAndArgs() { - return super.getArrayCtorAndArgs(); - } - - /** - * Get the {@link CtorAndArgsProvider} which provides the constructor and arguments used to construct - * individual elements of arrays instantiated with this builder. May be null if non of - * {@link ProtectedStructuredArrayBuilder#elementCtorAndArgsProvider}, - * {@link ProtectedStructuredArrayBuilder#elementCtorAndArgs}, - * {@link ProtectedStructuredArrayBuilder#resolve} or - * {@link ProtectedStructuredArrayBuilder#build} have been called yet. - * @return The {@link CtorAndArgsProvider} which provides the constructor and arguments used to construct - * individual elements of arrays instantiated with this builder - */ - public CtorAndArgsProvider getElementCtorAndArgsProvider() { - return super.getElementCtorAndArgsProvider(); - } - - /** - * Get the (opaque) contextCookie object associated with this builder. This contextCookie object will be - * set in {@link ConstructionContext} object passed to the element - * {@link CtorAndArgsProvider} provider for each element in instantiated arrays. - * @return The (opaque) contextCookie object associated with this builder - */ - public Object getContextCookie() { - return super.getContextCookie(); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/ReferenceArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/ReferenceArray.java deleted file mode 100644 index 2b15549..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/ReferenceArray.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A subclassable array of object references. - * - * {@link ProtectedReferenceArray} is designed with semantics specifically chosen and restricted such that - * a "flat" memory layout of the implemented data structure would be possible on optimizing JVMs. While fully - * functional on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates dead-reckoning (as - * opposed to de-referenced) access to elements - * - * @param The reference type - */ - -public class ReferenceArray extends AbstractReferenceArray { - - /** - * Get a reference to a T[] that represents the contents of this array. Will throw an - * exception if array is too long to represent as a T[]. - * - * @return a reference to a T[] that represents the contents of this array - * @throws IllegalStateException if array is too long to represent as a T[] - */ - public T[] asArray() throws IllegalStateException { - return _asArray(); - } - - /** - * Get the length of the array - * - * @return the length of the array - */ - public long getLength() { - return _getLength(); - } - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public T get(final int index) { - return _get(index); - } - - - /** - * Get the value of an element in the array. - * - * @param index the index of the element - * @return the value of the element at the given index - */ - public T get(final long index) { - return _get(index); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final int index, final T value) { - _set(index, value); - } - - /** - * set the value of an element in the array. - * - * @param index the index of the element to set - * @param value the value to assign to the element - */ - public void set(final long index, final T value) { - _set(index, value); - } - - /** - * Default constructor - */ - public ReferenceArray() { - super(); - } - - /** - * Copy constructor - * - * @param sourceArray the array to copy - */ - public ReferenceArray(ReferenceArray sourceArray) { - super(sourceArray); - } - - /** - * Create a new instance of ReferenceArray<T> with a given length. - * - * @param length the length of the array - * @param the reference type - * @return A newly created ReferenceArray<T> - */ - public static ReferenceArray newInstance(final long length) { - @SuppressWarnings("unchecked") - ReferenceArray referenceArray = _newInstance(noLookup, ReferenceArray.class, length); - return referenceArray; - } - - /** - * Create a new instance of <A extends {@link ReferenceArray}<T>> with a given length. - * - * @param arrayClass The class of the array to be created (extends ReferenceArray<T>) - * @param length the length of the array. - * @param the reference type - * @param The class of the array to be created (extends ReferenceArray<T>) - * @return a new instance of <A extends {@link ReferenceArray}<T>> with a given length - */ - public static > A newInstance( - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(noLookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ReferenceArray}<T>> with a given length. - * - * @param lookup The lookup object to use for accessing the array's constructor - * @param arrayClass The class of the array to be created (extends ReferenceArray<T>) - * @param length the length of the array. - * @param the reference type - * @param The class of the array to be created (extends ReferenceArray<T>) - * @return a new instance of <A extends {@link ReferenceArray}<T>> with a given length - */ - public static > A newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final long length) { - return AbstractPrimitiveArray._newInstance(lookup, arrayClass, length); - } - - /** - * Create a new instance of <A extends {@link ReferenceArray}> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayCtorAndArgs for creating the array - * @param The class of the array to be created (extends ReferenceArray) - * @return a new instance of <A extends {@link ReferenceArray}> - */ - public static A newInstance( - final CtorAndArgs arrayCtorAndArgs, - final long length) { - return AbstractPrimitiveArray._newInstance(arrayCtorAndArgs, length); - } - - /** - * Create a new instance of <A extends {@link ReferenceArray}<T>> with a given length, - * array constructor, and array constructor arguments. - * - * @param length The length of the array. - * @param arrayConstructor The array constructor to use - * @param arrayConstructorArgs The arguments to pass to the array constructor - * @param the reference type - * @param The class of the array to be created (extends ReferenceArray<T>) - * @return a new instance of <A extends {@link ReferenceArray}<T>> - */ - public static > A newInstance( - final long length, - final Constructor arrayConstructor, - final Object... arrayConstructorArgs) { - return AbstractPrimitiveArray._newInstance(length, arrayConstructor, arrayConstructorArgs); - } - - /** - * Create a new <A extends {@link ReferenceArray}<T>> instance, using a copy constructor to - * replicate the contents of the given source array - * @param source The array to replicate - * @param The class of the array to be created (extends ReferenceArray<T>) - * @param The class of the element in the array to be created - * @return a new instance of <A extends {@link ReferenceArray}<T>> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static > A copyInstance(A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(noLookup, source); - } - - /** - * Create a new <A extends {@link ReferenceArray}<T>> instance, using a copy constructor to - * replicate the contents of the given source array - * @param lookup The lookup object to use for accessing the array's constructor - * @param source The array to replicate - * @param The class of the array to be created (extends ReferenceArray<T>) - * @param The class of the element in the array to be created - * @return a new instance of <A extends {@link ReferenceArray}<T>> copied from the source array - * @throws NoSuchMethodException if <A> does not have a copy constructor - */ - public static > A copyInstance( - MethodHandles.Lookup lookup, - A source) throws NoSuchMethodException { - return AbstractPrimitiveArray._copyInstance(lookup, source); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/StructuredArray.java b/ObjectLayout/src/main/java/org/ObjectLayout/StructuredArray.java deleted file mode 100644 index 3b56f02..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/StructuredArray.java +++ /dev/null @@ -1,755 +0,0 @@ -/* - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Array; -import java.util.Collection; -import java.util.Iterator; -import java.util.NoSuchElementException; - -/** - * An array of non-replaceable objects. - *

- * A structured array contains array element objects of a fixed (at creation time, per array instance) class, - * and can support elements of any class that provides accessible constructors. The elements in a StructuredArray - * are all allocated and constructed at array creation time, and individual elements cannot be removed or - * replaced after array creation. Array elements can be accessed using an index-based accessor methods in - * the form of {@link StructuredArray#get}() using either int or long indices. Individual element contents - * can then be accessed and manipulated using any and all operations supported by the member element's class. - *

- * While simple creation of default-constructed elements and fixed constructor parameters are available through - * the newInstance factory methods, supporting arbitrary member types requires a wider range of construction - * options. The {@link CtorAndArgsProvider} API provides for array creation with arbitrary, user-supplied - * constructors and arguments, the selection of which can take the element index and construction context - * into account. - *

- * StructuredArray is designed with semantics specifically chosen and restricted such that a "flat" memory - * layout of the implemented data structure would be possible on optimizing JVMs. Doing so provides for the - * possibility of matching access speed benefits that exist in data structures with similar semantics that - * are supported in other languages (e.g. an array of structs in C-like languages). While fully functional - * on all JVM implementation (of Java SE 7 and above), the semantics are such that a JVM may transparently - * optimise the implementation to provide a compact contiguous layout that facilitates consistent stride - * based memory access and dead-reckoning (as opposed to de-referenced) access to elements - * - * @param The class of the array elements - */ -public class StructuredArray extends AbstractStructuredArray implements Iterable { - - // Single-dimensional newInstance forms: - - /** - * Create an array of length elements, each containing an element object of - * type elementClass. Using the elementClass's default constructor. - * - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array elements - * @return The newly created array - */ - public static StructuredArray newInstance( - final Class elementClass, - final long length) { - @SuppressWarnings("unchecked") - StructuredArray instance = _newInstance(StructuredArray.class, elementClass, length); - return instance; - } - - /** - * Create an array of length elements, each containing an element object of - * type elementClass. Using the elementClass's default constructor. - * - * @param lookup The lookup object to use when resolving constructors - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array elements - * @return The newly created array - */ - public static StructuredArray newInstance( - MethodHandles.Lookup lookup, - final Class elementClass, - final long length) { - @SuppressWarnings("unchecked") - StructuredArray instance = _newInstance(lookup, StructuredArray.class, elementClass, length); - return instance; - } - - /** - * Create an arrayClass array of length elements of - * type elementClass. Using the elementClass's default constructor. - * - * @param arrayClass of the array to create - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - final Class arrayClass, - final Class elementClass, - final long length) { - return _newInstance(arrayClass, elementClass, length); - } - - /** - * Create an arrayClass array of length elements of - * type elementClass. Using the elementClass's default constructor. - * - * @param lookup The lookup object to use when resolving constructors - * @param arrayClass of the array to create - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final long length) { - return _newInstance(lookup, arrayClass, elementClass, length); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use elementClass's default constructor. - * - * @param arrayCtorAndArgs for creating the array - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - final CtorAndArgs arrayCtorAndArgs, - final Class elementClass, - final long length) { - return _newInstance(arrayCtorAndArgs, elementClass, length); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use elementClass's default constructor. - * - * @param lookup The lookup object to use when resolving constructors - * @param arrayCtorAndArgs for creating the array - * @param elementClass of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - MethodHandles.Lookup lookup, - final CtorAndArgs arrayCtorAndArgs, - final Class elementClass, - final long length) { - return _newInstance(lookup, arrayCtorAndArgs, elementClass, length); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use elementClass's default constructor. - * - * @param arrayCtorAndArgs for creating the array - * @param elementCtorAndArgs of each element in the array - * @param length of the array to create - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - final CtorAndArgs arrayCtorAndArgs, - final CtorAndArgs elementCtorAndArgs, - final long length) { - return _newInstance(arrayCtorAndArgs, elementCtorAndArgs, length); - } - - /** - * Create an array of length elements of type elementClass. Use constructor and - * arguments supplied (on a potentially per element index basis) by the specified - * ctorAndArgsProvider to construct and initialize each element. - * - * @param elementClass of each element in the array - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param length of the array to create - * @param The class of the array elements - * @return The newly created array - */ - public static StructuredArray newInstance( - final Class elementClass, - final CtorAndArgsProvider ctorAndArgsProvider, - final long length) { - @SuppressWarnings("unchecked") - StructuredArray instance = _newInstance(StructuredArray.class, elementClass, length, ctorAndArgsProvider); - return instance; - } - - /** - * Create an arrayClass array of length elements, each containing an element object of - * type elementClass. Use constructor and arguments supplied (on a potentially - * per element index basis) by the specified ctorAndArgsProvider to construct and initialize - * each element. - * - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param length of the array to create - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - final Class arrayClass, - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - return _newInstance(arrayClass, elementClass, length, ctorAndArgsProvider); - } - - /** - * Create an arrayClass array of length elements, each containing an element object of - * type elementClass. Use constructor and arguments supplied (on a potentially - * per element index basis) by the specified ctorAndArgsProvider to construct and initialize - * each element. - * - * @param lookup The lookup object to use when resolving constructors - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param length of the array to create - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - return _newInstance(lookup, arrayClass, elementClass, length, ctorAndArgsProvider); - } - - /** - * Create an arrayCtorAndArgs.getConstructor().getDeclaringClass() array of length - * elements of type elementClass. Use constructor and arguments - * supplied (on a potentially per element index basis) by the specified ctorAndArgsProvider - * to construct and initialize each element. - * - * @param arrayCtorAndArgs of the array to create - * @param elementClass of each element in the array - * @param length of the array to create - * @param ctorAndArgsProvider produces element constructors [potentially] on a per element basis - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - final CtorAndArgs arrayCtorAndArgs, - final Class elementClass, - final long length, - final CtorAndArgsProvider ctorAndArgsProvider) { - return _newInstance(arrayCtorAndArgs, elementClass, length, ctorAndArgsProvider); - } - - /** - * Create a <S extends StructuredArray<T>> array instance with elements copied from a source - * collection. - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param sourceCollection provides details for building the array - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - final Class arrayClass, - final Class elementClass, - final Collection sourceCollection) { - return _newInstance(arrayClass, elementClass, sourceCollection); - } - - /** - * Create a <S extends StructuredArray<T>> array instance with elements copied from a source - * collection. - * @param lookup The lookup object to use when resolving constructors - * @param arrayClass of the array to create. - * @param elementClass of each element in the array - * @param sourceCollection provides details for building the array - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final Collection sourceCollection) { - return _newInstance(lookup, arrayClass, elementClass, sourceCollection); - } - - /** - * Create a <S extends StructuredArray<T>> array instance according to the details provided in the - * arrayBuilder. - * @param arrayBuilder provides details for building the array - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S newInstance( - final StructuredArrayBuilder arrayBuilder) { - return _newInstance(arrayBuilder); - } - - /** - * Copy a given array of elements to a newly created array. Copying of individual elements is done by using - * the elementClass copy constructor to construct the individual member elements of the new - * array based on the corresponding elements of the source array. - * - * @param source The array to duplicate - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S copyInstance( - final S source) { - return _copyInstance(source); - } - - /** - * Copy a given array of elements to a newly created array. Copying of individual elements is done by using - * the elementClass copy constructor to construct the individual member elements of the new - * array based on the corresponding elements of the source array. - * - * @param lookup The lookup object to use when resolving constructors - * @param source The array to duplicate - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S copyInstance( - MethodHandles.Lookup lookup, - final S source) { - return _copyInstance(lookup, source, 0, source.getLength()); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - * - * @param source The array to copy from - * @param sourceOffset offset index, indicating where the source region to be copied begins - * @param count the number of elements to copy - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S copyInstance( - final S source, - final long sourceOffset, - final long count) { - return _copyInstance(source, sourceOffset, count); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - * - * @param lookup The lookup object to use when resolving constructors - * @param source The array to copy from - * @param sourceOffset offset index, indicating where the source region to be copied begins - * @param count the number of elements to copy - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - public static , T> S copyInstance( - MethodHandles.Lookup lookup, - final S source, - final long sourceOffset, - final long count) { - return _copyInstance(lookup, source, new long[]{sourceOffset}, new long[]{count}); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - *

- * This form is useful [only] for copying partial ranges from nested StructuredArrays. - *

- * @param source The array to copy from - * @param sourceOffsets offset indexes, indicating where the source region to be copied begins at each - * StructuredArray nesting depth - * @param counts the number of elements to copy at each StructuredArray nesting depth - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - @SuppressWarnings("unchecked") - public static , T> S copyInstance( - final S source, - final long[] sourceOffsets, - final long[] counts) { - return _copyInstance(source, sourceOffsets, counts); - } - - /** - * Copy a range from an array of elements to a newly created array. Copying of individual elements is done - * by using the elementClass copy constructor to construct the individual member elements of - * the new array based on the corresponding elements of the source array. - *

- * This form is useful [only] for copying partial ranges from nested StructuredArrays. - *

- * @param lookup The lookup object to use when resolving constructors - * @param source The array to copy from - * @param sourceOffsets offset indexes, indicating where the source region to be copied begins at each - * StructuredArray nesting depth - * @param counts the number of elements to copy at each StructuredArray nesting depth - * @param The class of the array to be created - * @param The class of the array elements - * @return The newly created array - */ - @SuppressWarnings("unchecked") - public static , T> S copyInstance( - MethodHandles.Lookup lookup, - final S source, - final long[] sourceOffsets, - final long[] counts) { - return _copyInstance(lookup, source, sourceOffsets, counts); - } - - protected StructuredArray() { - } - - protected StructuredArray(StructuredArray sourceArray) { - // Support copy constructor. When we get here, everything is already set up for the regular - // (default) construction path to perform the required copy. - // Copying will actually be done according to the CtorAndArgsProvider and context already supplied, - // with top-most source array being (already) passed as the contextCookie in the builder's - // construction context, and copying proceeding using the context indices and the supplied - // contextCookie provided by each CtorAndArgsProvider to figure out individual sources. - super(sourceArray); - } - - /** - * Get the length (number of elements) of the array. - * - * @return the number of elements in the array. - */ - public long getLength() { - return super.getLength(); - } - - - /** - * Get the {@link Class} of elements stored in the array. - * - * @return the {@link Class} of elements stored in the array. - */ - public Class getElementClass() { - return super.getElementClass(); - } - - /** - * Get the array model - * @return a model of this array - */ - public StructuredArrayModel, T> getArrayModel() { - @SuppressWarnings("unchecked") - StructuredArrayModel, T> model = - (StructuredArrayModel, T>) super.getArrayModel(); - return model; - } - - /** - * Get a reference to an element in a single dimensional array, using a long index. - * - * @param index of the element to retrieve. - * @return a reference to the indexed element. - */ - public T get(final long index) throws IllegalArgumentException { - return super.get(index); - } - - /** - * Get a reference to an element in a single dimensional array, using an int index. - * - * @param index of the element to retrieve. - * @return a reference to the indexed element. - */ - public T get(final int index) throws IllegalArgumentException { - return super.get(index); - } - - // - // - // Collection interface support: - // - // - - /** - * Return a representation of this StructuredArray as a Collection. Will throw an exception if array is - * too long to represent as a Collection. - * - * @return a representation of this StructuredArray as a Collection - * @throws IllegalStateException if array is too long to represent as a Collection - */ - public Collection asCollection() throws IllegalStateException { - long length = getLength(); - if (length > Integer.MAX_VALUE) { - throw new IllegalStateException( - "Cannot make Collection from array with more than Integer.MAX_VALUE elements (" + length + ")"); - } - return new CollectionWrapper<>(this); - } - - class CollectionWrapper implements Collection { - StructuredArray array; - - CollectionWrapper(StructuredArray array) { - this.array = array; - } - - @Override - public int size() { - return (int) array.getLength(); - } - - @Override - public boolean isEmpty() { - return array.getLength() != 0; - } - - @Override - public boolean contains(Object o) { - for (E element : array) { - if (element == o) { - return true; - } - } - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public Iterator iterator() { - return array.iterator(); - } - - @Override - public Object[] toArray() { - Object[] toArray = new Object[(int) array.getLength()]; - for (int i = 0; i < toArray.length; i++) { - toArray[i] = array.get(i); - } - return toArray; - } - - @Override - public T1[] toArray(T1[] a) { - int newLength = (int) array.getLength(); - Class newType = a.getClass(); - @SuppressWarnings("unchecked") - T1[] toArray = (newType == Object[].class) - ? (T1[]) new Object[newLength] - : (T1[]) Array.newInstance(newType.getComponentType(), newLength); - - for (int i = 0; i < toArray.length; i++) { - @SuppressWarnings("unchecked") - T1 e = (T1) array.get(i); - toArray[i] = e; - } - return toArray; - } - - @Override - public boolean add(E e) { - throw new UnsupportedOperationException("StructuredArrays are immutable collections"); - } - - @Override - public boolean remove(Object o) { - throw new UnsupportedOperationException("StructuredArrays are immutable collections"); - } - - @Override - public boolean containsAll(Collection otherCollection) { - for (Object otherElement : otherCollection) { - if (!contains(otherElement)) { - return false; - } - } - return true; - } - - @Override - public boolean addAll(Collection c) { - throw new UnsupportedOperationException("StructuredArrays are immutable collections"); - } - - @Override - public boolean removeAll(Collection c) { - throw new UnsupportedOperationException("StructuredArrays are immutable collections"); - } - - @Override - public boolean retainAll(Collection c) { - throw new UnsupportedOperationException("StructuredArrays are immutable collections"); - } - - @Override - public void clear() { - throw new UnsupportedOperationException("StructuredArrays are immutable collections"); - } - } - - // - // - // Iterable interface support: - // - // - - /** - * {@inheritDoc} - */ - public ElementIterator iterator() { - return new ElementIterator(); - } - - /** - * Specialised {@link java.util.Iterator} with the ability to be {@link #reset()} enabling reuse. - */ - public class ElementIterator implements Iterator { - private long cursor = 0; - private final long initialOffset; - private final long end; - - public ElementIterator() { - this(0, getLength()); - } - - public ElementIterator(long offset, long length) { - this.initialOffset = offset; - this.cursor = offset; - this.end = offset + length; - } - - /** - * {@inheritDoc} - */ - public boolean hasNext() { - return cursor < end; - } - - /** - * {@inheritDoc} - */ - public T next() { - if (cursor >= end) { - throw new NoSuchElementException(); - } - - final T element = get(cursor); - - cursor++; - - return element; - } - - /** - * Remove operation is not supported on {@link StructuredArray}s. - * - * @throws UnsupportedOperationException if called. - */ - public void remove() { - throw new UnsupportedOperationException(); - } - - /** - * Reset to the beginning of the collection enabling reuse of the iterator. - */ - public void reset() { - cursor = initialOffset; - } - - public long getCursor() { - return cursor; - } - } - - // - // - // Shallow copy support: - // - // - - /** - * Shallow copy a region of element object contents from one array to the other. - *

- * shallowCopy will copy all fields from each of the source elements to the corresponding fields in each - * of the corresponding destination elements. If the same array is both the src and dst then the copy will - * happen as if a temporary intermediate array was used. - * - * @param src array to copy - * @param srcOffset offset index in src where the region begins - * @param dst array into which the copy should occur - * @param dstOffset offset index in the dst where the region begins - * @param count of structure elements to copy - * @param The class of the arrays - * @param The class of the array elements - * @throws IllegalArgumentException if the source and destination array element types are not identical, or if - * the source or destination arrays have nested StructuredArrays within them, or if final fields are discovered - * and all allowFinalFieldOverwrite is not true. - */ - public static , T> void shallowCopy( - final S src, - final long srcOffset, - final S dst, - final long dstOffset, - final long count) { - _shallowCopy(src, srcOffset, dst, dstOffset, count); - } - - /** - * Shallow copy a region of element object contents from one array to the other. - *

- * shallowCopy will copy all fields from each of the source elements to the corresponding fields in each - * of the corresponding destination elements. If the same array is both the src and dst then the copy will - * happen as if a temporary intermediate array was used. - * - * If allowFinalFieldOverwrite is specified as true, even final fields will be copied. - * - * @param src array to copy - * @param srcOffset offset index in src where the region begins - * @param dst array into which the copy should occur - * @param dstOffset offset index in the dst where the region begins - * @param count of structure elements to copy. - * @param allowFinalFieldOverwrite allow final fields to be overwritten during a copy operation. - * @param The class of the arrays - * @param The class of the array elements - * @throws IllegalArgumentException if the source and destination array element types are not identical, or if - * the source or destination arrays have nested StructuredArrays within them, or if final fields are discovered - * and all allowFinalFieldOverwrite is not true. - */ - public static , T> void shallowCopy( - final S src, - final long srcOffset, - final S dst, - final long dstOffset, - final long count, - final boolean allowFinalFieldOverwrite) { - _shallowCopy(src, srcOffset, dst, dstOffset, count, allowFinalFieldOverwrite); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/StructuredArrayBuilder.java b/ObjectLayout/src/main/java/org/ObjectLayout/StructuredArrayBuilder.java deleted file mode 100644 index e9d873b..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/StructuredArrayBuilder.java +++ /dev/null @@ -1,394 +0,0 @@ -package org.ObjectLayout; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -/** - * A builder used for instantiating a {@link StructuredArray}<T> - *

- * {@link org.ObjectLayout.StructuredArrayBuilder} follows the commonly used builder pattern, and is useful for - * capturing the instantiation parameters of {@link StructuredArray}s. - *

- *

- * {@link org.ObjectLayout.StructuredArrayBuilder}s can be created for "flat" and "nested" {@link StructuredArray} - * constructs, and can range from the simplest forms used when default constructors are employed, to forms that - * supply customized per-element construction arguments that can take construction context (such as index, - * containing array, and arbitrary data passed in a contextCookie) into account. - *

- * A simple example of using a {@link org.ObjectLayout.StructuredArrayBuilder} to instantiate a StructuredArray is: - *
- * StructuredArray<MyElementClass> array =
- *      new StructuredArrayBuilder(StructuredArray.class, MyElementClass.class, length).
- *          build();
- * 
- *

- * An example of passing specific (but identical) construction arguments to element constructors is: - *

- * Constructor<MyElementClass> constructor = MyElementClass.class.getConstructor(int.Class, int.Class);
- *
- * StructuredArray<MyElementClass> array =
- *      new StructuredArrayBuilder(
- *          StructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgs(constructor, initArg1, initArg2).
- *          build();
- * 
- * Some examples of providing per-element construction parameters that depend on construction context include: - *
- * Constructor<MyElementClass> constructor = MyElementClass.class.getConstructor(long.Class, long.Class);
- *
- * // Using a pre-constructed elementCtorAndArgsProvider:
- * StructuredArray<MyElementClass> array =
- *      new StructuredArrayBuilder(
- *          StructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgsProvider(myCtorAndArgsProvider).
- *          build();
- *
- * // Using a Lambda expression for elementCtorAndArgsProvider:
- * StructuredArray<MyElementClass> array2 =
- *      new StructuredArrayBuilder(
- *          StructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgsProvider(
- *              context -> new CtorAndArgs<MyElementClass>(
- *                  constructor, context.getIndex(), context.getIndex() * 2)
- *          ).
- *          build();
- *
- * // Using an anonymous class for elementCtorAndArgsProvider:
- * StructuredArray<MyElementClass> array3 =
- *      new StructuredArrayBuilder(
- *          StructuredArray.class,
- *          MyElementClass.class,
- *          length).
- *          elementCtorAndArgsProvider(
- *              new CtorAndArgsProvider() {
- *                  {@literal @}Override
- *                  public CtorAndArgs getForContext(ConstructionContext context) throws NoSuchMethodException {
- *                      return new CtorAndArgs(constructor, context.getIndex(), context.getIndex() * 2);
- *                  }
- *              }
- *          ).
- *          build();
- * 
- * - * @param The class of the StructuredArray that is to be instantiated by the builder - * @param The class of the elements in the StructuredArray that is to be instantiated the builder - */ -public class StructuredArrayBuilder, T> - extends AbstractStructuredArrayBuilder { - - /** - * Constructs a new {@link StructuredArrayBuilder} object for creating arrays of type S with - * elements of type T, and the given length. - * - * Note: This constructor form cannot be used with an element type T that extends StructuredArray. Use the - * constructor form {@link StructuredArrayBuilder#StructuredArrayBuilder(Class, StructuredArrayBuilder, long)} - * to create builders that instantiate nested StructuredArrays. - * - * @param arrayClass The class of the array to be built by this builder - * @param elementClass The class of elements in the array to be built by this builder - * @param length The length of the array to be build by this builder - */ - public StructuredArrayBuilder(final Class arrayClass, - final Class elementClass, - final long length) { - super(arrayClass, elementClass, length); - } - - /** - * Constructs a new {@link StructuredArrayBuilder} object for creating arrays of type S with - * elements of type T, and the given length. - * - * Note: This constructor form cannot be used with an element type T that extends StructuredArray. Use the - * constructor form {@link StructuredArrayBuilder#StructuredArrayBuilder(Class, StructuredArrayBuilder, long)} - * to create builders that instantiate nested StructuredArrays. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayClass The class of the array to be built by this builder - * @param elementClass The class of elements in the array to be built by this builder - * @param length The length of the array to be build by this builder - */ - public StructuredArrayBuilder(MethodHandles.Lookup lookup, - final Class arrayClass, - final Class elementClass, - final long length) { - super(lookup, arrayClass, elementClass, length); - } - - /** - * Constructs a new {@link StructuredArrayBuilder} object for creating arrays of the given array model. - * - * @param arrayModel The model of the array to be built by this builder - */ - public StructuredArrayBuilder(final StructuredArrayModel arrayModel) { - super(arrayModel); - } - - /** - * Constructs a new {@link StructuredArrayBuilder} object for creating arrays of the given array model. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayModel The model of the array to be built by this builder - */ - public StructuredArrayBuilder(MethodHandles.Lookup lookup, - final StructuredArrayModel arrayModel) { - super(lookup, arrayModel); - } - - /** - * Constructs a new {@link StructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends StructuredArray, such that the - * arrays instantiated by this builder would include nested StructuredArrays. - * - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * StructuredArrays) - * @param length The length of the array to be build by this builder - * @param
The class or the subArray (should match T for the StructuredArrayBuilder) - * @param The element class in the subArray. - */ - public , E> StructuredArrayBuilder(final Class arrayClass, - final StructuredArrayBuilder subArrayBuilder, - final long length) { - super(arrayClass, subArrayBuilder, length); - } - - /** - * Constructs a new {@link StructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends StructuredArray, such that the - * arrays instantiated by this builder would include nested StructuredArrays. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * StructuredArrays) - * @param length The length of the array to be build by this builder - * @param The class or the subArray (should match T for the StructuredArrayBuilder) - * @param The element class in the subArray. - */ - public , E> StructuredArrayBuilder( - MethodHandles.Lookup lookup, - final Class arrayClass, - final StructuredArrayBuilder subArrayBuilder, - final long length) { - super(lookup, arrayClass, subArrayBuilder, length); - } - - /** - * Constructs a new {@link StructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends AbstractPrimitiveArray, such that the - * arrays instantiated by this builder would include elements that are PrimitiveArrays. - * - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * subclassable PrimitiveArrays) - * @param length The length of the array to be build by this builder - * @param The class in the subArray (should match T for the StructuredArrayBuilder) - */ - public StructuredArrayBuilder(final Class arrayClass, - final PrimitiveArrayBuilder subArrayBuilder, - final long length) { - super(arrayClass, subArrayBuilder, length); - } - - /** - * Constructs a new {@link StructuredArrayBuilder} object for creating an array of type S with - * elements of type T, and the given length. Used when T extends AbstractPrimitiveArray, such that the - * arrays instantiated by this builder would include elements that are PrimitiveArrays. - * - * @param lookup The lookup object to use for accessing constructors when resolving this builder - * @param arrayClass The class of the array to be built by this builder - * @param subArrayBuilder The builder used for creating individual array elements (which are themselves - * subclassable PrimitiveArrays) - * @param length The length of the array to be build by this builder - * @param The class in the subArray (should match T for the StructuredArrayBuilder) - */ - public StructuredArrayBuilder( - MethodHandles.Lookup lookup, - final Class arrayClass, - final PrimitiveArrayBuilder subArrayBuilder, - final long length) { - super(lookup, arrayClass, subArrayBuilder, length); - } - - /** - * Set the {@link CtorAndArgsProvider} used for determining the constructor and construction - * arguments used for each element in the array. The provider may use the specific element's - * construction context in determining the construction parameters. - * - * Note: This method overlaps in purpose with the alternate methods for controlling element - * construction. Namely {@link StructuredArrayBuilder#elementCtorAndArgs(CtorAndArgs)} and - * {@link StructuredArrayBuilder#elementCtorAndArgs(Constructor, Object...)}. - * - * @param ctorAndArgsProvider The provider used for determining the constructor and construction - * arguments used for each element in instantiated arrays - * @return The builder - */ - public StructuredArrayBuilder elementCtorAndArgsProvider(final CtorAndArgsProvider ctorAndArgsProvider) { - return (StructuredArrayBuilder) super.elementCtorAndArgsProvider(ctorAndArgsProvider); - } - - /** - * Set the {@link CtorAndArgs} to be used for all elements in the array. All elements will be constructed with - * the same constructor and the same arguments. - * - * Note: This method overlaps in purpose with the alternate methods for controlling element - * construction. Namely {@link StructuredArrayBuilder#elementCtorAndArgsProvider(CtorAndArgsProvider)} and - * {@link StructuredArrayBuilder#elementCtorAndArgs(Constructor, Object...)}. - * - * @param ctorAndArgs The constructor and arguments used for all elements in arrays - * @return The builder - */ - public StructuredArrayBuilder elementCtorAndArgs(final CtorAndArgs ctorAndArgs) { - return (StructuredArrayBuilder) super.elementCtorAndArgs(ctorAndArgs); - } - - /** - * Set the {@link Constructor} and construction arguments to be used for all elements in the array. - * All elements will be constructed with the same constructor and the same arguments. - * - * Note: This method overlaps in purpose with the alternate methods for controlling element - * construction. Namely {@link StructuredArrayBuilder#elementCtorAndArgsProvider(CtorAndArgsProvider)} and - * {@link StructuredArrayBuilder#elementCtorAndArgs(CtorAndArgs)}. - * - * @param constructor The constructor used for all elements in arrays - * @param args The construction arguments supplied for the constructor, used for all elements in the array - * @return The builder - */ - public StructuredArrayBuilder elementCtorAndArgs(final Constructor constructor, final Object... args) { - return (StructuredArrayBuilder) super.elementCtorAndArgs(constructor, args); - } - - /** - * Set the {@link CtorAndArgs} to be used in constructing arrays. - * Setting the means for array construction is Required if the array class (S) does not support a - * default constructor, or if a non-default construction of the array instance is needed. - * - * @param arrayCtorAndArgs The constructor and arguments used for constructing arrays - * @return The builder - */ - public StructuredArrayBuilder arrayCtorAndArgs(final CtorAndArgs arrayCtorAndArgs) { - return (StructuredArrayBuilder) super.arrayCtorAndArgs(arrayCtorAndArgs); - } - - /** - * Set the {@link Constructor} and construction arguments to be used in constructing arrays. - * Setting the means for array construction is Required if the array class (S) does not support a - * default constructor, or if a non-default construction of the array instance is needed. - * - * @param constructor The constructor used for constructing arrays - * @param args The construction arguments supplied for the constructor - * @return The builder - */ - public StructuredArrayBuilder arrayCtorAndArgs(final Constructor constructor, final Object... args) { - return (StructuredArrayBuilder) super.arrayCtorAndArgs(constructor, args); - } - - /** - * Set the (opaque) contextCookie object associated with this builder. This contextCookie object will be - * set in {@link org.ObjectLayout.ConstructionContext} object passed to the element - * {@link CtorAndArgsProvider} provider for each element in instantiated arrays. - * - * @param contextCookie the contextCookie object - * @return The builder - */ - public StructuredArrayBuilder contextCookie(final Object contextCookie) { - return (StructuredArrayBuilder) super.contextCookie(contextCookie); - } - - /** - * Resolve any not-yet-resolved constructor information needed by this builder. Calling resolve() is not - * necessary ahead of building, but it is useful for ensuring resolution works ahead of actual building - * attempts. - * - * @return This builder - * @throws IllegalArgumentException if the array constructor or element constructor fail to resolve given - * the current information in the builder - */ - public StructuredArrayBuilder resolve() { - return (StructuredArrayBuilder) super.resolve(); - } - - /** - * Build a {@link StructuredArray} according to the information captured in this builder - * @return A newly instantiated {@link StructuredArray} - * - * @throws IllegalArgumentException if the array constructor or element constructor fail to resolve given - * the current information in the builder - */ - public S build() throws IllegalArgumentException { - return super.build(); - } - - /** - * Get the {@link org.ObjectLayout.StructuredArrayModel} that describes the arrays built by this builder - * - * @return The {@link org.ObjectLayout.StructuredArrayModel} that describes the arrays built by this builder - */ - public StructuredArrayModel getArrayModel() { - return super.getArrayModel(); - } - - /** - * Get the {@link org.ObjectLayout.StructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null - * - * @return The {@link org.ObjectLayout.StructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null if the array element type T does not extend {@link StructuredArray}. - */ - public StructuredArrayBuilder getStructuredSubArrayBuilder() { - return (StructuredArrayBuilder) super.getStructuredSubArrayBuilder(); - } - - /** - * Get the {@link org.ObjectLayout.StructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null - * - * @return The {@link org.ObjectLayout.StructuredArrayBuilder} for the elements of the arrays built by - * this builder. Null if the array element type T does not extend {@link StructuredArray}. - */ - public PrimitiveArrayBuilder getPrimitiveSubArrayBuilder() { - return super.getPrimitiveSubArrayBuilder(); - } - - /** - * Get the {@link CtorAndArgs} describing the constructor and arguments used to instantiate arrays with - * this builder. May be null if non of {@link org.ObjectLayout.StructuredArrayBuilder#arrayCtorAndArgs}, - * {@link org.ObjectLayout.StructuredArrayBuilder#resolve()} or - * {@link org.ObjectLayout.StructuredArrayBuilder#build()} have been called yet. - * @return The {@link CtorAndArgs} describing the constructor and arguments used to instantiate arrays with - * this builder. - */ - public CtorAndArgs getArrayCtorAndArgs() { - return super.getArrayCtorAndArgs(); - } - - /** - * Get the {@link CtorAndArgsProvider} which provides the constructor and arguments used to construct - * individual elements of arrays instantiated with this builder. May be null if non of - * {@link org.ObjectLayout.StructuredArrayBuilder#elementCtorAndArgsProvider}, - * {@link org.ObjectLayout.StructuredArrayBuilder#elementCtorAndArgs}, - * {@link org.ObjectLayout.StructuredArrayBuilder#resolve} or - * {@link org.ObjectLayout.StructuredArrayBuilder#build} have been called yet. - * @return The {@link CtorAndArgsProvider} which provides the constructor and arguments used to construct - * individual elements of arrays instantiated with this builder - */ - public CtorAndArgsProvider getElementCtorAndArgsProvider() { - return super.getElementCtorAndArgsProvider(); - } - - /** - * Get the (opaque) contextCookie object associated with this builder. This contextCookie object will be - * set in {@link org.ObjectLayout.ConstructionContext} object passed to the element - * {@link CtorAndArgsProvider} provider for each element in instantiated arrays. - * @return The (opaque) contextCookie object associated with this builder - */ - public Object getContextCookie() { - return super.getContextCookie(); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/StructuredArrayModel.java b/ObjectLayout/src/main/java/org/ObjectLayout/StructuredArrayModel.java deleted file mode 100644 index e3eb673..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/StructuredArrayModel.java +++ /dev/null @@ -1,148 +0,0 @@ -package org.ObjectLayout; - -/** - * A model that describes the structure of a StructuredArray - * - * @param The class of the StructuredArray modeled by the model - * @param The class of the elements in the StructuredArray modeled by the model - */ -public class StructuredArrayModel, T> extends - AbstractStructuredArrayModel { - - /** - * Create a model of a StructuredArray instance with terminal (non StructuredArray) elements, - * deriving the array class and element class from the generic class parameters - * - * @param length The length of the StructuredArray modeled by the model - */ - public StructuredArrayModel(final long length) { - super((Class) null, (Class) null, length); - } - - /** - * Create a model of a StructuredArray instance with terminal (non StructuredArray) elements - * - * @param arrayClass The class of the StructuredArray modeled by the model - * @param elementClass The class of the elements in the StructuredArray modeled by the model - * @param length The length of the StructuredArray modeled by the model - */ - public StructuredArrayModel(final Class arrayClass, - final Class elementClass, - final long length) { - super(arrayClass, elementClass, length); - } - - /** - * Create a model of a StructuredArray instance with elements that are themselves StructuredArrays - * - * @param arrayClass The class of the StructuredArray modeled by the model - * @param subArrayModel The model describing the structure of the elements of the array being modeled - * @param length The length of the StructuredArray modeled by the model - * @param The class of the StructuredArray modeled by the subArrayModel - * @param The class of the elements in the StructuredArray modeled by the subArrayModel - */ - public , T2> - StructuredArrayModel(final Class arrayClass, - final StructuredArrayModel subArrayModel, - final long length) { - super(arrayClass, subArrayModel, length); - } - - /** - * Create a model of a StructuredArray instance with elements that are themselves subclassable PrimitiveArrays - * - * @param arrayClass The class of the StructuredArray modeled by the model - * @param subArrayModel The model describing the structure of the elements of the array being modeled - * @param length The length of the StructuredArray modeled by the model - * @param The class of the PrimitiveArray modeled by the subArrayModel - */ - public - StructuredArrayModel(final Class arrayClass, - final PrimitiveArrayModel subArrayModel, - final long length) { - super(arrayClass, subArrayModel, length); - } - - /** - * Determine if this model is equal to another object. If the other object is not a model, they are - * not equal. If the other object is a model, the two are equal if all details, (arrayClass, elementClass, - * length, and any subArrayModel hierarchy details) are identical. - * - * @param other the other object - * @return true is the other object is a model that is equal to this one, false otherwise. - */ - @Override - public boolean equals(Object other) { - if (!(other instanceof StructuredArrayModel)) { - return false; - } - @SuppressWarnings("unchecked") - StructuredArrayModel otherArray = (StructuredArrayModel) other; - if ((getArrayClass() != otherArray.getArrayClass()) || - (getElementClass() != otherArray.getElementClass()) || - (getLength() != otherArray.getLength())) { - return false; - } - if ((getPrimitiveSubArrayModel() == null) && (otherArray.getPrimitiveSubArrayModel() == null)) { - if ((getStructuredSubArrayModel() == null) && (otherArray.getStructuredSubArrayModel() == null)) { - return true; - } - // if either structuredSubArrayModel is null, they are not equal. Otherwise, compare subArrays: - return (getStructuredSubArrayModel() != null) && - (otherArray.getStructuredSubArrayModel() != null) && - getStructuredSubArrayModel().equals(otherArray.getStructuredSubArrayModel()); - } - if ((getStructuredSubArrayModel() != null) || (otherArray.getStructuredSubArrayModel() != null)) { - return false; - } - // if either primitiveSubArrayModel is null, they are not equal. Otherwise, compare subArrays: - return (getPrimitiveSubArrayModel() != null) && - (otherArray.getPrimitiveSubArrayModel() != null) && - getPrimitiveSubArrayModel().equals(otherArray.getPrimitiveSubArrayModel()); - } - - @Override - public int hashCode() { - return getArrayClass().hashCode() ^ getElementClass().hashCode() ^ ((int)(getLength()^(getLength()>>>32))); - } - - /** - * Get the class of the StructuredArray modeled by this model - * @return the class of the StructuredArray modeled by this model - */ - public final Class getArrayClass() { - return super._getArrayClass(); - } - - /** - * Get the class of the elements in the StructuredArray modeled by the model - * @return the class of the elements in the StructuredArray modeled by the model - */ - public final Class getElementClass() { - return super._getElementClass(); - } - - /** - * Get the model describing the structure of the elements of the array being modeled - * @return the model describing the structure of the elements of the array being modeled - */ - public final AbstractStructuredArrayModel getStructuredSubArrayModel() { - return super._getStructuredSubArrayModel(); - } - - /** - * Get the model describing the structure of the elements of the array being modeled - * @return the model describing the structure of the elements of the array being modeled - */ - public final AbstractPrimitiveArrayModel getPrimitiveSubArrayModel() { - return super._getPrimitiveSubArrayModel(); - } - - /** - * Get the length of the StructuredArray modeled by the model - * @return The length of the StructuredArray modeled by the model - */ - public final long getLength() { - return super._getLength(); - } -} diff --git a/ObjectLayout/src/main/java/org/ObjectLayout/package-info.java b/ObjectLayout/src/main/java/org/ObjectLayout/package-info.java deleted file mode 100644 index 181126a..0000000 --- a/ObjectLayout/src/main/java/org/ObjectLayout/package-info.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * package-info.java - * - * Written by Gil Tene and Martin Thompson, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/** - *

ObjectLayout: An optimised memory layout package.

- *

- * The ObjectLayout package provides some key data structure classes designed with optimised memory layout - * in mind. These classes are aimed at matching the natural speed benefits similar data structure - * constructs enable in most C-style languages, while maintaining an idiomatic Java feel and a natural - * fit with existing code and libraries. - *

- * The package classes provide full functionality on all JVMs (of Java SE 5 or above) at reasonable layouts - * and execution speeds. However, the classes are carefully designed with semantics that would allow an - * optimised JVM to implement them with improved memory layout not directly expressible in Java. - *

- * The {@link org.ObjectLayout.StructuredArray} class is a good example of this design pattern. - * StructuredArray is carefully designed to allow a JVM to store it in memory with a layout similar to - * an array of structs in C-like languages. When a JVM optimises StructuredArray in such a way, array - * access benefits from both direct (as opposed to de-referenced) dead-reckoning index access, as well - * as from fixed memory strides during streaming operations. - *

- * The three commonly used C-style container layout forms that ObjectLayout seeks to enable in Java are: - *

    - *
  • An array of structs: struct foo[];
  • - *
  • A struct with a struct inside: struct foo { int a; bar b; int c; };
  • - *
  • A struct with an array at the end: struct foo { int len; char[] payload; };
  • - *
- *

- * The speed benefits in these three forms of layout derive from two dominant benefits: - *

    - *
  1. 1. Dead reckoning: In all three forms, the address of the target data field accessed - * through the containing object can be directly derived from the containing object reference - * without a data-dependent load operation (no de-referencing or equivalent operation needed).
  2. - *
  3. 2. Streaming: In the case of an array of structs, sequential access through multiple members - * of the containing array result in predictable striding access in memory, enabling prefetch logic - * (hardware assisted or otherwise) to compensate for much of the latency involved in cache misses.
  4. - *
- *

The matching ObjectLayout forms

- *

- * {@link org.ObjectLayout.StructuredArray} provides an idiomatic Java collection form - * with speed (and semantics) similar to an "array of structs" form, supporting any constructable - * java Object as an array member. - *

- * {@link org.ObjectLayout.Intrinsic @Intrinsic} provides an idiomatic Java means for declaring - * member objects that are intrinsic to the instances of the class they are declared in. - * {@link org.ObjectLayout.Intrinsic @Intrinsic} provides a "struct in struct" equivalent - * relationship between Java objects, exposing the speed and layout benefits similar to the same - * form in the C family languages. - *

- * Sub-classable Primitive and Reference array classes (e.g. {@link org.ObjectLayout.PrimitiveLongArray} - * and {@link org.ObjectLayout.ReferenceArray}) provide an idiomatic Java means of - * declaring constructs with speed (and semantics) similar to "struct with array at the end". They do - * so by supporting the subclassing of arrays of the various primitive and reference forms possible - * in Java. {@link org.ObjectLayout.StructuredArray} similarly supports this capability (via - * subclassing) for the equivalent of "struct with array of structs at the end". - * - * - */ - -package org.ObjectLayout; - - diff --git a/ObjectLayout/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/ObjectLayout/src/main/resources/META-INF/services/javax.annotation.processing.Processor deleted file mode 100644 index 22377b1..0000000 --- a/ObjectLayout/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ /dev/null @@ -1 +0,0 @@ -org.ObjectLayout.IntrinsicProcessor \ No newline at end of file diff --git a/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/IntrinsticObjectTest.java b/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/IntrinsticObjectTest.java deleted file mode 100644 index f201128..0000000 --- a/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/IntrinsticObjectTest.java +++ /dev/null @@ -1,412 +0,0 @@ -/* - * Written by Gil Tene, and released to the public domain, - * as explained at http://creativecommons.org/publicdomain/zero/1.0/ - */ - -package org.ObjectLayoutApiTests; - -import org.ObjectLayout.Intrinsic; -import org.ObjectLayout.IntrinsicObjects; -import org.junit.Test; - -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - -import static java.lang.Long.valueOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class IntrinsticObjectTest { - - @Test - public void shouldConstructLine() throws NoSuchMethodException { - Line line = new Line(); - Point endPoint1 = line.getEndPoint1(); - Point endPoint2 = line.getEndPoint2(); - - assertThat(valueOf(endPoint1.getX()), is(0L)); - assertThat(valueOf(endPoint1.getY()), is(0L)); - assertThat(valueOf(endPoint2.getX()), is(0L)); - assertThat(valueOf(endPoint2.getY()), is(0L)); - - Line line2 = new Line(1, 2, 3, 4); - endPoint1 = line2.getEndPoint1(); - endPoint2 = line2.getEndPoint2(); - - assertThat(valueOf(endPoint1.getX()), is(1L)); - assertThat(valueOf(endPoint1.getY()), is(2L)); - assertThat(valueOf(endPoint2.getX()), is(3L)); - assertThat(valueOf(endPoint2.getY()), is(4L)); - - Line line3 = new Line(line2); - endPoint1 = line3.getEndPoint1(); - endPoint2 = line3.getEndPoint2(); - - assertThat(valueOf(endPoint1.getX()), is(1L)); - assertThat(valueOf(endPoint1.getY()), is(2L)); - assertThat(valueOf(endPoint2.getX()), is(3L)); - assertThat(valueOf(endPoint2.getY()), is(4L)); - } - - @Test - public void shouldSucceedInAccessFakeIntrinsic() throws NoSuchMethodException { - Line line = new Line(); - Point endPoint1 = line.getEndPoint1(); - Point endPoint2 = line.getEndPoint2(); - - assertThat(valueOf(endPoint1.getX()), is(0L)); - assertThat(valueOf(endPoint1.getY()), is(0L)); - assertThat(valueOf(endPoint2.getX()), is(0L)); - assertThat(valueOf(endPoint2.getY()), is(0L)); - - // Make a fake intrinsic Point in the line: - Point badPoint = new Point(0, 0); - Line line2 = new Line(line, badPoint); - - // Access should still work (may be slower, but should work): - endPoint1 = line2.getEndPoint1(); - endPoint2 = line2.getEndPoint2(); - - assertThat(valueOf(endPoint1.getX()), is(0L)); - assertThat(valueOf(endPoint1.getY()), is(0L)); - assertThat(valueOf(endPoint2.getX()), is(0L)); - assertThat(valueOf(endPoint2.getY()), is(0L)); - } - - /** - * BadContainerSuperPoint: Wrong size init for intrinsic object member - */ - static class BadContainerSuperPoint { - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - static final Constructor constructor; - - static { - try { - constructor = SuperPoint.class.getConstructor(); - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } - - Object o = constructor; - @SuppressWarnings("unchecked") - @Intrinsic - private final Point intrinsicPoint = - IntrinsicObjects.constructWithin(lookup, - "intrinsicPoint", this, (Constructor) o, (Object[]) null); - - Point getPoint() { - return intrinsicPoint; - } - } - - @Test(expected = IllegalArgumentException.class) - public void testBadContainerSuperPoint() throws NoSuchMethodException { - BadContainerSuperPoint bad = new BadContainerSuperPoint(); - bad.getPoint().getX(); - } - - /** - * BadContainerNonPrivate: non @Intrinsic intrinsic object member construction attempt - */ - static class BadContainerNonIntrinsic { - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - private final Point intrinsicPoint = IntrinsicObjects.constructWithin(lookup, "intrinsicPoint", this); - - Point getPoint() { - return intrinsicPoint; - } - } - - @Test(expected = IllegalArgumentException.class) - public void testBadContainerNonIntrinsic() throws NoSuchMethodException { - BadContainerNonIntrinsic bad = new BadContainerNonIntrinsic(); - bad.getPoint().getX(); - } - - /** - * BadContainerNonPrivate: non private intrinsic object member - */ - static class BadContainerNonPrivate { - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - @Intrinsic - final Point intrinsicPoint = IntrinsicObjects.constructWithin(lookup, "intrinsicPoint", this); - - Point getPoint() { - return intrinsicPoint; - } - } - - @Test(expected = IllegalArgumentException.class) - public void testBadContainerNonPrivate() throws NoSuchMethodException { - BadContainerNonPrivate bad = new BadContainerNonPrivate(); - bad.getPoint().getX(); - } - - /** - * BadContainerNonFinal: non final intrinsic object member - */ - static class BadContainerNonFinal { - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - @Intrinsic - private Point intrinsicPoint = IntrinsicObjects.constructWithin(lookup, "intrinsicPoint", this); - - Point getPoint() { - return intrinsicPoint; - } - } - - @Test(expected = IllegalArgumentException.class) - public void testBadContainerNonFinal() throws NoSuchMethodException { - BadContainerNonFinal bad = new BadContainerNonFinal(); - bad.getPoint().getX(); - } - - /** - * BadContainerNullMember: null intrinsic object member - */ - static class BadContainerNullMember { - @Intrinsic - private final Point intrinsicPoint = null; - - Point getPoint() { - return intrinsicPoint; - } - } - - @Test(expected = NullPointerException.class) - public void testBadContainerNullMember() throws NoSuchMethodException { - BadContainerNullMember bad = new BadContainerNullMember(); - bad.getPoint().getX(); - } - - /** - * BadContainerOtherMemberIsNull: Badly initialized but not accessed member (should still work, may be slower). - */ - static class BadContainerOtherMemberIsNull { - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - @Intrinsic - private final Point intrinsicPoint1 = IntrinsicObjects.constructWithin(lookup, "intrinsicPoint1", this); - @Intrinsic - private final Point intrinsicPoint2 = null; - - Point getPoint() { - return intrinsicPoint1; - } - } - - @Test - public void testBadContainerOtherMemberIsNull() throws NoSuchMethodException { - BadContainerOtherMemberIsNull bad = new BadContainerOtherMemberIsNull(); - bad.getPoint().getX(); - } - - /** - * BadContainerCrossAssignment: Badly initialized but not accessed member (should still work, may be slower). - */ - static class BadContainerCrossAssignment { - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - @Intrinsic - private final Point intrinsicPoint1 = IntrinsicObjects.constructWithin(lookup, "intrinsicPoint1", this); - @Intrinsic - private final Point intrinsicPoint2 = intrinsicPoint1; - - Point getPoint() { - return intrinsicPoint1; - } - } - - @Test - public void testBadContainerCrossAssignment() throws NoSuchMethodException { - BadContainerCrossAssignment bad = new BadContainerCrossAssignment(); - bad.getPoint().getX(); - } - - /** - * BadContainerFieldName: Badly initialized member (using field name that doesn't exist). - */ - static class BadContainerFieldName { - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - @Intrinsic - private final Point intrinsicPoint = IntrinsicObjects.constructWithin(lookup, "someObject", this); - - Point getPoint() { - return intrinsicPoint; - } - } - - @Test(expected = IllegalArgumentException.class) - public void testBadContainerFieldName() throws NoSuchMethodException { - BadContainerFieldName bad = new BadContainerFieldName(); - bad.getPoint().getX(); - } - - - /** - * BadContainerFieldName: Badly initialized member (using field name that is not assignable from object). - */ - static class BadContainerFieldType { - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - @Intrinsic - private final Point intrinsicPoint = IntrinsicObjects.constructWithin(lookup, "someObject", this); - @Intrinsic - private final long someObject = 0; - - Point getPoint() { - return intrinsicPoint; - } - } - - @Test(expected = IllegalArgumentException.class) - public void testBadContainerFieldType() throws NoSuchMethodException { - BadContainerFieldType bad = new BadContainerFieldType(); - bad.getPoint().getX(); - } - - /** - * A simple x,y point class to be used as an element in various other examples. - * - */ - public static class Point { - private long x; - private long y; - - public Point() { - } - - public Point(final long x, final long y) { - this.x = x; - this.y = y; - } - - public Point(final Point source) { - this(source.x, source.y); - } - - public long getX() { - return x; - } - - public void setX(final long x) { - this.x = x; - } - - public long getY() { - return y; - } - - public void setY(final long y) { - this.y = y; - } - - public void set(final long x, final long y) { - this.x = x; - this.y = y; - } - } - - public static class SuperPoint extends Point { - private long z; - - public SuperPoint() { - } - - public SuperPoint(final long x, final long y, final long z) { - super(x, y); - this.z = z; - } - - public SuperPoint(final SuperPoint source) { - this(source.getX(), source.getY(), source.z); - } - - public long getZ() { - return z; - } - - public void setZ(final long z) { - this.z = z; - } - } - - /** - * A simple Line class example with two intrinsic Point end point objects. - * - * This class demonstrates - * - */ - private static class Line { - - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - /** - * Simple Intrinsic Object declaration and initialization: - */ - @Intrinsic - private final Point endPoint1 = IntrinsicObjects.constructWithin(lookup, "endPoint1", this); - - /** - * Declaration of an Intrinsic Object that will be initialized later during construction or other init code: - */ - @Intrinsic - private final Point endPoint2; - - public Line() { - this(0, 0, 0, 0); - } - - public Line(final long x1, final long y1, long x2, long y2) { - /** - * Construction-time Initialization of IntrinsicObject: - */ - this.endPoint2 = IntrinsicObjects.constructWithin(lookup, "endPoint2", this, xy_constructor, x2, y2); - - /** - * Access to IntrinsicObject within constructor: - */ - this.endPoint1.set(x1, y1); - } - - /** - * A bad Line() constructor, initializes an intrinsic member to - * with the value of an externally supplied parameter. - * - * @param source - * @param endPoint2 - */ - public Line(final Line source, final Point endPoint2) { - this.endPoint2 = endPoint2; - } - - public Line(final Line source) { - this(source.endPoint1.getX(), source.endPoint1.getY(), - source.endPoint2.getX(), source.endPoint2.getY()); - } - - public Point getEndPoint1() { - return endPoint1; - } - - public Point getEndPoint2() { - return endPoint2; - } - - static final Constructor xy_constructor; - - static { - try { - xy_constructor = Point.class.getConstructor(new Class[] {long.class, long.class}); - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } - } - -} diff --git a/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/PrimitiveLongArrayTest.java b/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/PrimitiveLongArrayTest.java deleted file mode 100644 index b07e0f4..0000000 --- a/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/PrimitiveLongArrayTest.java +++ /dev/null @@ -1,323 +0,0 @@ -package org.ObjectLayoutApiTests; - -import org.ObjectLayout.*; -import org.junit.Test; - -import java.lang.invoke.MethodHandles; -import java.util.Arrays; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -public class PrimitiveLongArrayTest { - - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - public static class ColoredLongArrayPublic extends PrimitiveLongArray { - private final String color; - - private static CtorAndArgs ctorAndArgs = - new CtorAndArgs(lookup, ColoredLongArrayPublic.class, - new Class[]{String.class}, "DefaultColor"); - - public static ColoredLongArrayPublic newInstance(String color, final int length) { - ctorAndArgs.getArgs()[0] = color; - return newInstance(ctorAndArgs, length); - } - - public ColoredLongArrayPublic(String color) { - this.color = color; - } - - public ColoredLongArrayPublic(ColoredLongArrayPublic sourceArray) { - super(sourceArray); - color = sourceArray.color; - } - - public String getColor() { - return color; - } - } - - private static class ColoredLongArray extends PrimitiveLongArray { - private final String color; - - private static CtorAndArgs ctorAndArgs = - new CtorAndArgs(lookup, ColoredLongArray.class, new Class[]{String.class}, "DefaultColor"); - - public static ColoredLongArray newInstance(String color, final int length) { - ctorAndArgs.getArgs()[0] = color; - return newInstance(ctorAndArgs, length); - } - - public ColoredLongArray(String color) { - this.color = color; - } - - public ColoredLongArray(ColoredLongArray sourceArray) { - super(sourceArray); - color = sourceArray.color; - } - - public String getColor() { - return color; - } - } - - @Test - public void testColoredLongArray() throws Exception { - ColoredLongArray blueArray = ColoredLongArray.newInstance("Blue", 10); - ColoredLongArray redArray = ColoredLongArray.newInstance("Red", 20); - - for (int i = 0; i < redArray.getLength(); i++) { - redArray.set(i, i); - } - - for (int i = 0; i < blueArray.getLength(); i++) { - blueArray.set(i, redArray.get(i)); - } - - assertTrue(redArray.getColor().equals("Red")); - assertTrue(blueArray.getColor().equals("Blue")); - } - - - @Test - public void testColoredLongArrayPublic() throws Exception { - ColoredLongArrayPublic blueArray = ColoredLongArrayPublic.newInstance("Blue", 10); - ColoredLongArrayPublic redArray = ColoredLongArrayPublic.newInstance("Red", 20); - - for (int i = 0; i < redArray.getLength(); i++) { - redArray.set(i, i); - } - - for (int i = 0; i < blueArray.getLength(); i++) { - blueArray.set(i, redArray.get(i)); - } - - assertTrue(redArray.getColor().equals("Red")); - assertTrue(blueArray.getColor().equals("Blue")); - } - - @Test - public void testCopyOfColoredLongArray() throws Exception { - ColoredLongArray blueArray = ColoredLongArray.newInstance("Blue", 10); - ColoredLongArray redArray = ColoredLongArray.newInstance("Red", 20); - - for (int i = 0; i < redArray.getLength(); i++) { - redArray.set(i, i); - } - - for (int i = 0; i < blueArray.getLength(); i++) { - blueArray.set(i, redArray.get(i)); - } - - ColoredLongArray blueArrayCopy = ColoredLongArray.copyInstance(lookup, blueArray); - - assertTrue(redArray.getColor().equals("Red")); - assertTrue(blueArray.getColor().equals("Blue")); - assertTrue(blueArrayCopy.getColor().equals("Blue")); - assertTrue(Arrays.equals(blueArray.asArray(), blueArrayCopy.asArray())); - } - - @Test - public void testCopyOfColoredLongArrayPublic() throws Exception { - ColoredLongArrayPublic blueArray = ColoredLongArrayPublic.newInstance("Blue", 10); - ColoredLongArrayPublic redArray = ColoredLongArrayPublic.newInstance("Red", 20); - - for (int i = 0; i < redArray.getLength(); i++) { - redArray.set(i, i); - } - - for (int i = 0; i < blueArray.getLength(); i++) { - blueArray.set(i, redArray.get(i)); - } - - ColoredLongArrayPublic blueArrayCopy = ColoredLongArrayPublic.copyInstance(blueArray); - - assertTrue(redArray.getColor().equals("Red")); - assertTrue(blueArray.getColor().equals("Blue")); - assertTrue(blueArrayCopy.getColor().equals("Blue")); - assertTrue(Arrays.equals(blueArray.asArray(), blueArrayCopy.asArray())); - } - - @Test - public void testColoredLongArrayBuilder() throws Exception { - PrimitiveArrayBuilder builder = new PrimitiveArrayBuilder( - ColoredLongArray.class, 50); - ColoredLongArray blueArray = builder.arrayCtorAndArgs(ColoredLongArray.ctorAndArgs.setArgs("Blue")).build(); - ColoredLongArray redArray = builder.arrayCtorAndArgs(ColoredLongArray.ctorAndArgs.setArgs("Red")).build(); - - for (int i = 0; i < redArray.getLength(); i++) { - redArray.set(i, i); - } - - for (int i = 0; i < blueArray.getLength(); i++) { - blueArray.set(i, redArray.get(i)); - } - - assertTrue(redArray.getColor().equals("Red")); - assertTrue(blueArray.getColor().equals("Blue")); - assertTrue(redArray.getLength() == 50); - assertTrue(Arrays.equals(redArray.asArray(), blueArray.asArray())); - } - - @Test - public void testColoredLongArrayBuilderPublic() throws Exception { - PrimitiveArrayBuilder builder = new PrimitiveArrayBuilder( - ColoredLongArrayPublic.class, 50); - ColoredLongArrayPublic blueArray = builder.arrayCtorAndArgs(ColoredLongArrayPublic.ctorAndArgs.setArgs("Blue")).build(); - ColoredLongArrayPublic redArray = builder.arrayCtorAndArgs(ColoredLongArrayPublic.ctorAndArgs.setArgs("Red")).build(); - - for (int i = 0; i < redArray.getLength(); i++) { - redArray.set(i, i); - } - - for (int i = 0; i < blueArray.getLength(); i++) { - blueArray.set(i, redArray.get(i)); - } - - assertTrue(redArray.getColor().equals("Red")); - assertTrue(blueArray.getColor().equals("Blue")); - assertTrue(redArray.getLength() == 50); - assertTrue(Arrays.equals(redArray.asArray(), blueArray.asArray())); - } - - @Test - public void testStructuredArrayOfColoredLongArrays() throws NoSuchMethodException { - @SuppressWarnings("unchecked") - StructuredArray a = - new StructuredArrayBuilder(StructuredArray.class, - new PrimitiveArrayBuilder(ColoredLongArray.class, 20). - arrayCtorAndArgs(ColoredLongArray.ctorAndArgs.setArgs("Yellow")), - 50). - build(); - assertThat(a.getLength(), is(50L)); - assertThat(a.get(0).getLength(), is(20L)); - assertThat(a.get(1).getColor(), is("Yellow")); - } - - @Test - public void testStructuredArrayOfColoredLongArraysPublic() throws NoSuchMethodException { - @SuppressWarnings("unchecked") - StructuredArray a = - new StructuredArrayBuilder(StructuredArray.class, - new PrimitiveArrayBuilder(ColoredLongArrayPublic.class, 20). - arrayCtorAndArgs(ColoredLongArrayPublic.ctorAndArgs.setArgs("Yellow")), - 50). - build(); - assertThat(a.getLength(), is(50L)); - assertThat(a.get(0).getLength(), is(20L)); - assertThat(a.get(1).getColor(), is("Yellow")); - } - - @Test(expected = RuntimeException.class) - public void testStructuredArrayOfColoredLongArrays_shouldFail() { - // Should fail to find default constructor: - @SuppressWarnings("unchecked") - StructuredArray a = - new StructuredArrayBuilder(StructuredArray.class, - new PrimitiveArrayBuilder(ColoredLongArray.class, 20), - 50). - build(); - } - - @Test - public void testStructuredArrayOfColoredLongArraysWithVariableNames() { - @SuppressWarnings("unchecked") - StructuredArray a = - new StructuredArrayBuilder(StructuredArray.class, - new PrimitiveArrayBuilder(ColoredLongArray.class, 20), - 50). - elementCtorAndArgsProvider( - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext(ConstructionContext context) throws NoSuchMethodException { - return ColoredLongArray.ctorAndArgs.setArgs("Color-" + context.getIndex()); - } - }). - build(); - assertThat(a.getLength(), is(50L)); - assertThat(a.get(0).getLength(), is(20L)); - assertThat(a.get(0).getColor(), is("Color-0")); - assertThat(a.get(1).getColor(), is("Color-1")); - assertThat(a.get(2).getColor(), is("Color-2")); - assertThat(a.get(48).getColor(), is("Color-48")); - assertThat(a.get(49).getColor(), is("Color-49")); - } - - @Test - public void testStructuredArrayOfColoredLongArraysWithVariableNamesPublic() { - @SuppressWarnings("unchecked") - StructuredArray a = - new StructuredArrayBuilder(StructuredArray.class, - new PrimitiveArrayBuilder(ColoredLongArrayPublic.class, 20), - 50). - elementCtorAndArgsProvider( - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext(ConstructionContext context) throws NoSuchMethodException { - return ColoredLongArrayPublic.ctorAndArgs.setArgs("Color-" + context.getIndex()); - } - }). - build(); - assertThat(a.getLength(), is(50L)); - assertThat(a.get(0).getLength(), is(20L)); - assertThat(a.get(0).getColor(), is("Color-0")); - assertThat(a.get(1).getColor(), is("Color-1")); - assertThat(a.get(2).getColor(), is("Color-2")); - assertThat(a.get(48).getColor(), is("Color-48")); - assertThat(a.get(49).getColor(), is("Color-49")); - } - - @Test - public void testCopyStructuredArrayOfColoredLongArrays() throws NoSuchMethodException { - @SuppressWarnings("unchecked") - StructuredArray a = - new StructuredArrayBuilder(StructuredArray.class, - new PrimitiveArrayBuilder(ColoredLongArray.class, 20). - arrayCtorAndArgs(ColoredLongArray.ctorAndArgs.setArgs("Yellow")), - 50). - build(); - - for (int i = 0; i < a.getLength(); i++) { - ColoredLongArray ca = a.get(i); - for (int j = 0; j < ca.getLength(); j++) { - ca.set(j, j); - } - } - - StructuredArray a2 = - StructuredArray.copyInstance(lookup, a); - - for (int i = 0; i < a.getLength(); i++) { - assertTrue(Arrays.equals(a.get(i).asArray(), a2.get(i).asArray())); - } - } - - @Test - public void testCopyStructuredArrayOfColoredLongArraysPublic() throws NoSuchMethodException { - @SuppressWarnings("unchecked") - StructuredArray a = - new StructuredArrayBuilder(StructuredArray.class, - new PrimitiveArrayBuilder(ColoredLongArrayPublic.class, 20). - arrayCtorAndArgs(ColoredLongArrayPublic.ctorAndArgs.setArgs("Yellow")), - 50). - build(); - - for (int i = 0; i < a.getLength(); i++) { - ColoredLongArrayPublic ca = a.get(i); - for (int j = 0; j < ca.getLength(); j++) { - ca.set(j, j); - } - } - - StructuredArray a2 = - StructuredArray.copyInstance(a); - - for (int i = 0; i < a.getLength(); i++) { - assertTrue(Arrays.equals(a.get(i).asArray(), a2.get(i).asArray())); - } - } -} diff --git a/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/ReferenceArrayTest.java b/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/ReferenceArrayTest.java deleted file mode 100644 index 006077b..0000000 --- a/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/ReferenceArrayTest.java +++ /dev/null @@ -1,165 +0,0 @@ -package org.ObjectLayoutApiTests; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import org.ObjectLayout.ProtectedReferenceArray; -import org.ObjectLayout.ProtectedStructuredArray; -import org.ObjectLayout.ReferenceArray; -import org.junit.Test; - -import java.lang.invoke.MethodHandles; - -public class ReferenceArrayTest { - - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - public static class StackPublic extends ReferenceArray { - private int size = 0; - private final long capacity; - - public static StackPublic newInstance(final long length) { - return newInstance(StackPublic.class, length); - } - - public StackPublic() { - this.capacity = getLength(); - } - - public void push(Object o) { - if (size == capacity) { - throw new IndexOutOfBoundsException(); - } - - set(size, o); - size++; - } - - public Object pop() { - if (size == 0) { - throw new IndexOutOfBoundsException(); - } - - Object o = get(--size); - return o; - } - - public int size() { - return size; - } - } - - private static class Stack extends ReferenceArray { - private int size = 0; - private final long capacity; - - public static Stack newInstance(final long length) { - return newInstance(lookup, Stack.class, length); - } - - public Stack() { - this.capacity = getLength(); - } - - public void push(Object o) { - if (size == capacity) { - throw new IndexOutOfBoundsException(); - } - - set(size, o); - size++; - } - - public Object pop() { - if (size == 0) { - throw new IndexOutOfBoundsException(); - } - - Object o = get(--size); - return o; - } - - public int size() { - return size; - } - } - - - public static class StackProtected extends ProtectedReferenceArray { - private int size = 0; - private final long capacity; - - public static StackProtected newInstance(final long length) { - return newInstance(StackProtected.class, length); - } - - public StackProtected() { - this.capacity = getLength(); - } - - public void push(Object o) { - if (size == capacity) { - throw new IndexOutOfBoundsException(); - } - - set(size, o); - size++; - } - - public Object pop() { - if (size == 0) { - throw new IndexOutOfBoundsException(); - } - - Object o = get(--size); - return o; - } - - public int size() { - return size; - } - } - - @Test - public void pushesAndPops() throws Exception { - Stack s0 = Stack.newInstance(lookup, Stack.class, 10); // Just to test the base form of instantiation - Stack s = Stack.newInstance(10); // The convenient way... - - String foo = "foo"; - s.push(foo); - - assertThat(s.size(), is(1)); - assertThat(s.pop(), is((Object) foo)); - assertThat(s.size(), is(0)); - - Object r = s.get(0); // So, this is possible on a ReferenceArray subclass (but not on ProtectedReferenceArray).... - } - - @Test - public void pushesAndPopsPublic() throws Exception { - StackPublic s0 = StackPublic.newInstance(StackPublic.class, 10); // Just to test the base form of instantiation - StackPublic s = StackPublic.newInstance(10); // The convenient way... - - String foo = "foo"; - s.push(foo); - - assertThat(s.size(), is(1)); - assertThat(s.pop(), is((Object) foo)); - assertThat(s.size(), is(0)); - - Object r = s.get(0); // So, this is possible on a ReferenceArray subclass (but not on ProtectedReferenceArray).... - } - - - @Test - public void pushesAndPopsProtected() throws Exception { - StackProtected s = StackProtected.newInstance(10); // The convenient way... - - String foo = "foo"; - s.push(foo); - - assertThat(s.size(), is(1)); - assertThat(s.pop(), is((Object) foo)); - assertThat(s.size(), is(0)); - } -} diff --git a/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/StructuredArrayPerfTest.java b/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/StructuredArrayPerfTest.java deleted file mode 100644 index 819d51d..0000000 --- a/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/StructuredArrayPerfTest.java +++ /dev/null @@ -1,299 +0,0 @@ -/* -* Written by Gil Tene and Martin Thompson, and released to the public domain, -* as explained at http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -package org.ObjectLayoutApiTests; - -import org.ObjectLayout.ConstructionContext; -import org.ObjectLayout.CtorAndArgs; -import org.ObjectLayout.CtorAndArgsProvider; -import org.ObjectLayout.StructuredArray; -import org.junit.Test; - -import java.lang.reflect.Constructor; -import java.util.Random; - -import static java.lang.Long.valueOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -public class StructuredArrayPerfTest { - StructuredArray array; - StructuredArrayOfMockStructure subclassedArray; - GenericEncapsulatedArray genericEncapsulatedArray; - EncapsulatedArray encapsulatedArray; - EncapsulatedRandomizedArray encapsulatedRandomizedArray; - - class EncapsulatedArray { - final MockStructure[] array; - - EncapsulatedArray(int length) { - array = new MockStructure[length]; - for (int i = 0; i < array.length; i++) { - array[i] = new MockStructure(i, i*2); - } - } - - MockStructure get(final int index) { - return array[index]; - } - - int getLength() { - return array.length; - } - } - - class EncapsulatedRandomizedArray { - final MockStructure[] array; - - EncapsulatedRandomizedArray(int length) { - array = new MockStructure[length]; - for (int i = 0; i < array.length; i++) { - array[i] = new MockStructure(i, i*2); - } - // swap elements around randomly - Random generator = new Random(); - for (int i = 0; i < array.length; i++) { - int target = generator.nextInt(array.length); - MockStructure temp = array[target]; - array[target] = array[i]; - array[i] = temp; - } - } - - MockStructure get(final int index) { - return array[index]; - } - - int getLength() { - return array.length; - } - } - - class GenericEncapsulatedArray { - final E[] array; - - GenericEncapsulatedArray(Constructor constructor, int length) { - @SuppressWarnings("unchecked") - final E[] a = (E[]) new Object[length]; - array = a; - try { - for (int i = 0; i < array.length; i++) { - array[i] = constructor.newInstance(i, i * 2); - } - } catch (final Exception ex) { - throw new RuntimeException(ex); - } - } - - E get(final int index) { - return array[index]; - } - - int getLength() { - return array.length; - } - } - - long arrayLoopSumTest() { - long sum = 0; - for (int i = 0 ; i < array.getLength(); i++) { - sum += array.get(i).getTestValue(); - } - return sum; - } - - long subclassedArrayLoopSumTest() { - long sum = 0; - for (int i = 0 ; i < array.getLength(); i++) { - sum += subclassedArray.get(i).getTestValue(); - } - return sum; - } - - long loopGenericEncapsulatedArraySumTest() { - long sum = 0; - for (int i = 0 ; i < genericEncapsulatedArray.getLength(); i++) { - sum += genericEncapsulatedArray.get(i).getTestValue(); - } - return sum; - } - - long loopEncapsulatedArraySumTest() { - long sum = 0; - for (int i = 0 ; i < encapsulatedArray.getLength(); i++) { - sum += encapsulatedArray.get(i).getTestValue(); - } - return sum; - } - - long loopEncapsulatedRandomizedArraySumTest() { - long sum = 0; - for (int i = 0 ; i < encapsulatedRandomizedArray.getLength(); i++) { - sum += encapsulatedRandomizedArray.get(i).getTestValue(); - } - return sum; - } - - public void testLoop(int length) { - long startTime5 = System.nanoTime(); - long sum5 = loopEncapsulatedRandomizedArraySumTest(); - long endTime5 = System.nanoTime(); - double loopsPerSec5 = 1000 * (double) length / (endTime5 - startTime5); - - long startTime4 = System.nanoTime(); - long sum4 = loopEncapsulatedArraySumTest(); - long endTime4 = System.nanoTime(); - double loopsPerSec4 = 1000 * (double) length / (endTime4 - startTime4); - - long startTime3 = System.nanoTime(); - long sum3 = loopGenericEncapsulatedArraySumTest(); - long endTime3 = System.nanoTime(); - double loopsPerSec3 = 1000 * (double) length / (endTime3 - startTime3); - - long startTime2 = System.nanoTime(); - long sum2 = subclassedArrayLoopSumTest(); - long endTime2 = System.nanoTime(); - double loopsPerSec2 = 1000 * (double) length / (endTime2 - startTime2); - - long startTime1 = System.nanoTime(); - long sum1 = arrayLoopSumTest(); - long endTime1 = System.nanoTime(); - double loopsPerSec1 = 1000 * (double) length / (endTime1 - startTime1); - - System.out.println("StructuredArray: (" + loopsPerSec1 + - "M), SubclassedSA: (" + loopsPerSec2 + - "M), GenericEncapsulatedArray: (" + loopsPerSec3 + - "M), EncapsulatedArray: (" + loopsPerSec4 + - "M), EncapsulatedRandomizedArray: (" + loopsPerSec5 + - "M) cksum = " + (sum1 + sum2 + sum3 + sum4 + sum5)); - } - - @Test - public void testLoopingSpeeds() throws NoSuchMethodException { - final int length = 1000000; - - final Object[] args = new Object[2]; - final CtorAndArgs ctorAndArgs = - new CtorAndArgs( - MockStructure.class.getConstructor(MockStructure.constructorArgTypes), args); - - - final CtorAndArgsProvider ctorAndArgsProvider = - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - args[0] = context.getIndex(); - args[1] = context.getIndex() * 2; - return ctorAndArgs; - } - }; - - - array = StructuredArray.newInstance(MockStructure.class, ctorAndArgsProvider, length); - subclassedArray = StructuredArrayOfMockStructure.newInstance(ctorAndArgsProvider, length); - encapsulatedArray = new EncapsulatedArray(length); - encapsulatedRandomizedArray = new EncapsulatedRandomizedArray(length); - genericEncapsulatedArray = - new GenericEncapsulatedArray( - MockStructure.class.getConstructor(MockStructure.constructorArgTypes), length); - for (int i = 0; i < 10; i++) { - testLoop(length); - try { - Thread.sleep(100); - } catch (InterruptedException ex) { - - } - } - } - - public static void main(String[] args) { - try { - StructuredArrayPerfTest test = new StructuredArrayPerfTest(); - // Useful for keeping program alive and active when doing drill-down browsing in an interactive profiler: - while (true) { - test.testLoopingSpeeds(); - } - } catch (Exception ex) { - } - } - - /////////////////////////////////////////////////////////////////////////////////////////////// - // Test support below - /////////////////////////////////////////////////////////////////////////////////////////////// - - public static class MockStructure { - - static final Class[] constructorArgTypes = {Long.TYPE, Long.TYPE}; - - private long index = -1; - private long testValue = Long.MIN_VALUE; - - public MockStructure() { - } - - public MockStructure(final long index, final long testValue) { - this.index = index; - this.testValue = testValue; - } - - public MockStructure(MockStructure src) { - this.index = src.index; - this.testValue = src.testValue; - } - - public long getIndex() { - return index; - } - - public void setIndex(final long index) { - this.index = index; - } - - public long getTestValue() { - return testValue; - } - - public void setTestValue(final long testValue) { - this.testValue = testValue; - } - - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final MockStructure that = (MockStructure)o; - - return index == that.index && testValue == that.testValue; - } - - public int hashCode() { - int result = (int)(index ^ (index >>> 32)); - result = 31 * result + (int)(testValue ^ (testValue >>> 32)); - return result; - } - - public String toString() { - return "MockStructure{" + - "index=" + index + - ", testValue=" + testValue + - '}'; - } - } - - public static class MockStructureWithFinalField { - private final int value = 888; - } - - public static class StructuredArrayOfMockStructure extends StructuredArray { - public static StructuredArrayOfMockStructure newInstance( - final CtorAndArgsProvider ctorAndArgsProvider,final long length) { - return StructuredArray.newInstance( - StructuredArrayOfMockStructure.class, MockStructure.class, length, ctorAndArgsProvider); - } - - } -} diff --git a/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/StructuredArrayTest.java b/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/StructuredArrayTest.java deleted file mode 100644 index 6724d74..0000000 --- a/ObjectLayout/src/test/java/org/ObjectLayoutApiTests/StructuredArrayTest.java +++ /dev/null @@ -1,1180 +0,0 @@ -/* -* Written by Gil Tene and Martin Thompson, and released to the public domain, -* as explained at http://creativecommons.org/publicdomain/zero/1.0/ -*/ - -package org.ObjectLayoutApiTests; - -import org.ObjectLayout.*; -import org.junit.Test; - -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; -import java.util.ArrayList; - -import static java.lang.Long.valueOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -public class StructuredArrayTest { - - static final MethodHandles.Lookup lookup = MethodHandles.lookup(); - - @Test - public void shouldConstructArrayOfGivenDirectLengths() throws NoSuchMethodException { - final long[] lengths = {7L, 8L, 9L}; - - @SuppressWarnings("unchecked") - final StructuredArray>> array = - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - lookup, - StructuredArray.class, - MockStructure.class, - lengths[2] - ), - lengths[1] - ), - lengths[0] - ).build(); - - assertThat(valueOf(array.getLength()), is(lengths[0])); - assertThat(valueOf(array.get(0).getLength()), is(lengths[1])); - assertThat(valueOf(array.get(0).get(0).getLength()), is(lengths[2])); - - assertTrue(array.getElementClass().isAssignableFrom(StructuredArray.class)); - assertTrue(array.get(0).getElementClass().isAssignableFrom(StructuredArray.class)); - assertTrue(array.get(0).get(0).getElementClass() == MockStructure.class); - } - - @Test - public void shouldConstructArrayOfGivenDirectLengthsPublic() throws NoSuchMethodException { - final long[] lengths = {7L, 8L, 9L}; - - @SuppressWarnings("unchecked") - StructuredArray>> array = - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - StructuredArray.class, - PublicMockStructure.class, - lengths[2] - ), - lengths[1] - ), - lengths[0] - ).build(); - - assertThat(valueOf(array.getLength()), is(lengths[0])); - assertThat(valueOf(array.get(0).getLength()), is(lengths[1])); - assertThat(valueOf(array.get(0).get(0).getLength()), is(lengths[2])); - - assertTrue(array.getElementClass().isAssignableFrom(StructuredArray.class)); - assertTrue(array.get(0).getElementClass().isAssignableFrom(StructuredArray.class)); - assertTrue(array.get(0).get(0).getElementClass() == PublicMockStructure.class); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithNewInstance() throws NoSuchMethodException { - long length = 9L; - StructuredArray array = StructuredArray.newInstance(lookup, MockStructure.class, length); - - assertThat(valueOf(array.getLength()), is(valueOf(length))); - assertTrue(array.getElementClass() == MockStructure.class); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithNewInstancePublic() throws NoSuchMethodException { - long length = 9L; - StructuredArray array = StructuredArray.newInstance(PublicMockStructure.class, length); - - assertThat(valueOf(array.getLength()), is(valueOf(length))); - assertTrue(array.getElementClass() == PublicMockStructure.class); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilder() throws NoSuchMethodException { - long length = 9L; - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - lookup, - StructuredArray.class, - MockStructure.class, - length). - build(); - - assertThat(valueOf(array.getLength()), is(valueOf(length))); - assertTrue(array.getElementClass() == MockStructure.class); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderPublic() throws NoSuchMethodException { - long length = 9L; - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - StructuredArray.class, - PublicMockStructure.class, - length). - build(); - - assertThat(valueOf(array.getLength()), is(valueOf(length))); - assertTrue(array.getElementClass() == PublicMockStructure.class); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderAndCtorAndArgs() throws NoSuchMethodException, IllegalAccessException { - final Class[] initArgTypes = {long.class, long.class}; - final long expectedIndex = 4L; - final long expectedValue = 777L; - long length = 9L; - - final CtorAndArgs ctorAndArgs = - new CtorAndArgs(lookup, MockStructure.class, initArgTypes, expectedIndex, expectedValue); - - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - lookup, - StructuredArray.class, - MockStructure.class, - length). - elementCtorAndArgs(ctorAndArgs). - build(); - - assertCorrectFixedInitialisation(expectedIndex, expectedValue, new long[]{length}, array); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderAndCtorAndArgsPublic() throws NoSuchMethodException { - final Class[] initArgTypes = {long.class, long.class}; - final long expectedIndex = 4L; - final long expectedValue = 777L; - long length = 9L; - - final CtorAndArgs ctorAndArgs = - new CtorAndArgs(PublicMockStructure.class, initArgTypes, expectedIndex, expectedValue); - - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - StructuredArray.class, - PublicMockStructure.class, - length). - elementCtorAndArgs(ctorAndArgs). - build(); - - assertCorrectFixedInitialisation(expectedIndex, expectedValue, new long[] {length}, array); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderAndCtorAndArgs2() throws NoSuchMethodException { - final long expectedIndex = 4L; - final long expectedValue = 777L; - long length = 9L; - - final Constructor constructor = MockStructure.class.getConstructor(long.class, long.class); - constructor.setAccessible(true); // When constructor is passed in, setAccessible is the caller responsibility... - - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - StructuredArray.class, - MockStructure.class, - length). - elementCtorAndArgs(constructor, expectedIndex, expectedValue). - build(); - - assertCorrectFixedInitialisation(expectedIndex, expectedValue, new long[] {length}, array); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderAndCtorAndArgs2Public() throws NoSuchMethodException { - final long expectedIndex = 4L; - final long expectedValue = 777L; - long length = 9L; - - final Constructor constructor = - PublicMockStructure.class.getConstructor(long.class, long.class); - - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - StructuredArray.class, - PublicMockStructure.class, - length). - elementCtorAndArgs(constructor, expectedIndex, expectedValue). - build(); - - assertCorrectFixedInitialisation(expectedIndex, expectedValue, new long[] {length}, array); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderAndCtorAndArgsProvider() throws NoSuchMethodException { - long length = 9L; - - final Constructor constructor = MockStructure.class.getConstructor(long.class, long.class); - constructor.setAccessible(true); // When constructor is passed in, setAccessible is the caller responsibility... - - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - StructuredArray.class, - MockStructure.class, - length). - elementCtorAndArgsProvider( - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return new CtorAndArgs(constructor, context.getIndex(), context.getIndex() * 2); - } - } - ). - build(); - - assertCorrectVariableInitialisation(new long[]{length}, array); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderAndCtorAndArgsProviderPublic() throws NoSuchMethodException { - long length = 9L; - - final Constructor constructor = - PublicMockStructure.class.getConstructor(long.class, long.class); - - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - StructuredArray.class, - PublicMockStructure.class, - length). - elementCtorAndArgsProvider( - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return new CtorAndArgs(constructor, context.getIndex(), context.getIndex() * 2); - } - } - ). - build(); - - assertCorrectVariableInitialisation(new long[] {length}, array); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderAndCtorAndArgsProvider2() throws NoSuchMethodException { - long length = 9L; - - final Constructor constructor = MockStructure.class.getConstructor(long.class, long.class); - constructor.setAccessible(true); // When constructor is passed in, setAccessible is the caller responsibility... - final CtorAndArgs ctorAndArgs = new CtorAndArgs(constructor, (Object[]) null); - final Object[] args = new Object[2]; - - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - StructuredArray.class, - MockStructure.class, - length). - elementCtorAndArgsProvider( - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - args[0] = context.getIndex(); - args[1] = context.getIndex() * 2; - return ctorAndArgs.setArgs(args); - } - } - ). - build(); - - assertCorrectVariableInitialisation(new long[] {length}, array); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderAndCtorAndArgsProvider2Public() throws NoSuchMethodException { - long length = 9L; - - final Constructor constructor = - PublicMockStructure.class.getConstructor(long.class, long.class); - final CtorAndArgs ctorAndArgs = - new CtorAndArgs(constructor, (Object[]) null); - final Object[] args = new Object[2]; - - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - StructuredArray.class, - PublicMockStructure.class, - length). - elementCtorAndArgsProvider( - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - args[0] = context.getIndex(); - args[1] = context.getIndex() * 2; - return ctorAndArgs.setArgs(args); - } - } - ). - build(); - - assertCorrectVariableInitialisation(new long[] {length}, array); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderAndCtorAndArgsProvider3() throws NoSuchMethodException { - long length = 9L; - - final Constructor constructor = MockStructure.class.getConstructor(MockStructure.class); - constructor.setAccessible(true); // When constructor is passed in, setAccessible is the caller responsibility... - final MockStructure paramMock = new MockStructure(); - final CtorAndArgs ctorAndArgs = new CtorAndArgs(constructor, paramMock); - - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - StructuredArray.class, - MockStructure.class, - length). - elementCtorAndArgsProvider( - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - paramMock.setIndex(context.getIndex()); - paramMock.setTestValue(context.getIndex() * 2); - return ctorAndArgs; - } - } - ). - build(); - - assertCorrectVariableInitialisation(new long[] {length}, array); - } - - @Test - public void shouldConstructArrayOfGivenLengthWithBuilderAndCtorAndArgsProvider3Public() throws NoSuchMethodException { - long length = 9L; - - final Constructor constructor = - PublicMockStructure.class.getConstructor(PublicMockStructure.class); - final PublicMockStructure paramMock = new PublicMockStructure(); - final CtorAndArgs ctorAndArgs = - new CtorAndArgs(constructor, paramMock); - - @SuppressWarnings("unchecked") - StructuredArray array = - new StructuredArrayBuilder( - StructuredArray.class, - PublicMockStructure.class, - length). - elementCtorAndArgsProvider( - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - paramMock.setIndex(context.getIndex()); - paramMock.setTestValue(context.getIndex() * 2); - return ctorAndArgs; - } - } - ). - build(); - - assertCorrectVariableInitialisation(new long[] {length}, array); - } - - @Test - public void shouldConstructArrayFromCollection() throws NoSuchMethodException { - long length = 100; - ArrayList mockSource = new ArrayList(); - for (int i = 0; i < length; i++) { - mockSource.add(new MockStructure(i, i*2)); - } - - @SuppressWarnings("unchecked") - StructuredArray mocks = - StructuredArray.newInstance(lookup, StructuredArray.class, MockStructure.class, mockSource); - - assertThat(valueOf(mocks.get(5).getIndex()), is(valueOf(5))); - - assertCorrectVariableInitialisation(new long[] {length}, mocks); - } - - @Test - public void shouldConstructArrayFromCollectionPublic() throws NoSuchMethodException { - long length = 100; - ArrayList mockSource = new ArrayList(); - for (int i = 0; i < length; i++) { - mockSource.add(new PublicMockStructure(i, i*2)); - } - - @SuppressWarnings("unchecked") - StructuredArray mocks = StructuredArray.newInstance(StructuredArray.class, - PublicMockStructure.class, mockSource); - - assertThat(valueOf(mocks.get(5).getIndex()), is(valueOf(5))); - - assertCorrectVariableInitialisation(new long[] {length}, mocks); - } - - @Test - public void shouldConstructArrayElementsViaConstantCtorAndArgsProvider() throws NoSuchMethodException { - final Class[] initArgTypes = {long.class, long.class}; - final long expectedIndex = 4L; - final long expectedValue = 777L; - long length = 9L; - - final CtorAndArgs ctorAndArgs = - new CtorAndArgs(lookup, MockStructure.class, initArgTypes, expectedIndex, expectedValue); - final CtorAndArgsProvider ctorAndArgsProvider = - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return ctorAndArgs; - } - }; - - final StructuredArray array = - StructuredArray.newInstance(MockStructure.class, ctorAndArgsProvider, length); - - assertCorrectFixedInitialisation(expectedIndex, expectedValue, new long[]{length}, array); - } - - @Test - public void shouldConstructArrayElementsViaConstantCtorAndArgsProviderPublic() throws NoSuchMethodException { - final Class[] initArgTypes = {long.class, long.class}; - final long expectedIndex = 4L; - final long expectedValue = 777L; - long length = 9L; - - final CtorAndArgs ctorAndArgs = - new CtorAndArgs(PublicMockStructure.class, initArgTypes, expectedIndex, expectedValue); - final CtorAndArgsProvider ctorAndArgsProvider = - new CtorAndArgsProvider() { - @Override - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - return ctorAndArgs; - } - }; - - final StructuredArray array = - StructuredArray.newInstance(PublicMockStructure.class, ctorAndArgsProvider, length); - - assertCorrectFixedInitialisation(expectedIndex, expectedValue, new long[] {length}, array); - } - - @Test - public void shouldConstructArrayElementsViaCtorAndArgsProvider() throws NoSuchMethodException { - final long[] lengths = {9}; - final DefaultMockCtorAndArgsProvider ctorAndArgsProvider = new DefaultMockCtorAndArgsProvider(); - final StructuredArray array = - StructuredArray.newInstance(MockStructure.class, ctorAndArgsProvider, lengths[0]); - - assertCorrectVariableInitialisation(lengths, array); - } - - @Test - public void shouldConstructArrayElementsViaCtorAndArgsProviderPublic() throws NoSuchMethodException { - final long[] lengths = {9}; - final DefaultPublicMockCtorAndArgsProvider ctorAndArgsProvider = - new DefaultPublicMockCtorAndArgsProvider(); - final StructuredArray array = - StructuredArray.newInstance(PublicMockStructure.class, ctorAndArgsProvider, lengths[0]); - - assertCorrectVariableInitialisation(lengths, array); - } - - @SuppressWarnings("unchecked") - @Test - public void shouldConstructArrayElementsViaCtorAndArgsProvider3D() throws NoSuchMethodException { - final long[] lengths = {7, 8, 9}; - final DefaultMockCtorAndArgsProvider ctorAndArgsProvider = new DefaultMockCtorAndArgsProvider(); - - final StructuredArrayBuilder>>, - StructuredArray>> builder = get3dBuilder(lengths); - builder.getStructuredSubArrayBuilder(). - getStructuredSubArrayBuilder(). - elementCtorAndArgsProvider(ctorAndArgsProvider); - - final StructuredArray>> array = builder.build(); - - assertCorrectVariableInitialisation(lengths, array); - } - - @SuppressWarnings("unchecked") - @Test - public void shouldConstructArrayElementsViaCtorAndArgsProvider3DPublic() throws NoSuchMethodException { - final long[] lengths = {7, 8, 9}; - final DefaultPublicMockCtorAndArgsProvider ctorAndArgsProvider = - new DefaultPublicMockCtorAndArgsProvider(); - - final StructuredArrayBuilder>>, - StructuredArray>> builder = get3dBuilderPublic(lengths); - builder.getStructuredSubArrayBuilder(). - getStructuredSubArrayBuilder(). - elementCtorAndArgsProvider(ctorAndArgsProvider); - - final StructuredArray>> array = builder.build(); - - assertCorrectVariableInitialisation(lengths, array); - } - - @Test - public void shouldConstructArrayElementsViaLambdas() throws NoSuchMethodException { -// Uncomment for Java 8, keep commented for Java 7 and 6 -// -// final Constructor constructor = -// MockStructure.class.getConstructor(Long.TYPE, Long.TYPE); -// -// final long length = 8; -// final StructuredArray array = -// StructuredArray.newInstance(MockStructure.class, -// context -> new CtorAndArgs( -// constructor, -// context.getIndex(), context.getIndex() * 2), -// length); -// -// assertCorrectVariableInitialisation(new long[] {length}, array); -// -// final long[] lengths = {7, 8, 9}; -// -// final StructuredArrayBuilder>>, -// StructuredArray>> builder = get3dBuilder(lengths); -// builder.getSubArrayBuilder().getSubArrayBuilder().elementCtorAndArgsProvider( -// context -> { -// long indexSum = 0; -// for (ConstructionContext c = context; c != null; c = c.getContainingContext()) { -// indexSum += c.getIndex(); -// } -// return new CtorAndArgs(constructor, -// indexSum, (indexSum * 2L)); -// } -// ); -// -// final StructuredArray>> array2 = builder.build(); -// -// assertCorrectVariableInitialisation(lengths, array2); - } - - @Test - public void shouldSetAndGetCorrectValueAtGivenIndex() throws NoSuchMethodException { - final long[] lengths = {11, 10, 3}; - final StructuredArray>> array = get3dBuilder(lengths).build(); - - initValues(lengths, array); - assertCorrectVariableInitialisation(lengths, array); - } - - @Test - public void shouldIterateOverArray() throws NoSuchMethodException { - final long[] lengths = {11}; - final StructuredArray array = - StructuredArray.newInstance(lookup, MockStructure.class, lengths[0]); - - initValues(lengths, array); - - StructuredArray.ElementIterator iter = array.iterator(); - - long sum = 0; - long elementCount = 0; - while (iter.hasNext()) { - final long index = iter.getCursor(); - final MockStructure mockStructure = iter.next(); - - assertThat(valueOf(mockStructure.getIndex()), is(valueOf(index))); - assertThat(valueOf(mockStructure.getTestValue()), is(valueOf(index * 2))); - sum += index; - elementCount++; - } - - long sum2 = 0; - long elementCount2 = 0; - for (final MockStructure mockStructure : array) { - sum2 += mockStructure.getIndex(); - elementCount2++; - } - - assertThat(valueOf(elementCount), is(valueOf(array.getLength()))); - assertThat(valueOf(sum), is(valueOf(sum2))); - assertThat(valueOf(elementCount), is(valueOf(elementCount2))); - } - - @Test - public void shouldIterateOverArrayAndResetAgain() throws NoSuchMethodException { - final long length = 11; - final StructuredArray array = - StructuredArray.newInstance(lookup, MockStructure.class, length); - - initValues(new long[] {length}, array); - - int i = 0; - final StructuredArray.ElementIterator iter = array.iterator(); - while (iter.hasNext()) { - final long index = iter.getCursor(); - final MockStructure mockStructure = iter.next(); - assertThat(valueOf(mockStructure.getIndex()), is(valueOf(index))); - assertThat(valueOf(mockStructure.getTestValue()), is(valueOf(index * 2))); - i++; - } - - iter.reset(); - i = 0; - while (iter.hasNext()) { - final long index = iter.getCursor(); - final MockStructure mockStructure = iter.next(); - assertThat(valueOf(mockStructure.getIndex()), is(valueOf(index))); - assertThat(valueOf(mockStructure.getTestValue()), is(valueOf(index * 2))); - i++; - } - - assertThat(valueOf(i), is(valueOf(length))); - } - - @Test - public void shouldConstructCopyOfArray() throws NoSuchMethodException { - final long length = 15; - final DefaultMockCtorAndArgsProvider ctorAndArgsProvider = new DefaultMockCtorAndArgsProvider(); - final StructuredArray sourceArray = - StructuredArray.newInstance(MockStructure.class, ctorAndArgsProvider, length); - - assertThat(valueOf(sourceArray.getLength()), is(valueOf(length))); - assertTrue(sourceArray.getElementClass() == MockStructure.class); - - final StructuredArray newArray = StructuredArray.copyInstance(lookup, sourceArray); - - // We expect MockStructure elements to be initialized with index = index, and testValue = index * 2: - assertCorrectVariableInitialisation(new long[]{length}, newArray); - } - - @Test - public void shouldConstructCopyOfArrayPublic() throws NoSuchMethodException { - final long length = 15; - final DefaultPublicMockCtorAndArgsProvider ctorAndArgsProvider = new DefaultPublicMockCtorAndArgsProvider(); - final StructuredArray sourceArray = - StructuredArray.newInstance(PublicMockStructure.class, ctorAndArgsProvider, length); - - assertThat(valueOf(sourceArray.getLength()), is(valueOf(length))); - assertTrue(sourceArray.getElementClass() == PublicMockStructure.class); - - final StructuredArray newArray = StructuredArray.copyInstance(sourceArray); - - // We expect PublicMockStructure elements to be initialized with index = index, and testValue = index * 2: - assertCorrectVariableInitialisation(new long[] {length}, newArray); - } - - @SuppressWarnings("unchecked") - @Test - public void shouldConstructCopyOfArray3D() throws NoSuchMethodException { - final long[] lengths = {15, 7, 5}; - final DefaultMockCtorAndArgsProvider ctorAndArgsProvider = new DefaultMockCtorAndArgsProvider(); - - final StructuredArrayBuilder>>, - StructuredArray>> builder = get3dBuilder(lengths); - builder.getStructuredSubArrayBuilder(). - getStructuredSubArrayBuilder(). - elementCtorAndArgsProvider(ctorAndArgsProvider); - - final StructuredArray>> sourceArray = builder.build(); - - StructuredArray> subArray1 = sourceArray.get(0); - StructuredArray subArray2 = subArray1.get(0); - - assertThat(valueOf(sourceArray.getLength()), is(valueOf(lengths[0]))); - assertThat(valueOf(subArray1.getLength()), is(valueOf(lengths[1]))); - assertThat(valueOf(subArray2.getLength()), is(valueOf(lengths[2]))); - assertTrue(subArray2.getElementClass() == MockStructure.class); - - final StructuredArray>> newArray = - StructuredArray.copyInstance(lookup, sourceArray); - - // We expect MockStructure elements to be initialized with index = index, and testValue = index * 2: - assertCorrectVariableInitialisation(lengths, newArray); - } - - @SuppressWarnings("unchecked") - @Test - public void shouldConstructCopyOfArray3DPublic() throws NoSuchMethodException { - final long[] lengths = {15, 7, 5}; - final DefaultPublicMockCtorAndArgsProvider ctorAndArgsProvider = new DefaultPublicMockCtorAndArgsProvider(); - - final StructuredArrayBuilder>>, - StructuredArray>> builder = get3dBuilderPublic(lengths); - builder.getStructuredSubArrayBuilder(). - getStructuredSubArrayBuilder(). - elementCtorAndArgsProvider(ctorAndArgsProvider); - - final StructuredArray>> sourceArray = builder.build(); - - StructuredArray> subArray1 = sourceArray.get(0); - StructuredArray subArray2 = subArray1.get(0); - - assertThat(valueOf(sourceArray.getLength()), is(valueOf(lengths[0]))); - assertThat(valueOf(subArray1.getLength()), is(valueOf(lengths[1]))); - assertThat(valueOf(subArray2.getLength()), is(valueOf(lengths[2]))); - assertTrue(subArray2.getElementClass() == PublicMockStructure.class); - - final StructuredArray>> newArray = - StructuredArray.copyInstance(sourceArray); - - // We expect PublicMockStructure elements to be initialized with index = index, and testValue = index * 2: - assertCorrectVariableInitialisation(lengths, newArray); - } - - @SuppressWarnings("unchecked") - @Test - public void shouldConstructCopyOfArrayRange() throws NoSuchMethodException { - final long[] lengths = {15, 7, 5}; - final DefaultMockCtorAndArgsProvider ctorAndArgsProvider = new DefaultMockCtorAndArgsProvider(); - - final StructuredArrayBuilder>>, - StructuredArray>> builder = get3dBuilder(lengths); - builder.getStructuredSubArrayBuilder(). - getStructuredSubArrayBuilder(). - elementCtorAndArgsProvider(ctorAndArgsProvider); - - final StructuredArray>> sourceArray = builder.build(); - - StructuredArray> subArray1 = sourceArray.get(0); - StructuredArray subArray2 = subArray1.get(0); - - assertThat(valueOf(sourceArray.getLength()), is(valueOf(lengths[0]))); - assertThat(valueOf(subArray1.getLength()), is(valueOf(lengths[1]))); - assertThat(valueOf(subArray2.getLength()), is(valueOf(lengths[2]))); - assertTrue(subArray2.getElementClass() == MockStructure.class); - - long[] offsets = {2, 2, 2}; - long[] counts = {13, 5, 3}; - final StructuredArray>> newArray = - StructuredArray.copyInstance(lookup, sourceArray, offsets, counts); - - assertCorrectVariableInitialisation(counts, newArray, 2); - } - - @Test(expected = ArrayIndexOutOfBoundsException.class) - public void shouldThrowOutOfBoundExceptionForAccessesOutOfBounds() throws NoSuchMethodException { - final long length = 11; - final StructuredArray array = - StructuredArray.newInstance(lookup, MockStructure.class, length); - - array.get(length); - } - - @Test - public void shouldNotThrowIncompatibleTypeExceptionForGetsOfProperTypes() throws NoSuchMethodException { - final long[] lengths = {11, 7, 4}; - final StructuredArray>> array = get3dBuilder(lengths).build(); - - // Step by step gets of the correct type (array vs. element) per dimension: - StructuredArray> subArray1 = array.get(2); - StructuredArray subArray2 = subArray1.get(2); - subArray2.get(2); - - } - - @Test - public void shouldCopyRegionLeftInArray() throws NoSuchMethodException { - final long length = 11; - final StructuredArray array = - StructuredArray.newInstance(lookup, MockStructure.class, length); - - initValues(new long[]{length}, array); - - StructuredArray.shallowCopy(array, 4, array, 3, 2, false); - - assertThat(valueOf(array.get(3).getIndex()), is(valueOf(4))); - assertThat(valueOf(array.get(4).getIndex()), is(valueOf(5))); - assertThat(valueOf(array.get(5).getIndex()), is(valueOf(5))); - } - - @Test - public void shouldCopyRegionRightInArray() throws NoSuchMethodException { - final long length = 11; - final StructuredArray array = - StructuredArray.newInstance(lookup, MockStructure.class, length); - - initValues(new long[]{length}, array); - - StructuredArray.shallowCopy(array, 5, array, 6, 2, false); - - assertThat(valueOf(array.get(5).getIndex()), is(valueOf(5))); - assertThat(valueOf(array.get(6).getIndex()), is(valueOf(5))); - assertThat(valueOf(array.get(7).getIndex()), is(valueOf(6))); - } - - @Test - public void shouldCopyEvenWithFinalFields() throws NoSuchMethodException { - final long length = 11; - final StructuredArray array = - StructuredArray.newInstance(lookup, MockStructureWithFinalField.class, length); - - StructuredArray.shallowCopy(array, 1, array, 3, 1, true); - } - - @Test(expected = IllegalArgumentException.class) - public void shouldThrowExceptionWhenFinalFieldWouldBeCopied() throws NoSuchMethodException { - final long length = 11; - final StructuredArray array = - StructuredArray.newInstance(lookup, MockStructureWithFinalField.class, length); - - StructuredArray.shallowCopy(array, 1, array, 3, 1); - } - - @Test - public void moveObjectsIntoNewArray() throws NoSuchMethodException { - int length = 100; - ArrayList sourceMocks = new ArrayList(length); - for (int i = 0; i < length; i++) { - sourceMocks.add(new MockStructure(i, i * 2)); - } - - @SuppressWarnings("unchecked") - StructuredArrayBuilder, MockStructure> builder = - new StructuredArrayBuilder( - lookup, - StructuredArray.class, - MockStructure.class, - length - ); - builder.elementCtorAndArgsProvider(new CopyFromArrayListProvider(sourceMocks)); - StructuredArray mocks = builder.build(); - assertThat(valueOf(mocks.get(5).getIndex()), is(valueOf(5))); - assertThat(valueOf(mocks.get(5).getTestValue()), is(valueOf(10))); - MockStructure mock = mocks.get(7); - } - - - /////////////////////////////////////////////////////////////////////////////////////////////// - // Test support below - /////////////////////////////////////////////////////////////////////////////////////////////// - - private void assertCorrectFixedInitialisation( - final long expectedIndex, - final long expectedValue, - final long[] lengths, - final StructuredArray array) { - StructuredArray a = array; - for (int i = 0; i < lengths.length - 1; i++) { - assertThat(valueOf(a.getLength()), is(valueOf(lengths[i]))); - a = (StructuredArray) a.get(0); - } - assertThat(valueOf(a.getLength()), is(valueOf(lengths[lengths.length - 1]))); - - assertTrue(MockStructure.class.isAssignableFrom(a.getElementClass())); - - long totalElementCount = 1; - for (long l : lengths) { - totalElementCount *= l; - } - - final long[] cursors = new long[lengths.length]; - - long elementCountToCursor = 0; - - while (elementCountToCursor < totalElementCount) { - // Check element at cursors: - // Check element at cursors: - a = array; - for (int i = 0; i < cursors.length - 1; i++) { - a = (StructuredArray) a.get(cursors[i]); - } - MockStructure mockStructure = (MockStructure) a.get(cursors[cursors.length - 1]); - - assertThat(valueOf(mockStructure.getIndex()), is(valueOf(expectedIndex))); - assertThat(valueOf(mockStructure.getTestValue()), is(valueOf(expectedValue))); - - // Increment cursors from inner-most dimension out: - for (int cursorDimension = cursors.length - 1; cursorDimension >= 0; cursorDimension--) { - if ((++cursors[cursorDimension]) < lengths[cursorDimension]) { - break; - } - // This dimension wrapped. Reset to zero and continue to one dimension higher - cursors[cursorDimension] = 0; - } - elementCountToCursor++; - } - } - - private void assertCorrectVariableInitialisation(final long[] lengths, - final StructuredArray array) { - assertCorrectVariableInitialisation(lengths, array, 0); - } - - private void assertCorrectVariableInitialisation(final long[] lengths, - final StructuredArray array, long indexOffset) { - StructuredArray a = array; - for (int i = 0; i < lengths.length - 1; i++) { - assertThat(valueOf(a.getLength()), is(valueOf(lengths[i]))); - a = (StructuredArray) a.get(0); - } - assertThat(valueOf(a.getLength()), is(valueOf(lengths[lengths.length - 1]))); - - assertTrue(MockStructure.class.isAssignableFrom(a.getElementClass())); - - long totalElementCount = 1; - for (long l : lengths) { - totalElementCount *= l; - } - - final long[] cursors = new long[lengths.length]; - - long elementCountToCursor = 0; - - while (elementCountToCursor < totalElementCount) { - // Check element at cursors: - a = array; - for (int i = 0; i < cursors.length - 1; i++) { - a = (StructuredArray) a.get(cursors[i]); - } - MockStructure mockStructure = (MockStructure) a.get(cursors[cursors.length - 1]); - - long indexSum = 0; - String cursorsString = ""; - for (long index : cursors) { - indexSum += index + indexOffset; - cursorsString += index + ","; - } - - assertThat("elementCountToCursor: " + elementCountToCursor + " cursors: " + cursorsString, - valueOf(mockStructure.getIndex()), is(valueOf(indexSum))); - assertThat("elementCountToCursor: " + elementCountToCursor + " cursors: " + cursorsString, - valueOf(mockStructure.getTestValue()), is(valueOf(indexSum * 2))); - - // Increment cursors from inner-most dimension out: - for (int cursorDimension = cursors.length - 1; cursorDimension >= 0; cursorDimension--) { - if ((++cursors[cursorDimension]) < lengths[cursorDimension]) { - break; - } - // This dimension wrapped. Reset to zero and continue to one dimension higher - cursors[cursorDimension] = 0; - } - elementCountToCursor++; - } - } - - private void initValues(final long[] lengths, final StructuredArray array) { - final long[] cursors = new long[lengths.length]; - long totalElementCount = 1; - for (long l : lengths) { - totalElementCount *= l; - } - - long elementCountToCursor = 0; - - while (elementCountToCursor < totalElementCount) { - // Check element at cursors: - StructuredArray a = array; - for (int i = 0; i < cursors.length - 1; i++) { - a = (StructuredArray) a.get(cursors[i]); - } - MockStructure mockStructure = (MockStructure) a.get(cursors[cursors.length - 1]); - - long indexSum = 0; - for (long index : cursors) { - indexSum += index; - } - - mockStructure.setIndex(indexSum); - mockStructure.setTestValue(indexSum * 2); - - // Increment cursors from inner-most dimension out: - for (int cursorDimension = cursors.length - 1; cursorDimension >= 0; cursorDimension--) { - if ((++cursors[cursorDimension]) < lengths[cursorDimension]) { - break; - } - - // This dimension wrapped. Reset to zero and continue to one dimension higher - cursors[cursorDimension] = 0; - } - elementCountToCursor++; - } - } - - public static class PublicMockStructure extends MockStructure { - public PublicMockStructure() { - } - - public PublicMockStructure(final long index, final long testValue) { - super(index, testValue); - } - - public PublicMockStructure(final PublicMockStructure src) { - super(src); - } - } - - private static class MockStructure { - - private long index = -1; - private long testValue = Long.MIN_VALUE; - - public MockStructure() { - } - - public MockStructure(final long index, final long testValue) { - this.index = index; - this.testValue = testValue; - } - - public MockStructure(final MockStructure src) { - this.index = src.index; - this.testValue = src.testValue; - } - - public long getIndex() { - return index; - } - - public void setIndex(final long index) { - this.index = index; - } - - public long getTestValue() { - return testValue; - } - - public void setTestValue(final long testValue) { - this.testValue = testValue; - } - - public boolean equals(final Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - final MockStructure that = (MockStructure)o; - - return index == that.index && testValue == that.testValue; - } - - public int hashCode() { - int result = (int)(index ^ (index >>> 32)); - result = 31 * result + (int)(testValue ^ (testValue >>> 32)); - return result; - } - - public String toString() { - return "MockStructure{" + - "index=" + index + - ", testValue=" + testValue + - '}'; - } - } - - public static class MockStructureWithFinalField { - private final int value = 888; - } - - private static class DefaultPublicMockCtorAndArgsProvider implements CtorAndArgsProvider { - private final Class[] argsTypes = {Long.TYPE, Long.TYPE}; - - public CtorAndArgs getForContext( - ConstructionContext context) throws NoSuchMethodException { - long indexSum = 0; - for (ConstructionContext c = context; c != null; c = c.getContainingContext()) { - indexSum += c.getIndex(); - } - Object[] args = {indexSum, indexSum * 2}; - // We could do this much more efficiently with atomic caching of a single allocated CtorAndArgs, - // as CopyCtorAndArgsProvider does, but no need to put in the effort in a test... - return new CtorAndArgs(PublicMockStructure.class, argsTypes, args); - } - } - - private static class DefaultMockCtorAndArgsProvider implements CtorAndArgsProvider { - - private final Class[] argsTypes = {Long.TYPE, Long.TYPE}; - - public CtorAndArgs getForContext(ConstructionContext context) throws NoSuchMethodException { - long indexSum = 0; - for (ConstructionContext c = context; c != null; c = c.getContainingContext()) { - indexSum += c.getIndex(); - } - Object[] args = {indexSum, indexSum * 2}; - // We could do this much more efficiently with atomic caching of a single allocated CtorAndArgs, - // as CopyCtorAndArgsProvider does, but no need to put in the effort in a test... - return new CtorAndArgs(lookup, MockStructure.class, argsTypes, args); - } - } - - - private static class CopyFromArrayListProvider implements CtorAndArgsProvider { - - static final Constructor copyCtor; - - static { - try { - copyCtor = MockStructure.class.getConstructor(new Class[]{MockStructure.class}); - copyCtor.setAccessible(true); // When constructor is passed in, setAccessible is the caller responsibility... - } catch (NoSuchMethodException ex) { - throw new RuntimeException(ex); - } - } - - private final ArrayList fromList; - - public CopyFromArrayListProvider(ArrayList fromList) { - this.fromList = fromList; - } - - public CtorAndArgs getForContext(ConstructionContext context) throws NoSuchMethodException { - return new CtorAndArgs(copyCtor, fromList.get((int) context.getIndex())); - } - } - - StructuredArrayBuilder>>, - StructuredArray>> get3dBuilder(long... lengths) { - @SuppressWarnings("unchecked") - StructuredArrayBuilder>>, - StructuredArray>> builder = - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - lookup, - StructuredArray.class, - MockStructure.class, - lengths[2] - ), - lengths[1] - ), - lengths[0] - ); - return builder; - } - - StructuredArrayBuilder>>, - StructuredArray>> get3dBuilderPublic(long... lengths) { - @SuppressWarnings("unchecked") - StructuredArrayBuilder>>, - StructuredArray>> builder = - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - StructuredArray.class, - new StructuredArrayBuilder( - StructuredArray.class, - PublicMockStructure.class, - lengths[2] - ), - lengths[1] - ), - lengths[0] - ); - return builder; - } -} diff --git a/README.md b/README.md deleted file mode 100644 index 1a06bb7..0000000 --- a/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# ObjectLayout - -[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/ObjectLayout/ObjectLayout?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -ObjectLayout is aimed at creating some useful core Java classes that are designed with optimizable memory layout in mind - -See http://objectlayout.github.io/ObjectLayout/ for some detail diff --git a/index.html b/index.html new file mode 100644 index 0000000..a5476ef --- /dev/null +++ b/index.html @@ -0,0 +1,115 @@ + + + + + + ObjectLayout by giltene and mjpt777 + + + + + + + +
+
+

org.ObjectLayout

+

A layout-optimized Java data structure package

+ +

+ View the Project on GitHub ObjectLayout/ObjectLayout

+ +

+ View the Project JavaDoc ObjectLayout.github.com/ObjectLayout/JavaDoc

+ + + +
+
+

org.ObjectLayout: A layout-optimized Java data structure package

+ +

+ The org.ObjectLayout package provides a set of data structure classes designed with optimised memory + layout in mind. These classes are aimed at matching the natural speed benefits similar data + structure constructs enable in most C-style languages, while maintaining an idiomatic Java feel + and a natural fit with existing code and libraries. +

+

+ The package classes provide full functionality on all JVMs (of Java SE 7 or above) at reasonable layouts + and execution speeds. However, the classes are carefully designed with semantics that would allow an + optimised JVM to implement them with improved memory layout not directly expressible in Java. +

+

The common C-style constructs org.ObjectLayout seeks to match are:

+
    +
  • An array of structs: +
    struct foo[];
  • +
  • A struct with a struct inside:
    + struct foo { int a; bar b; int c; };
  • +
  • A struct with an array at the end:
    + struct foo { int len; char[] payload; };
  • +
+

+ These common C-style constructs, both individually and in composed forms, provide tangible + access speed benefits. The natural memory-layouts involved facilitate both dead-reckoning + (avoiding de-referencing and data-dependent loads) and memory streaming optimizations. +

+

The matching org.ObjectLayout forms

+

+

+ StructuredArray is meant to provide an idiomatic Java collection form + with speed (and semantics) similar to an "array of structs" form, supporting any constructable + java Object as an array member. +

+

+ @Intrinsic provides an idiomatic Java means for declaring + member objects that are intrinsic to the instances of the class they are declared in. + @Intrinsic provides a "struct in struct" equivalent + relationship between Java objects, exposing the speed and layout benefits similar to the same + form in the C family languages. +

+

+ Sub-classable Primitive and Reference array classes (e.g. + PrimitiveLongArray + and + ReferenceArray + ) are meant to support an idiomatic Java means of + declaring constructs with speed (and semantics) similar to "struct with array at the end". They do + so by supporting the subclassing of arrays of the various primitive and reference forms possible + in Java. + StructuredArray similarly supports this capability (via + subclassing) for the equivalent of "struct with array of structs at the end". +

+ +

Authors, Contributors, and License

+ +

+ ObjectLayout was authored by Gil Tene + (@giltene) + and Martin Thompson (@mjpt777) + and placed in the public domain, as explained at + http://creativecommons.org/publicdomain/zero/1.0/ +

+ +

Support or Contact

+

Don't call us, We won't call you.

+ +
+ + +
+ + + + diff --git a/javascripts/scale.fix.js b/javascripts/scale.fix.js new file mode 100644 index 0000000..87a40ca --- /dev/null +++ b/javascripts/scale.fix.js @@ -0,0 +1,17 @@ +var metas = document.getElementsByTagName('meta'); +var i; +if (navigator.userAgent.match(/iPhone/i)) { + for (i=0; i` element will link to the contributor's GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.\r\n\r\n### Support or Contact\r\nHaving trouble with Pages? Check out the documentation at http://help.github.com/pages or contact support@github.com and we’ll help you sort it out.","name":"HdrHistogram","tagline":"A High Dynamic Range (HDR) Histogram"} \ No newline at end of file diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 99eea2c..0000000 --- a/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - 4.0.0 - - org.objectlayout - ObjectLayout-parent - 1.0.5-SNAPSHOT - - ObjectLayout - pom - - - UTF-8 - - - - ObjectLayout - ObjectLayout-benchmarks - ObjectLayout-examples - - diff --git a/stylesheets/pygment_trac.css b/stylesheets/pygment_trac.css new file mode 100644 index 0000000..c6a6452 --- /dev/null +++ b/stylesheets/pygment_trac.css @@ -0,0 +1,69 @@ +.highlight { background: #ffffff; } +.highlight .c { color: #999988; font-style: italic } /* Comment */ +.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ +.highlight .k { font-weight: bold } /* Keyword */ +.highlight .o { font-weight: bold } /* Operator */ +.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */ +.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */ +.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */ +.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */ +.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ +.highlight .gd .x { color: #000000; background-color: #ffaaaa } /* Generic.Deleted.Specific */ +.highlight .ge { font-style: italic } /* Generic.Emph */ +.highlight .gr { color: #aa0000 } /* Generic.Error */ +.highlight .gh { color: #999999 } /* Generic.Heading */ +.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ +.highlight .gi .x { color: #000000; background-color: #aaffaa } /* Generic.Inserted.Specific */ +.highlight .go { color: #888888 } /* Generic.Output */ +.highlight .gp { color: #555555 } /* Generic.Prompt */ +.highlight .gs { font-weight: bold } /* Generic.Strong */ +.highlight .gu { color: #800080; font-weight: bold; } /* Generic.Subheading */ +.highlight .gt { color: #aa0000 } /* Generic.Traceback */ +.highlight .kc { font-weight: bold } /* Keyword.Constant */ +.highlight .kd { font-weight: bold } /* Keyword.Declaration */ +.highlight .kn { font-weight: bold } /* Keyword.Namespace */ +.highlight .kp { font-weight: bold } /* Keyword.Pseudo */ +.highlight .kr { font-weight: bold } /* Keyword.Reserved */ +.highlight .kt { color: #445588; font-weight: bold } /* Keyword.Type */ +.highlight .m { color: #009999 } /* Literal.Number */ +.highlight .s { color: #d14 } /* Literal.String */ +.highlight .na { color: #008080 } /* Name.Attribute */ +.highlight .nb { color: #0086B3 } /* Name.Builtin */ +.highlight .nc { color: #445588; font-weight: bold } /* Name.Class */ +.highlight .no { color: #008080 } /* Name.Constant */ +.highlight .ni { color: #800080 } /* Name.Entity */ +.highlight .ne { color: #990000; font-weight: bold } /* Name.Exception */ +.highlight .nf { color: #990000; font-weight: bold } /* Name.Function */ +.highlight .nn { color: #555555 } /* Name.Namespace */ +.highlight .nt { color: #000080 } /* Name.Tag */ +.highlight .nv { color: #008080 } /* Name.Variable */ +.highlight .ow { font-weight: bold } /* Operator.Word */ +.highlight .w { color: #bbbbbb } /* Text.Whitespace */ +.highlight .mf { color: #009999 } /* Literal.Number.Float */ +.highlight .mh { color: #009999 } /* Literal.Number.Hex */ +.highlight .mi { color: #009999 } /* Literal.Number.Integer */ +.highlight .mo { color: #009999 } /* Literal.Number.Oct */ +.highlight .sb { color: #d14 } /* Literal.String.Backtick */ +.highlight .sc { color: #d14 } /* Literal.String.Char */ +.highlight .sd { color: #d14 } /* Literal.String.Doc */ +.highlight .s2 { color: #d14 } /* Literal.String.Double */ +.highlight .se { color: #d14 } /* Literal.String.Escape */ +.highlight .sh { color: #d14 } /* Literal.String.Heredoc */ +.highlight .si { color: #d14 } /* Literal.String.Interpol */ +.highlight .sx { color: #d14 } /* Literal.String.Other */ +.highlight .sr { color: #009926 } /* Literal.String.Regex */ +.highlight .s1 { color: #d14 } /* Literal.String.Single */ +.highlight .ss { color: #990073 } /* Literal.String.Symbol */ +.highlight .bp { color: #999999 } /* Name.Builtin.Pseudo */ +.highlight .vc { color: #008080 } /* Name.Variable.Class */ +.highlight .vg { color: #008080 } /* Name.Variable.Global */ +.highlight .vi { color: #008080 } /* Name.Variable.Instance */ +.highlight .il { color: #009999 } /* Literal.Number.Integer.Long */ + +.type-csharp .highlight .k { color: #0000FF } +.type-csharp .highlight .kt { color: #0000FF } +.type-csharp .highlight .nf { color: #000000; font-weight: normal } +.type-csharp .highlight .nc { color: #2B91AF } +.type-csharp .highlight .nn { color: #000000 } +.type-csharp .highlight .s { color: #A31515 } +.type-csharp .highlight .sc { color: #A31515 } diff --git a/stylesheets/styles.css b/stylesheets/styles.css new file mode 100644 index 0000000..dacf2e1 --- /dev/null +++ b/stylesheets/styles.css @@ -0,0 +1,255 @@ +@import url(https://fonts.googleapis.com/css?family=Lato:300italic,700italic,300,700); + +body { + padding:50px; + font:14px/1.5 Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + color:#777; + font-weight:300; +} + +h1, h2, h3, h4, h5, h6 { + color:#222; + margin:0 0 20px; +} + +p, ul, ol, table, pre, dl { + margin:0 0 20px; +} + +h1, h2, h3 { + line-height:1.1; +} + +h1 { + font-size:28px; +} + +h2 { + color:#393939; +} + +h3, h4, h5, h6 { + color:#494949; +} + +a { + color:#39c; + font-weight:400; + text-decoration:none; +} + +a small { + font-size:11px; + color:#777; + margin-top:-0.6em; + display:block; +} + +.wrapper { + width:860px; + margin:0 auto; +} + +blockquote { + border-left:1px solid #e5e5e5; + margin:0; + padding:0 0 0 20px; + font-style:italic; +} + +code, pre { + font-family:Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal; + color:#333; + font-size:12px; +} + +pre { + padding:8px 15px; + background: #f8f8f8; + border-radius:5px; + border:1px solid #e5e5e5; + overflow-x: auto; +} + +table { + width:100%; + border-collapse:collapse; +} + +th, td { + text-align:left; + padding:5px 10px; + border-bottom:1px solid #e5e5e5; +} + +dt { + color:#444; + font-weight:700; +} + +th { + color:#444; +} + +img { + max-width:100%; +} + +header { + width:270px; + float:left; + position:fixed; +} + +header ul { + list-style:none; + height:40px; + + padding:0; + + background: #eee; + background: -moz-linear-gradient(top, #f8f8f8 0%, #dddddd 100%); + background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f8f8f8), color-stop(100%,#dddddd)); + background: -webkit-linear-gradient(top, #f8f8f8 0%,#dddddd 100%); + background: -o-linear-gradient(top, #f8f8f8 0%,#dddddd 100%); + background: -ms-linear-gradient(top, #f8f8f8 0%,#dddddd 100%); + background: linear-gradient(top, #f8f8f8 0%,#dddddd 100%); + + border-radius:5px; + border:1px solid #d2d2d2; + box-shadow:inset #fff 0 1px 0, inset rgba(0,0,0,0.03) 0 -1px 0; + width:270px; +} + +header li { + width:89px; + float:left; + border-right:1px solid #d2d2d2; + height:40px; +} + +header ul a { + line-height:1; + font-size:11px; + color:#999; + display:block; + text-align:center; + padding-top:6px; + height:40px; +} + +strong { + color:#222; + font-weight:700; +} + +header ul li + li { + width:88px; + border-left:1px solid #fff; +} + +header ul li + li + li { + border-right:none; + width:89px; +} + +header ul a strong { + font-size:14px; + display:block; + color:#222; +} + +section { + width:500px; + float:right; + padding-bottom:50px; +} + +small { + font-size:11px; +} + +hr { + border:0; + background:#e5e5e5; + height:1px; + margin:0 0 20px; +} + +footer { + width:270px; + float:left; + position:fixed; + bottom:50px; +} + +@media print, screen and (max-width: 960px) { + + div.wrapper { + width:auto; + margin:0; + } + + header, section, footer { + float:none; + position:static; + width:auto; + } + + header { + padding-right:320px; + } + + section { + border:1px solid #e5e5e5; + border-width:1px 0; + padding:20px 0; + margin:0 0 20px; + } + + header a small { + display:inline; + } + + header ul { + position:absolute; + right:50px; + top:52px; + } +} + +@media print, screen and (max-width: 720px) { + body { + word-wrap:break-word; + } + + header { + padding:0; + } + + header ul, header p.view { + position:static; + } + + pre, code { + word-wrap:normal; + } +} + +@media print, screen and (max-width: 480px) { + body { + padding:15px; + } + + header ul { + display:none; + } +} + +@media print { + body { + padding:0.4in; + font-size:12pt; + color:#444; + } +}