Path: blob/master/runtime/compiler/env/J9VMAccessCriticalSection.hpp
6000 views
/*******************************************************************************1* Copyright (c) 2000, 2016 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#ifndef J9_VMACCESSCRITICALSECTION_INCL23#define J9_VMACCESSCRITICALSECTION_INCL2425/*26* The following #define and typedef must appear before any #includes in this file27*/28#ifndef J9_VMACCESSCRITICALSECTION_CONNECTOR29#define J9_VMACCESSCRITICALSECTION_CONNECTOR30namespace J9 { class VMAccessCriticalSection; }31namespace J9 { typedef J9::VMAccessCriticalSection VMAccessCriticalSectionConnector; }32#endif3334#include "env/OMRVMAccessCriticalSection.hpp"35#include "env/CompilerEnv.hpp"36#include "infra/Annotations.hpp"37#include "env/jittypes.h"38#include "env/VMJ9.h"39#include "j9.h"4041namespace TR { class Compilation; }4243namespace J944{4546class OMR_EXTENSIBLE VMAccessCriticalSection : public OMR::VMAccessCriticalSectionConnector47{48public:4950VMAccessCriticalSection(51TR_J9VMBase *fej9,52VMAccessAcquireProtocol protocol,53TR::Compilation *comp) :54OMR::VMAccessCriticalSectionConnector(protocol, comp),55_fej9(fej9)56{57_initializedBySubClass = true;58switch (protocol)59{60case acquireVMAccessIfNeeded:61_acquiredVMAccess = TR::Compiler->vm.acquireVMAccessIfNeeded(fej9);62_hasVMAccess = true;63break;6465case tryToAcquireVMAccess:66_hasVMAccess = TR::Compiler->vm.tryToAcquireAccess(comp, &_acquiredVMAccess);67break;68}69}707172VMAccessCriticalSection(73TR::Compilation *comp,74VMAccessAcquireProtocol protocol) :75OMR::VMAccessCriticalSectionConnector(protocol, comp),76_fej9(NULL)77{78_initializedBySubClass = true;79switch (protocol)80{81case acquireVMAccessIfNeeded:82_acquiredVMAccess = TR::Compiler->vm.acquireVMAccessIfNeeded(comp->fej9());83_hasVMAccess = true;84break;8586case tryToAcquireVMAccess:87_hasVMAccess = TR::Compiler->vm.tryToAcquireAccess(comp, &_acquiredVMAccess);88break;89}90}9192~VMAccessCriticalSection()93{94if (!_vmAccessReleased)95{96if (_comp)97{98switch (_protocol)99{100case acquireVMAccessIfNeeded:101TR::Compiler->vm.releaseVMAccessIfNeeded(_comp, _acquiredVMAccess);102break;103104case tryToAcquireVMAccess:105if (_hasVMAccess && _acquiredVMAccess)106{107TR::Compiler->vm.releaseAccess(_comp);108}109break;110}111}112else if (_fej9)113{114switch (_protocol)115{116case acquireVMAccessIfNeeded:117TR::Compiler->vm.releaseVMAccessIfNeeded(_fej9, _acquiredVMAccess);118break;119120case tryToAcquireVMAccess:121if (_hasVMAccess && _acquiredVMAccess)122{123TR::Compiler->vm.releaseAccess(_fej9);124}125break;126}127}128129_vmAccessReleased = true;130}131}132133protected:134135TR_J9VMBase *_fej9;136};137138}139140#endif141142143