JDK-6378421 : Provide a command line option to affinitize java.exe to processors.
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-01-30
  • Updated: 2011-02-16
  • Resolved: 2006-02-14
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
It would be nice to have an option in the java interpreter (java.exe) to define the processor affinity of the executable.


JUSTIFICATION :
In my work, I sometimes detect problems which only happen when running on multi-processor or hyper-threaded applications. Since the problem is in some third-party library which may be solved at any time, nobody took the time to implement the capability to affinitize all the threads to a single processor.
Currently, to test one or another I have to reboot the PC and change the hyper-thread support. It would be much nicer to be able to force the application to use a single processor or run normaly by providing a command line option to java.exe.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Have a command line option to define the processor affinity of java.exe.
ACTUAL -
There is no way to define the processor affinity in the command line.

CUSTOMER SUBMITTED WORKAROUND :
1) Reboot the machine and change to hyper-thread support.
2) Use two different machines.
3) Implement some code to configure it (I'm not a Java programmer so I don't know if this is even possible since we use third-party libraries).

Comments
WORK AROUND Windows TaskManager allows the affinity of a process to be set after it is launched. In addition there are third-party launcher tools that can set the affinity at launch time (google for "windows set affinity". Finally. the Windows resource kit contains the imagecfg.exe utility that can be used to set the affinity mask of an executable file. On Solaris pbind can be used in conjunction with a shell launcher script to bind a process to a single CPU. On some linux distributions affinity for a process can be set through the /proc interface.
14-02-2006

EVALUATION As discussed in 4234402 exactly what "set affinity" should allow/provide becomes more unclear with modern processors. An option to force use of only a single CPU might be possible on most platforms, but a more general facility to restrict usage to a specific number of CPU's is more difficult. Solaris provides pbind to bind a process to a single CPU. It also provides processor sets to group CPU's, but these affect all processes in the system so can't be used to associate just one process with a set of CPU's. Linux added sched_setaffinity in the 2.6 kernel with some distributions backporting to 2.4 kernels. Unfortunately there are two different versions of this API taking different arguments, which makes their use more awkward than it should be. Some systems also support setting the affinity through the /proc interface. Windows provides both utilities and a programmatic interface to set the "affinity mask" but the mask is limited to 32-bits on 32-bit systems, so a system with more than 32 logical processors would have multiple processors per bit-mask. Given the lack of cross-platform consistency in the available API's, and the fact that there ware reasonable workarounds - particularly for Windows - I'm closing this RFE. *** (#1 of 1): [ UNSAVED ] ###@###.###
14-02-2006