duke@435: /* stefank@2314: * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_PRIMS_JVMTIUTIL_HPP stefank@2314: #define SHARE_VM_PRIMS_JVMTIUTIL_HPP stefank@2314: stefank@2314: #include "jvmtifiles/jvmti.h" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "prims/jvmtiEventController.hpp" stefank@2314: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // class JvmtiUtil duke@435: // duke@435: // class for miscellaneous jvmti utility static methods duke@435: // duke@435: duke@435: class JvmtiUtil : AllStatic { duke@435: duke@435: static ResourceArea* _single_threaded_resource_area; duke@435: duke@435: static const char* _error_names[]; duke@435: static const bool _event_threaded[]; duke@435: duke@435: public: duke@435: duke@435: static ResourceArea* single_threaded_resource_area(); duke@435: duke@435: static const char* error_name(int num) { return _error_names[num]; } // To Do: add range checking duke@435: duke@435: static const bool has_event_capability(jvmtiEvent event_type, const jvmtiCapabilities* capabilities_ptr); duke@435: duke@435: static const bool event_threaded(int num) { duke@435: if (num >= JVMTI_MIN_EVENT_TYPE_VAL && num <= JVMTI_MAX_EVENT_TYPE_VAL) { duke@435: return _event_threaded[num]; duke@435: } duke@435: if (num >= EXT_MIN_EVENT_TYPE_VAL && num <= EXT_MAX_EVENT_TYPE_VAL) { duke@435: return false; duke@435: } duke@435: ShouldNotReachHere(); duke@435: return false; duke@435: } duke@435: }; duke@435: duke@435: duke@435: /////////////////////////////////////////////////////////////// duke@435: // duke@435: // class SafeResourceMark duke@435: // duke@435: // ResourceMarks that work before threads exist duke@435: // duke@435: duke@435: class SafeResourceMark : public ResourceMark { duke@435: duke@435: ResourceArea* safe_resource_area() { duke@435: Thread* thread; duke@435: duke@435: if (Threads::number_of_threads() == 0) { duke@435: return JvmtiUtil::single_threaded_resource_area(); duke@435: } duke@435: thread = ThreadLocalStorage::thread(); duke@435: if (thread == NULL) { duke@435: return JvmtiUtil::single_threaded_resource_area(); duke@435: } duke@435: return thread->resource_area(); duke@435: } duke@435: duke@435: public: duke@435: duke@435: SafeResourceMark() : ResourceMark(safe_resource_area()) {} duke@435: duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_PRIMS_JVMTIUTIL_HPP