Thu, 15 Dec 2016 19:48:32 -0500
8147910: Cache initial active_processor_count
Summary: Introduce and initialize active_processor_count variable in VM.
Reviewed-by: dholmes, jprovino
src/share/vm/runtime/os.cpp | file | annotate | diff | comparison | revisions | |
src/share/vm/runtime/os.hpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/runtime/os.cpp Fri Dec 02 11:07:27 2016 +0100 1.2 +++ b/src/share/vm/runtime/os.cpp Thu Dec 15 19:48:32 2016 -0500 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -78,6 +78,7 @@ 1.11 uintptr_t os::_serialize_page_mask = 0; 1.12 long os::_rand_seed = 1; 1.13 int os::_processor_count = 0; 1.14 +int os::_initial_active_processor_count = 0; 1.15 size_t os::_page_sizes[os::page_sizes_max]; 1.16 1.17 #ifndef PRODUCT 1.18 @@ -322,6 +323,7 @@ 1.19 } 1.20 1.21 void os::init_before_ergo() { 1.22 + initialize_initial_active_processor_count(); 1.23 // We need to initialize large page support here because ergonomics takes some 1.24 // decisions depending on large page support and the calculated large page size. 1.25 large_page_init(); 1.26 @@ -835,7 +837,11 @@ 1.27 st->print("CPU:"); 1.28 st->print("total %d", os::processor_count()); 1.29 // It's not safe to query number of active processors after crash 1.30 - // st->print("(active %d)", os::active_processor_count()); 1.31 + // st->print("(active %d)", os::active_processor_count()); but we can 1.32 + // print the initial number of active processors. 1.33 + // We access the raw value here because the assert in the accessor will 1.34 + // fail if the crash occurs before initialization of this value. 1.35 + st->print(" (initial active %d)", _initial_active_processor_count); 1.36 st->print(" %s", VM_Version::cpu_features()); 1.37 st->cr(); 1.38 pd_print_cpu_info(st); 1.39 @@ -1418,6 +1424,11 @@ 1.40 return result; 1.41 } 1.42 1.43 +void os::initialize_initial_active_processor_count() { 1.44 + assert(_initial_active_processor_count == 0, "Initial active processor count already set."); 1.45 + _initial_active_processor_count = active_processor_count(); 1.46 +} 1.47 + 1.48 void os::SuspendedThreadTask::run() { 1.49 assert(Threads_lock->owned_by_self() || (_thread == VMThread::vm_thread()), "must have threads lock to call this"); 1.50 internal_do_task();
2.1 --- a/src/share/vm/runtime/os.hpp Fri Dec 02 11:07:27 2016 +0100 2.2 +++ b/src/share/vm/runtime/os.hpp Thu Dec 15 19:48:32 2016 -0500 2.3 @@ -151,6 +151,7 @@ 2.4 2.5 static size_t page_size_for_region(size_t region_size, size_t min_pages, bool must_be_aligned); 2.6 2.7 + static void initialize_initial_active_processor_count(); 2.8 public: 2.9 static void init(void); // Called before command line parsing 2.10 static void init_before_ergo(void); // Called after command line parsing 2.11 @@ -238,6 +239,13 @@ 2.12 // Note that on some OSes this can change dynamically. 2.13 static int active_processor_count(); 2.14 2.15 + // At startup the number of active CPUs this process is allowed to run on. 2.16 + // This value does not change dynamically. May be different from active_processor_count(). 2.17 + static int initial_active_processor_count() { 2.18 + assert(_initial_active_processor_count > 0, "Initial active processor count not set yet."); 2.19 + return _initial_active_processor_count; 2.20 + } 2.21 + 2.22 // Bind processes to processors. 2.23 // This is a two step procedure: 2.24 // first you generate a distribution of processes to processors, 2.25 @@ -975,8 +983,9 @@ 2.26 2.27 2.28 protected: 2.29 - static long _rand_seed; // seed for random number generator 2.30 - static int _processor_count; // number of processors 2.31 + static long _rand_seed; // seed for random number generator 2.32 + static int _processor_count; // number of processors 2.33 + static int _initial_active_processor_count; // number of active processors during initialization. 2.34 2.35 static char* format_boot_path(const char* format_string, 2.36 const char* home,