5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 // This class is used internally by nmethods, to cache 26 // exception/pc/handler information. 27 28 class ExceptionCache : public CHeapObj { 29 friend class VMStructs; 30 private: 31 static address _unwind_handler; 32 enum { cache_size = 16 }; 33 klassOop _exception_type; 34 address _pc[cache_size]; 35 address _handler[cache_size]; 36 int _count; 37 ExceptionCache* _next; 38 39 address pc_at(int index) { assert(index >= 0 && index < count(),""); return _pc[index]; } 40 void set_pc_at(int index, address a) { assert(index >= 0 && index < cache_size,""); _pc[index] = a; } 41 address handler_at(int index) { assert(index >= 0 && index < count(),""); return _handler[index]; } 42 void set_handler_at(int index, address a) { assert(index >= 0 && index < cache_size,""); _handler[index] = a; } 43 int count() { return _count; } 44 void increment_count() { _count++; } 687 // Locks an nmethod so its code will not get removed, even if it is a zombie/not_entrant method 688 class nmethodLocker : public StackObj { 689 nmethod* _nm; 690 691 static void lock_nmethod(nmethod* nm); // note: nm can be NULL 692 static void unlock_nmethod(nmethod* nm); // (ditto) 693 694 public: 695 nmethodLocker(address pc); // derive nm from pc 696 nmethodLocker(nmethod *nm) { _nm = nm; lock_nmethod(_nm); } 697 nmethodLocker() { _nm = NULL; } 698 ~nmethodLocker() { unlock_nmethod(_nm); } 699 700 nmethod* code() { return _nm; } 701 void set_code(nmethod* new_nm) { 702 unlock_nmethod(_nm); // note: This works even if _nm==new_nm. 703 _nm = new_nm; 704 lock_nmethod(_nm); 705 } 706 }; | 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_CODE_NMETHOD_HPP 26 #define SHARE_VM_CODE_NMETHOD_HPP 27 28 #include "code/codeBlob.hpp" 29 #include "code/pcDesc.hpp" 30 31 // This class is used internally by nmethods, to cache 32 // exception/pc/handler information. 33 34 class ExceptionCache : public CHeapObj { 35 friend class VMStructs; 36 private: 37 static address _unwind_handler; 38 enum { cache_size = 16 }; 39 klassOop _exception_type; 40 address _pc[cache_size]; 41 address _handler[cache_size]; 42 int _count; 43 ExceptionCache* _next; 44 45 address pc_at(int index) { assert(index >= 0 && index < count(),""); return _pc[index]; } 46 void set_pc_at(int index, address a) { assert(index >= 0 && index < cache_size,""); _pc[index] = a; } 47 address handler_at(int index) { assert(index >= 0 && index < count(),""); return _handler[index]; } 48 void set_handler_at(int index, address a) { assert(index >= 0 && index < cache_size,""); _handler[index] = a; } 49 int count() { return _count; } 50 void increment_count() { _count++; } 693 // Locks an nmethod so its code will not get removed, even if it is a zombie/not_entrant method 694 class nmethodLocker : public StackObj { 695 nmethod* _nm; 696 697 static void lock_nmethod(nmethod* nm); // note: nm can be NULL 698 static void unlock_nmethod(nmethod* nm); // (ditto) 699 700 public: 701 nmethodLocker(address pc); // derive nm from pc 702 nmethodLocker(nmethod *nm) { _nm = nm; lock_nmethod(_nm); } 703 nmethodLocker() { _nm = NULL; } 704 ~nmethodLocker() { unlock_nmethod(_nm); } 705 706 nmethod* code() { return _nm; } 707 void set_code(nmethod* new_nm) { 708 unlock_nmethod(_nm); // note: This works even if _nm==new_nm. 709 _nm = new_nm; 710 lock_nmethod(_nm); 711 } 712 }; 713 714 #endif // SHARE_VM_CODE_NMETHOD_HPP |