|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.realtime.Affinity
public class Affinity
Affinity provides APIs that permit access to the set of Processors a Thread or BoundAsyncEventHandler is permitted to run on. It also provides APIs to be informed of changes in the number of CPUs available for the Java VM.
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.)
Method Summary | |
---|---|
static Affinity |
generate(BitSet bitSet)
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Affinity generate(BitSet bitSet)
bitSet
- the set of CPUs that should be part of the set.
NullPointerException
- if bitSet == null;
IllegalArgumentException
- if bitSet does not have
cardinality one and bitSet is not equal to the processor set of
any Affinity returned by getAvailableProcessors().public static Affinity get(BoundAsyncEventHandler baeh)
baeh
- the async event handler
NullPointerException
- if baeh == nullpublic static Affinity get(Thread thread)
thread
- the thread
NullPointerException
- if thread == nullpublic static Affinity get(ProcessingGroupParameters pgp)
pgp
- the ProcessingGroupParameters of the processing group.
NullPointerException
- if pgp == nullpublic 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)
dest
- (out!) the array the predefined sets should be copied
to, null to allocate a new array.
IllegalArgumentException
- in case dest!= null but
dest.length() < getPredefinedAffinityCount().public static boolean isSetAffinitySupported()
public static void set(Affinity set, BoundAsyncEventHandler baeh) throws ProcessorAffinityException
set
- the affinity setbaeh
- the bound async event handler whose CPU affinity is
to be set
NullPointerException
- if set == null or baeh == null
ProcessorAffinityException
- if !isSetAffinitySupported.public static void set(Affinity set, Thread thread) throws ProcessorAffinityException
set
- the CPU affinitythread
- the thread whose affinity is to be set.
NullPointerException
- if set == null or thread == null.
ProcessorAffinityException
- if !isSetAffinitySupported.public static void set(Affinity set, ProcessingGroupParameters pgp) throws ProcessorAffinityException
set
- the affinity setpgp
- the ProcessingGroupParameters
NullPointerException
- if set == null or pgp == null.
ProcessorAffinityException
- if !isSetAffinitySupported.public 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)
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |