Path: blob/master/src/hotspot/share/interpreter/invocationCounter.cpp
40949 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "compiler/compiler_globals.hpp"26#include "interpreter/invocationCounter.hpp"2728void InvocationCounter::init() {29_counter = 0; // reset all the bits, including the sticky carry30}3132void InvocationCounter::set(uint count, uint flag) {33_counter = (count << number_of_noncount_bits) | (flag & carry_mask);34}3536void InvocationCounter::set(uint count) {37uint carry = (_counter & carry_mask); // the carry bit is sticky38_counter = (count << number_of_noncount_bits) | carry;39}4041void InvocationCounter::update(uint new_count) {42// Don't make the method look like it's never been executed43uint counter = raw_counter();44uint c = extract_count(counter);45uint f = extract_carry(counter);46// prevent from going to zero, to distinguish from never-executed methods47if (c > 0 && new_count == 0) new_count = 1;48set(new_count, f);49}5051void InvocationCounter::set_carry_on_overflow() {52if (!carry() && count() > InvocationCounter::count_limit / 2) {53set_carry();54}55}5657void InvocationCounter::reset() {58update(0);59}6061void InvocationCounter::decay() {62update(count() >> 1);63}6465void InvocationCounter::print() {66uint counter = raw_counter();67tty->print_cr("invocation count: up = %d, limit = %d, carry = %s",68extract_count(counter), limit(),69extract_carry(counter) ? "true" : "false");70}717273