methodHandles_x86.hpp revision 3101
6329N/A * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. 6329N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6329N/A * This code is free software; you can redistribute it and/or modify it 6329N/A * under the terms of the GNU General Public License version 2 only, as 6329N/A * published by the Free Software Foundation. 6329N/A * This code is distributed in the hope that it will be useful, but WITHOUT 6329N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6329N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6329N/A * version 2 for more details (a copy is included in the LICENSE file that 6329N/A * You should have received a copy of the GNU General Public License version 6329N/A * 2 along with this work; if not, write to the Free Software Foundation, 6329N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6329N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6329N/A// Platform-specific definitions for method handles. 6329N/A// These definitions are inlined into class MethodHandles. 6329N/Aenum /* platform_dependent_constants */ {
// The stack just after the recursive call from a ricochet frame // looks something like this. Offsets are marked in words, not bytes. // rsi (r13 on LP64) is part of the interpreter calling sequence // which tells the callee where is my real rsp (for frame walking). // (...lower memory addresses) // rsp: [ return pc ] always the global RicochetBlob::bounce_addr // rsp+1: [ recursive arg N ] // rsp+2: [ recursive arg N-1 ] // rsp+N: [ recursive arg 1 ] // rsp+N+1: [ recursive method handle ] // rbp-6: [ cleanup continuation pc ] <-- (struct RicochetFrame) // rbp-5: [ saved target MH ] the MH we will call on the saved args // rbp-4: [ saved args layout oop ] an int[] array which describes argument layout // rbp-3: [ saved args pointer ] address of transformed adapter arg M (slot 0) // rbp-2: [ conversion ] information about how the return value is used // rbp-1: [ exact sender sp ] exact TOS (rsi/r13) of original sender frame // rbp+0: [ saved sender fp ] (for original sender of AMH) // rbp+1: [ saved sender pc ] (back to original sender of AMH) // rbp+2: [ transformed adapter arg M ] <-- (extended TOS of original sender) // rbp+3: [ transformed adapter arg M-1] // rbp+M+1: [ transformed adapter arg 1 ] // rbp+M+2: [ padding ] <-- (rbp + saved args base offset) // ... [ optional padding] // (higher memory addresses...) // The arguments originally passed by the original sender // are lost, and arbitrary amounts of stack motion might have // happened due to argument transformation. // (This is done by C2I/I2C adapters and non-direct method handles.) // This is why there is an unpredictable amount of memory between // the extended and exact TOS of the sender. // The ricochet adapter itself will also (in general) perform // transformations before the recursive call. // The transformed and saved arguments, immediately above the saved // return PC, are a well-formed method handle invocation ready to execute. // When the GC needs to walk the stack, these arguments are described // via the saved arg types oop, an int[] array with a private format. // This array is derived from the type of the transformed adapter // method handle, which also sits at the base of the saved argument // bundle. Since the GC may not be able to fish out the int[] // array, so it is pushed explicitly on the stack. This may be // an unnecessary expense. // The following register conventions are significant at this point: // rsp the thread stack, as always; preserved by caller // rsi/r13 exact TOS of recursive frame (contents of [rbp-2]) // rcx recursive method handle (contents of [rsp+N+1]) // rbp preserved by caller (not used by caller) // Unless otherwise specified, all registers can be blown by the call. // If this frame must be walked, the transformed adapter arguments // will be found with the help of the saved arguments descriptor. // Therefore, the descriptor must match the referenced arguments. // The arguments must be followed by at least one word of padding, // which will be necessary to complete the final method handle call. // That word is not treated as holding an oop. Neither is the word // The word pointed to by the return argument pointer is not // treated as an oop, even if points to a saved argument. // This allows the saved argument list to have a "hole" in it // to receive an oop from the recursive call. // (The hole might temporarily contain RETURN_VALUE_PLACEHOLDER.) // When the recursive callee returns, RicochetBlob::bounce_addr will // immediately jump to the continuation stored in the RF. // This continuation will merge the recursive return value // into the saved argument list. At that point, the original // rsi, rbp, and rsp will be reloaded, the ricochet frame will // disappear, and the final target of the adapter method handle // will be invoked on the transformed argument list. // The extended sender SP is above the current RicochetFrame. // This value is not used for much, but it apparently must be nonzero. // The magic number is supposed to help find ricochet frames within the bytes of stack dumps. // The RicochetFrame is found by subtracting a constant offset from rbp. // Additional helper methods for MethodHandles code generation: // Similar to InterpreterMacroAssembler::jump_from_interpreted. // Takes care of special dispatch from single stepping too. // Should be in sharedRuntime, not here.