# HG changeset patch # User tschatzl # Date 1492496746 -3600 # Node ID 8ba07ad46983953ef1b13187462a48dac5b24c8d # Parent bbd1934c49f740c3a7ceaded63350664b9aec003 8147910: Cache initial active_processor_count Summary: Introduce and initialize active_processor_count variable in VM. Reviewed-by: dholmes, jprovino diff -r bbd1934c49f7 -r 8ba07ad46983 src/share/vm/runtime/os.cpp --- a/src/share/vm/runtime/os.cpp Tue Apr 18 07:03:25 2017 +0100 +++ b/src/share/vm/runtime/os.cpp Tue Apr 18 07:25:46 2017 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -78,6 +78,7 @@ uintptr_t os::_serialize_page_mask = 0; long os::_rand_seed = 1; int os::_processor_count = 0; +int os::_initial_active_processor_count = 0; size_t os::_page_sizes[os::page_sizes_max]; #ifndef PRODUCT @@ -314,6 +315,7 @@ } void os::init_before_ergo() { + initialize_initial_active_processor_count(); // We need to initialize large page support here because ergonomics takes some // decisions depending on large page support and the calculated large page size. large_page_init(); @@ -820,7 +822,11 @@ st->print("CPU:"); st->print("total %d", os::processor_count()); // It's not safe to query number of active processors after crash - // st->print("(active %d)", os::active_processor_count()); + // st->print("(active %d)", os::active_processor_count()); but we can + // print the initial number of active processors. + // We access the raw value here because the assert in the accessor will + // fail if the crash occurs before initialization of this value. + st->print(" (initial active %d)", _initial_active_processor_count); st->print(" %s", VM_Version::cpu_features()); st->cr(); pd_print_cpu_info(st); @@ -1410,6 +1416,11 @@ return (int) i; } +void os::initialize_initial_active_processor_count() { + assert(_initial_active_processor_count == 0, "Initial active processor count already set."); + _initial_active_processor_count = active_processor_count(); +} + void os::SuspendedThreadTask::run() { assert(Threads_lock->owned_by_self() || (_thread == VMThread::vm_thread()), "must have threads lock to call this"); internal_do_task(); diff -r bbd1934c49f7 -r 8ba07ad46983 src/share/vm/runtime/os.hpp --- a/src/share/vm/runtime/os.hpp Tue Apr 18 07:03:25 2017 +0100 +++ b/src/share/vm/runtime/os.hpp Tue Apr 18 07:25:46 2017 +0100 @@ -139,6 +139,7 @@ static void pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint); + static void initialize_initial_active_processor_count(); public: static void init(void); // Called before command line parsing static void init_before_ergo(void); // Called after command line parsing @@ -218,6 +219,13 @@ // Note that on some OSes this can change dynamically. static int active_processor_count(); + // At startup the number of active CPUs this process is allowed to run on. + // This value does not change dynamically. May be different from active_processor_count(). + static int initial_active_processor_count() { + assert(_initial_active_processor_count > 0, "Initial active processor count not set yet."); + return _initial_active_processor_count; + } + // Bind processes to processors. // This is a two step procedure: // first you generate a distribution of processes to processors, @@ -935,8 +943,9 @@ protected: - static long _rand_seed; // seed for random number generator - static int _processor_count; // number of processors + static long _rand_seed; // seed for random number generator + static int _processor_count; // number of processors + static int _initial_active_processor_count; // number of active processors during initialization. static char* format_boot_path(const char* format_string, const char* home,