aoqi@0: /* aoqi@0: * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_PRIMS_JNIFASTGETFIELD_HPP aoqi@0: #define SHARE_VM_PRIMS_JNIFASTGETFIELD_HPP aoqi@0: aoqi@0: #include "memory/allocation.hpp" aoqi@0: #include "prims/jvm_misc.hpp" aoqi@0: aoqi@0: // Basic logic of a fast version of jni_GetField: aoqi@0: // aoqi@0: // (See safepoint.hpp for a description of _safepoint_counter) aoqi@0: // aoqi@0: // load _safepoint_counter into old_counter aoqi@0: // IF old_counter is odd THEN aoqi@0: // a safepoint is going on, return jni_GetXXXField aoqi@0: // ELSE aoqi@0: // load the primitive field value into result (speculatively) aoqi@0: // load _safepoint_counter into new_counter aoqi@0: // IF (old_counter == new_counter) THEN aoqi@0: // no safepoint happened during the field access, return result aoqi@0: // ELSE aoqi@0: // a safepoint might have happened in-between, return jni_GetXXXField() aoqi@0: // ENDIF aoqi@0: // ENDIF aoqi@0: // aoqi@0: // LoadLoad membars to maintain the load order may be necessary aoqi@0: // for some platforms. aoqi@0: // aoqi@0: // The fast versions don't check for pending suspension request. aoqi@0: // This is fine since it's totally read-only and doesn't create new race. aoqi@0: // aoqi@0: // There is a hypothetical safepoint counter wraparound. But it's not aoqi@0: // a practical concern. aoqi@0: aoqi@0: class JNI_FastGetField : AllStatic { aoqi@0: private: aoqi@0: enum { LIST_CAPACITY = 40 }; // a conservative number for the number of aoqi@0: // speculative loads on all the platforms aoqi@0: static address speculative_load_pclist []; aoqi@0: static address slowcase_entry_pclist []; aoqi@0: static int count; aoqi@0: aoqi@0: static address generate_fast_get_int_field0(BasicType type); aoqi@0: static address generate_fast_get_float_field0(BasicType type); aoqi@0: aoqi@0: public: aoqi@0: #if defined(_WINDOWS) && !defined(_WIN64) aoqi@0: static GetBooleanField_t jni_fast_GetBooleanField_fp; aoqi@0: static GetByteField_t jni_fast_GetByteField_fp; aoqi@0: static GetCharField_t jni_fast_GetCharField_fp; aoqi@0: static GetShortField_t jni_fast_GetShortField_fp; aoqi@0: static GetIntField_t jni_fast_GetIntField_fp; aoqi@0: static GetLongField_t jni_fast_GetLongField_fp; aoqi@0: static GetFloatField_t jni_fast_GetFloatField_fp; aoqi@0: static GetDoubleField_t jni_fast_GetDoubleField_fp; aoqi@0: #endif aoqi@0: aoqi@0: static address generate_fast_get_boolean_field(); aoqi@0: static address generate_fast_get_byte_field(); aoqi@0: static address generate_fast_get_char_field(); aoqi@0: static address generate_fast_get_short_field(); aoqi@0: static address generate_fast_get_int_field(); aoqi@0: static address generate_fast_get_long_field(); aoqi@0: static address generate_fast_get_float_field(); aoqi@0: static address generate_fast_get_double_field(); aoqi@0: aoqi@0: // If pc is in speculative_load_pclist, return the corresponding aoqi@0: // slow case entry pc. Otherwise, return -1. aoqi@0: // This is used by signal/exception handler to handle such case: aoqi@0: // After an even safepoint counter is loaded and a fast field access aoqi@0: // is about to begin, a GC kicks in and shrinks the heap. Then the aoqi@0: // field access may fault. The signal/exception handler needs to aoqi@0: // return to the slow case. aoqi@0: // aoqi@0: // The GC may decide to temporarily stuff some bad values into handles, aoqi@0: // for example, for debugging purpose, in which case we need the mapping also. aoqi@0: static address find_slowcase_pc(address pc); aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_PRIMS_JNIFASTGETFIELD_HPP