public final class Affinity extends Object implements Serializable, Cloneable
An instance of Affinity is an immutable set of processors. The processors are identified by integer numbers with a platform-dependent meaning.
An Affinity can be set to be used by a Thread or a BoundAsyncEventHandler. This setting is modifiable at runtime.
Affinity sets containing more than one processor are only supported for pre-defined affinity sets provided by the VM. getPredefinedAffinities() returns an array of all these predefined sets.
Changes of the number of CPUs available may cause cause failures such as deadlocks. Therefore, dynamically enabling or disabling CPUs should be disabled, at least for those CPUs used for RTSJ threads.
For JamaicaVM, the processors ids correspond to the processor ids that are passed to the VM or to the builder command via the option -Xcpus.
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Creates and returns a copy of this object.
|
boolean |
equals(Object other)
Indicates whether some other object is "equal to" this one.
|
static Affinity |
generate(BitSet set)
Determines the Affinity corresponding to a
BitSet , where each
bit in set represents a CPU. |
static Affinity |
getAffinity(Thread thread)
Obtain the affinity of the current thread.
|
static BitSet |
getAvailableProcessors()
Short hand for getAvailableProcessors(null).
|
static BitSet |
getAvailableProcessors(BitSet dest)
Determine the set of processors that are currently available for
the Java VM to execute Java code.
|
static Affinity |
getCurrentAffinity()
Obtain the affinity of the current thread.
|
static Affinity[] |
getPredefinedAffinities()
Short hand for getPredefinedAffinities(null)
|
static Affinity[] |
getPredefinedAffinities(Affinity[] dest)
Copy the set of all predefined affinity sets to an array
|
static int |
getPredefinedAffinitiesCount()
Determine the number or predefined affinities.
|
static AsyncEvent |
getProcessorAddedEvent()
Gets the event used for CPU addition notification.
|
int |
getProcessorCount()
Determines the number of CPUs in this affinity
|
static AsyncEvent |
getProcessorRemovedEvent()
Gets the event used for CPU removal notification.
|
BitSet |
getProcessors()
Return a newly allocated BitSet containing the CPU ids for the
CPUs in this affinity set.
|
BitSet |
getProcessors(BitSet dest)
Determines the set of CPUs representing the processor affinity
of this
Affinity . |
static Affinity |
getRootAffinity()
Gets the root Affinity: the Affinity that can be used to allow
a schedulable to run on all the processing units available to the VM.
|
static boolean |
isAffinityChangeNotificationSupported()
Determines whether or not the system can trigger an event for notifying
the application when the set of available CPUs changes.
|
boolean |
isProcessorInSet(int processorId)
Check whether a processor is included in this affinity set.
|
static boolean |
isSetAffinitySupported()
Check whether affinity setting (via methods
setProcessorAffinity(set, ...) is supported by this VM.
|
boolean |
isValid()
Determines whether or not the affinity can be used for scheduling or
just for limiting the processors available to members of
RealtimeThreadGroup . |
static void |
setProcessorAddedEvent(AsyncEvent event)
Sets the AsyncEvent that will be fired when a processor is added to
the set available to the JVM.
|
static void |
setProcessorRemovedEvent(AsyncEvent event)
Sets the
AsyncEvent that will be fired when a processor is
removed from the set available to the JVM. |
boolean |
subsumes(Affinity other)
Determines whether or not
other is equal to or a proper subset
of this affinity. |
String |
toString()
Returns a String representing this Affinity in the form of
"Affinity("+processorSet+")".
|
public static Affinity generate(BitSet set)
BitSet
, where each
bit in set
represents a CPU. When BitSet
does not
correspond to a predefined affinity or a affinity with a cardinality of
one, the resulting Affinity
instance is not a valid affinity and
can only be used for limiting the CPUs that can be used by a
RealtimeThreadGroup
. The method isValid()
can be used to
determine whether or not the result is a valid affinity.
Platforms that support specific affinities will register those
Affinity
instances with Affinity
. They
appear in the arrays returned by getPredefinedAffinities()
and getPredefinedAffinities(Affinity[])
.
StaticIllegalArgumentException
- when set
is null
or when set
is empty.set
- the set
of CPUs that should be in the Affinity
.Affinity
such that
result.getProcessors().equals(bitSet)
.public static BitSet getAvailableProcessors()
public static BitSet getAvailableProcessors(BitSet dest)
dest
- a BitSet
to receive the set of available CPUs. May
be null to ask for allocation of a new BitSet
.public static int getPredefinedAffinitiesCount()
public static Affinity[] getPredefinedAffinities()
public static Affinity[] getPredefinedAffinities(Affinity[] dest)
StaticIllegalArgumentException
- in case dest != null
but dest.length() < getPredefinedAffinitiesCount().dest
- (out!) the array the predefined sets should be copied
to, null to allocate a new array.null
.public static boolean isSetAffinitySupported()
public static Affinity getRootAffinity()
Affinity
.public static Affinity getAffinity(Thread thread)
StaticIllegalArgumentException
- when the affinity is not valid.public static Affinity getCurrentAffinity()
public BitSet getProcessors()
public final BitSet getProcessors(BitSet dest)
Affinity
.dest
- Set dest
to the BitSet
value.
When dest
is null
, create a new
BitSet
in the current allocation context.BitSet
representing the processor affinity
set of this Affinity
.public final boolean isProcessorInSet(int processorId)
processorId
- A number identifying a single CPU in a
multiprocessor system.true
when and only when processorId
is
represented in this affinity set.public boolean isValid()
RealtimeThreadGroup
.true
when valid for scheduling and false
otherwise.public int getProcessorCount()
public static final boolean isAffinityChangeNotificationSupported()
true
when change notification is supported. (See
setProcessorAddedEvent(AsyncEvent)
and
setProcessorRemovedEvent(AsyncEvent)
.)public static AsyncEvent getProcessorAddedEvent()
null
when change notification is not supported,
or when no asynchronous event has been designated.public static void setProcessorAddedEvent(AsyncEvent event) throws StaticUnsupportedOperationException, StaticIllegalArgumentException
StaticUnsupportedOperationException
- when change notification
is not supported.StaticIllegalArgumentException
- when event
is
not in immortal memory.event
- The asynchronous event to fire in case an added
processor is detected, or null
to cause no
asynchronous event to be called in case an added processor
is detected.public static AsyncEvent getProcessorRemovedEvent() throws StaticUnsupportedOperationException
StaticUnsupportedOperationException
- when change notification
is not supported.null
when change notification is not supported,
or when no asynchronous event has been designated.public static void setProcessorRemovedEvent(AsyncEvent event) throws StaticUnsupportedOperationException, StaticIllegalArgumentException
AsyncEvent
that will be fired when a processor is
removed from the set available to the JVM.StaticUnsupportedOperationException
- when change notification
is not supported.StaticIllegalArgumentException
- when event
is
not null
or in immortal memory.event
- Called when a processor is removed.public boolean equals(Object other)
Object
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class Object
other
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
public String toString()
public boolean subsumes(Affinity other)
other
is equal to or a proper subset
of this affinity.other
- The other affinity with which to comparetrue
Only when the affinity in parameter is a equal to
or a proper subset of this affinity.public Object clone()
Object
x
, the expression:
will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true
, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x)
true
, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
super.clone
. If a class and all of its superclasses (except
Object
) obey this convention, it will be the case that
x.clone().getClass() == x.getClass()
.
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by super.clone
before returning it. Typically, this means
copying any mutable objects that comprise the internal "deep structure"
of the object being cloned and replacing the references to these
objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually
the case that no fields in the object returned by super.clone
need to be modified.
The method clone
for class Object
performs a
specific cloning operation. First, if the class of this object does
not implement the interface Cloneable
, then a
CloneNotSupportedException
is thrown. Note that all arrays
are considered to implement the interface Cloneable
and that
the return type of the clone
method of an array type T[]
is T[]
where T is any reference or primitive type.
Otherwise, this method creates a new instance of the class of this
object and initializes all its fields with exactly the contents of
the corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned. Thus, this method
performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object
does not itself implement the interface
Cloneable
, so calling the clone
method on an object
whose class is Object
will result in throwing an
exception at run time.
aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2025 aicas GmbH. All Rights Reserved.