--- /dev/null 2015-06-27 04:11:18.000000000 +0300 +++ new/src/share/vm/prims/unsafe.hpp 2015-06-27 04:11:18.000000000 +0300 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "utilities/globalDefinitions.hpp" + +class Unsafe { +public: + // Note: The VM's obj_field and related accessors use byte-scaled + // ("unscaled") offsets, just as the unsafe methods do. + + // However, the method Unsafe.fieldOffset explicitly declines to + // guarantee this. The field offset values manipulated by the Java user + // through the Unsafe API are opaque cookies that just happen to be byte + // offsets. We represent this state of affairs by passing the cookies + // through conversion functions when going between the VM and the Unsafe API. + // The conversion functions just happen to be no-ops at present. + enum { + final_bits = 1, + offset_bits = BitsPerLong - final_bits, + + final_shift = 0, + offset_shift = final_bits, + + final_mask = right_n_bits(final_bits) + }; + + static jlong field_offset_to_byte_offset(jlong field_offset) { + return (field_offset >> offset_shift); + } + + static jlong field_offset_from_byte_offset(jlong byte_offset, bool is_final = false) { + return (byte_offset << offset_shift) | (is_final ? final_mask : 0); + } + + static jint invocation_key_from_method_slot(jint slot) { + return slot; + } + + static jint invocation_key_to_method_slot(jint key) { + return key; + } +}; +