Path: blob/master/src/hotspot/share/prims/foreign_globals.inline.hpp
41144 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#ifndef SHARE_PRIMS_FOREIGN_GLOBALS_INLINE_HPP24#define SHARE_PRIMS_FOREIGN_GLOBALS_INLINE_HPP2526#include "prims/foreign_globals.hpp"2728#include "oops/oopsHierarchy.hpp"29#include "oops/objArrayOop.hpp"3031template<typename T>32static bool check_type(oop theOop) {33static_assert(sizeof(T) == 0, "No check_type specialization found for this type");34return false;35}36template<>37inline bool check_type<objArrayOop>(oop theOop) { return theOop->is_objArray(); }38template<>39inline bool check_type<typeArrayOop>(oop theOop) { return theOop->is_typeArray(); }4041template<typename R>42R ForeignGlobals::cast(oop theOop) {43assert(check_type<R>(theOop), "Invalid cast");44return (R) theOop;45}4647template<typename T, typename Func>48void ForeignGlobals::loadArray(objArrayOop jarray, int type_index, GrowableArray<T>& array, Func converter) const {49objArrayOop subarray = cast<objArrayOop>(jarray->obj_at(type_index));50int subarray_length = subarray->length();51for (int i = 0; i < subarray_length; i++) {52oop storage = subarray->obj_at(i);53jint index = storage->int_field(VMS.index_offset);54array.push(converter(index));55}56}5758#endif // SHARE_PRIMS_FOREIGN_GLOBALS_INLINE_HPP596061