public 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 options -Xcpus or -XcpusFromEnv.
NYI: UNDER DEVELOPMENT: From the Spec: Real-time threads and bound async event handlers that have processing group parameters are members of that processing group, and their processor affinity is governed by the intersection of the processing group's affinity and the schedulable object's affinity. The affinity set of a processing group must have exactly one processor, so the intersection of that set with the schedulable object's affinity set must contain at most one entry. If the intersection is empty the affinity defaults. Ordinarily, an execution context inherits its creator's affinity set, but: Java threads do not inherit affinity from SOs Unbound async event handlers cannot be assigned a non-default affinity. SOs do not inherit affinity from Java threads. When an execution context does not inherit its creator's affinity set, its initial affinity set defaults according to the rules specified: The default used when a heap-mode SO does not inherit its creator's affinity set, and for all unbound heap-mode async event handlers The default used when a no-heap SO does not inherit its creator's affinity set, and for all unbound no-heap async event handlers. The default used for Java threads created by SOs. This class also controls the default affinity used when a processing group is created using a constructor that does not assign a processing group. When the affinity set of a processing group is permitted to default, it defaults to the set of all available processors. (Which permits each member of the processing group to use the affinity set it would use if it were in no processing group.)
Modifier and Type | Method and Description |
---|---|
static Affinity |
generate(BitSet set)
Create an affinity set based on the given bitset of processors.
|
static Affinity |
get(BoundAsyncEventHandler baeh)
return the affinity set that was set for a given async event
handler.
|
static Affinity |
get(ProcessingGroupParameters pgp)
Return the affinity set that was set for a given processing
group.
|
static Affinity |
get(Thread thread)
Return the affinity set that was set for a given 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 int |
getCurrentProcessor()
Return the id of the processor the current thread is running on.
|
static Affinity |
getHeapSoDefaultAffinity()
Return the default CPU affinity set for schedulable objects that
may access heap memory.
|
static Affinity |
getJavaThreadDefaultAffinity()
Return the default CPU affinity set for non-RTSJ normal Java
threads.
|
static Affinity |
getNoHeapSoDefaultAffinity()
Return the default CPU affinity set for schedulable objects that
run in no-heap mode.
|
static Affinity |
getPGroupDefaultAffinity()
Return the default CPU affinity set for schedulable objects for
which the intersection of their CPU affinity and the affinity set
for their ProcessingGroupParameters is empty.
|
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 |
getPredefinedAffinityCount()
Determine the number or predefined affinity sets.
|
BitSet |
getProcessors()
Return a newly allocated BitSet containing the CPU ids for the
CPUs in this affinity set.
|
BitSet |
getProcessors(BitSet dest)
Return a bitset containing the CPU ids for the CPUS in this
affinity set.
|
boolean |
isProcessorInSet(int processorNumber)
Check if a given processor is part of this affinity set
|
static boolean |
isSetAffinitySupported()
Check whether affinity setting (via methods
setProcessorAffinity(set, ...) is supported by this VM.
|
static void |
set(Affinity set,
BoundAsyncEventHandler baeh)
Set the CPU affinity of a given bound async event handler.
|
static void |
set(Affinity set,
ProcessingGroupParameters pgp)
Set the processors affinity of a given processing group
parameters instance.
|
static void |
set(Affinity set,
Thread thread)
Set the CPU affinity of a given thread.
|
public static Affinity generate(BitSet set)
StaticIllegalArgumentException
- when set
is null
or set
is empty.set
- the set of CPUs that should be part of the set.public static Affinity get(BoundAsyncEventHandler baeh)
NullPointerException
- if baeh == nullbaeh
- the async event handlerpublic static Affinity get(Thread thread)
NullPointerException
- if thread == nullthread
- the threadpublic static Affinity get(ProcessingGroupParameters pgp)
NullPointerException
- if pgp == nullpgp
- the ProcessingGroupParameters of the processing group.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 getCurrentProcessor()
UnsupportedOperationException
- if this operation is not
supported on the current system.public static Affinity getHeapSoDefaultAffinity()
public static Affinity getJavaThreadDefaultAffinity()
public static Affinity getNoHeapSoDefaultAffinity()
public static Affinity getPGroupDefaultAffinity()
public static int getPredefinedAffinityCount()
public static Affinity[] getPredefinedAffinities()
public static Affinity[] getPredefinedAffinities(Affinity[] dest)
StaticIllegalArgumentException
- in case dest!= null but
dest.length() < getPredefinedAffinityCount().dest
- (out!) the array the predefined sets should be copied
to, null to allocate a new array.public static boolean isSetAffinitySupported()
public static void set(Affinity set, BoundAsyncEventHandler baeh) throws ProcessorAffinityException
NullPointerException
- if set == null or baeh == nullProcessorAffinityException
- if !isSetAffinitySupported.set
- the affinity setbaeh
- the bound async event handler whose CPU affinity is
to be setpublic static void set(Affinity set, Thread thread) throws ProcessorAffinityException
NullPointerException
- if set == null or thread == null.ProcessorAffinityException
- if !isSetAffinitySupported.set
- the CPU affinitythread
- the thread whose affinity is to be set.public static void set(Affinity set, ProcessingGroupParameters pgp) throws ProcessorAffinityException
NullPointerException
- if set == null or pgp == null.ProcessorAffinityException
- if !isSetAffinitySupported.set
- the affinity setpgp
- the ProcessingGroupParameterspublic BitSet getProcessors()
public final BitSet getProcessors(BitSet dest)
dest
- (out!) the bitset to store the result in, null to
force allocation of a new result.public final boolean isProcessorInSet(int processorNumber)
aicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2019 aicas GmbH. All Rights Reserved.