1798N/A/*
1798N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
1798N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1798N/A *
1798N/A * This code is free software; you can redistribute it and/or modify it
1798N/A * under the terms of the GNU General Public License version 2 only, as
1798N/A * published by the Free Software Foundation.
1798N/A *
1798N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1798N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1798N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1798N/A * version 2 for more details (a copy is included in the LICENSE file that
1798N/A * accompanied this code).
1798N/A *
1798N/A * You should have received a copy of the GNU General Public License version
1798N/A * 2 along with this work; if not, write to the Free Software Foundation,
1798N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1798N/A *
1798N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1798N/A * or visit www.oracle.com if you need additional information or have any
1798N/A * questions.
1798N/A *
1798N/A */
1798N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "runtime/basicLock.hpp"
1879N/A#include "runtime/synchronizer.hpp"
1798N/A
1798N/Avoid BasicLock::print_on(outputStream* st) const {
1798N/A st->print("monitor");
1798N/A}
1798N/A
1798N/Avoid BasicLock::move_to(oop obj, BasicLock* dest) {
1798N/A // Check to see if we need to inflate the lock. This is only needed
1798N/A // if an object is locked using "this" lightweight monitor. In that
1798N/A // case, the displaced_header() is unlocked, because the
1798N/A // displaced_header() contains the header for the originally unlocked
1798N/A // object. However the object could have already been inflated. But it
1798N/A // does not matter, the inflation will just a no-op. For other cases,
1798N/A // the displaced header will be either 0x0 or 0x3, which are location
1798N/A // independent, therefore the BasicLock is free to move.
1798N/A //
1798N/A // During OSR we may need to relocate a BasicLock (which contains a
1798N/A // displaced word) from a location in an interpreter frame to a
1798N/A // new location in a compiled frame. "this" refers to the source
1798N/A // basiclock in the interpreter frame. "dest" refers to the destination
1798N/A // basiclock in the new compiled frame. We *always* inflate in move_to().
1798N/A // The always-Inflate policy works properly, but in 1.5.0 it can sometimes
1798N/A // cause performance problems in code that makes heavy use of a small # of
1798N/A // uncontended locks. (We'd inflate during OSR, and then sync performance
1798N/A // would subsequently plummet because the thread would be forced thru the slow-path).
1798N/A // This problem has been made largely moot on IA32 by inlining the inflated fast-path
1798N/A // operations in Fast_Lock and Fast_Unlock in i486.ad.
1798N/A //
1798N/A // Note that there is a way to safely swing the object's markword from
1798N/A // one stack location to another. This avoids inflation. Obviously,
1798N/A // we need to ensure that both locations refer to the current thread's stack.
1798N/A // There are some subtle concurrency issues, however, and since the benefit is
1798N/A // is small (given the support for inflated fast-path locking in the fast_lock, etc)
1798N/A // we'll leave that optimization for another time.
1798N/A
1798N/A if (displaced_header()->is_neutral()) {
1798N/A ObjectSynchronizer::inflate_helper(obj);
1798N/A // WARNING: We can not put check here, because the inflation
1798N/A // will not update the displaced header. Once BasicLock is inflated,
1798N/A // no one should ever look at its content.
1798N/A } else {
1798N/A // Typically the displaced header will be 0 (recursive stack lock) or
1798N/A // unused_mark. Naively we'd like to assert that the displaced mark
1798N/A // value is either 0, neutral, or 3. But with the advent of the
1798N/A // store-before-CAS avoidance in fast_lock/compiler_lock_object
1798N/A // we can find any flavor mark in the displaced mark.
1798N/A }
1798N/A// [RGV] The next line appears to do nothing!
1798N/A intptr_t dh = (intptr_t) displaced_header();
1798N/A dest->set_displaced_header(displaced_header());
1798N/A}