0

Where can I find the soruce code/implementation for the availableProcessors() method in the java.lang.Runtime class.

Abhilash
  • 377
  • 1
  • 3
  • 13

1 Answers1

3

Since it's a bit hard to find but the source code is here: http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/tip/src/share/vm/runtime/os.cpp

Look for os::_processor_count

The value is set in a OS-specific file. Here is the Linux version.

My strategy to find this was: Google for site:http://hg.openjdk.java.net/ jdk7 runtime

Then I opened the first link (http://hg.openjdk.java.net/jdk7/jdk7/hotspot/file/tip/src/share/vm/runtime/synchronizer.cpp) and removed the synchronizer.cpp from the URL. I can now see all the files in the runtime/ folder. Then I went through the file names. os.cpp sounded interesting.

For the link above, I replaced the revision number with tip to make the link always point to the latest version.

Inside of that file, I saw os::_processor_count.

Googling for that gave me a couple of links again. os_linux.cpp looked promising.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820