comparison agent/src/share/classes/sun/jvm/hotspot/runtime/NativeSignatureIterator.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 package sun.jvm.hotspot.runtime;
26
27 import sun.jvm.hotspot.oops.*;
28
29 /** Specialized SignatureIterator: Used for native call purposes */
30
31 public abstract class NativeSignatureIterator extends SignatureIterator {
32 private Method method;
33 // [RGV] We need seperate JNI and Java offset values because in 64 bit mode, the argument offsets
34 // are not in sync with the Java stack. For example a long takes up 1 "C" stack entry
35 // but 2 Java stack entries.
36 private int offset; // The java stack offset
37 private int prepended; // number of prepended JNI parameters (1 JNIEnv, plus 1 mirror if static)
38 private int jni_offset; // the current parameter offset, starting with 0
39
40 public void doBool () { passInt(); jni_offset++; offset++; }
41 public void doChar () { passInt(); jni_offset++; offset++; }
42 public void doFloat () {
43 if (VM.getVM().isLP64()) {
44 passFloat();
45 } else {
46 passInt();
47 }
48 jni_offset++; offset++;
49 }
50
51 public void doDouble() {
52 if (VM.getVM().isLP64()) {
53 passDouble(); jni_offset++; offset += 2;
54 } else {
55 passDouble(); jni_offset += 2; offset += 2;
56 }
57 }
58
59 public void doByte () { passInt(); jni_offset++; offset++; }
60 public void doShort () { passInt(); jni_offset++; offset++; }
61 public void doInt () { passInt(); jni_offset++; offset++; }
62
63 public void doLong () {
64 if (VM.getVM().isLP64()) {
65 passLong(); jni_offset++; offset += 2;
66 } else {
67 passLong(); jni_offset += 2; offset += 2;
68 }
69 }
70
71 public void doVoid () { throw new RuntimeException("should not reach here"); }
72 public void doObject(int begin, int end) { passObject(); jni_offset++; offset++; }
73 public void doArray (int begin, int end) { passObject(); jni_offset++; offset++; }
74
75 public Method method() { return method; }
76 public int offset() { return offset; }
77 public int jniOffset() { return jni_offset + prepended; }
78 public boolean isStatic() { return method.isStatic(); }
79
80 public abstract void passInt();
81 public abstract void passLong();
82 public abstract void passObject();
83 public abstract void passFloat();
84 public abstract void passDouble();
85
86 public NativeSignatureIterator(Method method) {
87 super(method.getSignature());
88 this.method = method;
89 offset = 0;
90 jni_offset = 0;
91
92 int JNIEnv_words = 1;
93 int mirror_words = 1;
94 prepended = !isStatic() ? JNIEnv_words : JNIEnv_words + mirror_words;
95 }
96
97 // iterate() calles the 2 virtual methods according to the following invocation syntax:
98 //
99 // {pass_int | pass_long | pass_object}
100 //
101 // Arguments are handled from left to right (receiver first, if any).
102 // The offset() values refer to the Java stack offsets but are 0 based and increasing.
103 // The java_offset() values count down to 0, and refer to the Java TOS.
104 // The jni_offset() values increase from 1 or 2, and refer to C arguments.
105 public void iterate() {
106 if (!isStatic()) {
107 // handle receiver (not handled by iterate because not in signature)
108 passObject(); jni_offset++; offset++;
109 }
110 iterateParameters();
111 }
112 }