twisti@2047: /* stefank@2314: * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. twisti@2047: * Copyright 2009 Red Hat, Inc. twisti@2047: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. twisti@2047: * twisti@2047: * This code is free software; you can redistribute it and/or modify it twisti@2047: * under the terms of the GNU General Public License version 2 only, as twisti@2047: * published by the Free Software Foundation. twisti@2047: * twisti@2047: * This code is distributed in the hope that it will be useful, but WITHOUT twisti@2047: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or twisti@2047: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License twisti@2047: * version 2 for more details (a copy is included in the LICENSE file that twisti@2047: * accompanied this code). twisti@2047: * twisti@2047: * You should have received a copy of the GNU General Public License version twisti@2047: * 2 along with this work; if not, write to the Free Software Foundation, twisti@2047: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. twisti@2047: * twisti@2047: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA twisti@2047: * or visit www.oracle.com if you need additional information or have any twisti@2047: * questions. twisti@2047: * twisti@2047: */ twisti@2047: stefank@2314: #ifndef SHARE_VM_SHARK_SHARKCODEBUFFER_HPP stefank@2314: #define SHARE_VM_SHARK_SHARKCODEBUFFER_HPP stefank@2314: stefank@2314: #include "asm/codeBuffer.hpp" stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "shark/llvmHeaders.hpp" stefank@2314: twisti@2047: class SharkCodeBuffer : public StackObj { twisti@2047: public: twisti@2047: SharkCodeBuffer(MacroAssembler* masm) twisti@2047: : _masm(masm), _base_pc(NULL) {} twisti@2047: twisti@2047: private: twisti@2047: MacroAssembler* _masm; twisti@2047: llvm::Value* _base_pc; twisti@2047: twisti@2047: private: twisti@2047: MacroAssembler* masm() const { twisti@2047: return _masm; twisti@2047: } twisti@2047: twisti@2047: public: twisti@2047: llvm::Value* base_pc() const { twisti@2047: return _base_pc; twisti@2047: } twisti@2047: void set_base_pc(llvm::Value* base_pc) { twisti@2047: assert(_base_pc == NULL, "only do this once"); twisti@2047: _base_pc = base_pc; twisti@2047: } twisti@2047: twisti@2047: // Allocate some space in the buffer and return its address. twisti@2047: // This buffer will have been relocated by the time the method twisti@2047: // is installed, so you can't inline the result in code. twisti@2047: public: twisti@2047: void* malloc(size_t size) const { twisti@2047: masm()->align(BytesPerWord); twisti@2047: void *result = masm()->pc(); twisti@2047: masm()->advance(size); twisti@2047: return result; twisti@2047: } twisti@2047: twisti@2047: // Create a unique offset in the buffer. twisti@2047: public: twisti@2047: int create_unique_offset() const { twisti@2047: int offset = masm()->offset(); twisti@2047: masm()->advance(1); twisti@2047: return offset; twisti@2047: } twisti@2047: twisti@2047: // Inline an oop into the buffer and return its offset. twisti@2047: public: twisti@2047: int inline_oop(jobject object) const { twisti@2047: masm()->align(BytesPerWord); twisti@2047: int offset = masm()->offset(); twisti@2047: masm()->store_oop(object); twisti@2047: return offset; twisti@2047: } twisti@2047: twisti@4314: int inline_Metadata(Metadata* metadata) const { twisti@4314: masm()->align(BytesPerWord); twisti@4314: int offset = masm()->offset(); twisti@4314: masm()->store_Metadata(metadata); twisti@4314: return offset; twisti@4314: } twisti@4314: twisti@2047: // Inline a block of non-oop data into the buffer and return its offset. twisti@2047: public: twisti@2047: int inline_data(void *src, size_t size) const { twisti@2047: masm()->align(BytesPerWord); twisti@2047: int offset = masm()->offset(); twisti@2047: void *dst = masm()->pc(); twisti@2047: masm()->advance(size); twisti@2047: memcpy(dst, src, size); twisti@2047: return offset; twisti@2047: } twisti@2047: }; stefank@2314: stefank@2314: #endif // SHARE_VM_SHARK_SHARKCODEBUFFER_HPP