source: trunk/src/gcc/libjava/include/java-interp.h@ 2

Last change on this file since 2 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.0 KB
Line 
1// java-interp.h - Header file for the bytecode interpreter. -*- c++ -*-
2
3/* Copyright (C) 1999, 2000, 2001 Free Software Foundation
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
10
11#ifndef __JAVA_INTERP_H__
12#define __JAVA_INTERP_H__
13
14#include <jvm.h>
15#include <java-cpool.h>
16
17#ifdef INTERPRETER
18
19#pragma interface
20
21#include <java/lang/Class.h>
22#include <java/lang/ClassLoader.h>
23
24extern "C" {
25#include <ffi.h>
26}
27
28extern inline jboolean
29_Jv_IsInterpretedClass (jclass c)
30{
31 return (c->loader != 0);
32}
33
34struct _Jv_ResolvedMethod;
35
36void _Jv_DefineClass (jclass, jbyteArray, jint, jint);
37
38void _Jv_InitField (jobject, jclass, int);
39void * _Jv_AllocMethodInvocation (jsize size);
40int _Jv_count_arguments (_Jv_Utf8Const *signature,
41 jboolean staticp = true);
42void _Jv_VerifyMethod (_Jv_InterpMethod *method);
43
44/* FIXME: this should really be defined in some more generic place */
45#define ROUND(V, A) (((((unsigned) (V))-1) | ((A)-1))+1)
46
47/* the interpreter is written in C++, primarily because it makes it easy for
48 * the entire thing to be "friend" with class Class. */
49
50class _Jv_InterpClass;
51class _Jv_InterpMethod;
52class _Jv_InterpMethodInvocation;
53
54class _Jv_InterpException
55{
56 int start_pc;
57 int end_pc;
58 int handler_pc;
59 int handler_type;
60
61 friend class _Jv_ClassReader;
62 friend class _Jv_InterpMethod;
63 friend class _Jv_BytecodeVerifier;
64};
65
66// Base class for method representations. Subclasses are interpreted
67// and JNI methods.
68class _Jv_MethodBase
69{
70protected:
71 // The class which defined this method.
72 _Jv_InterpClass *defining_class;
73
74 // The method description.
75 _Jv_Method *self;
76
77 // Size of raw arguments.
78 _Jv_ushort args_raw_size;
79
80public:
81 _Jv_Method *get_method ()
82 {
83 return self;
84 }
85};
86
87class _Jv_InterpMethod : public _Jv_MethodBase
88{
89 _Jv_ushort max_stack;
90 _Jv_ushort max_locals;
91 int code_length;
92
93 _Jv_ushort exc_count;
94
95 unsigned char* bytecode ()
96 {
97 return
98 ((unsigned char*)this)
99 + ROUND((sizeof (_Jv_InterpMethod)
100 + exc_count*sizeof (_Jv_InterpException)), 4);
101 }
102
103 _Jv_InterpException * exceptions ()
104 {
105 return (_Jv_InterpException*) (this+1);
106 }
107
108 static size_t size (int exc_count, int code_length)
109 {
110 return
111 ROUND ((sizeof (_Jv_InterpMethod)
112 + (exc_count * sizeof (_Jv_InterpException))), 4)
113 + code_length;
114 }
115
116 // return the method's invocation pointer (a stub).
117 void *ncode ();
118 void continue1 (_Jv_InterpMethodInvocation *inv);
119
120 static void run_normal (ffi_cif*, void*, ffi_raw*, void*);
121 static void run_synch_object (ffi_cif*, void*, ffi_raw*, void*);
122 static void run_synch_class (ffi_cif*, void*, ffi_raw*, void*);
123
124 inline jobject run (ffi_cif*, void*, ffi_raw*,
125 _Jv_InterpMethodInvocation*);
126
127 bool find_exception (jobject ex,
128 _Jv_InterpMethodInvocation *inv);
129
130 public:
131 static void dump_object(jobject o);
132
133 friend class _Jv_ClassReader;
134 friend class _Jv_InterpMethodInvocation;
135 friend class _Jv_BytecodeVerifier;
136
137 friend void _Jv_PrepareClass(jclass);
138};
139
140class _Jv_InterpMethodInvocation {
141 _Jv_InterpMethod *running;
142 _Jv_word *sp;
143 unsigned char *pc;
144 _Jv_word state[0];
145
146 _Jv_word* stack_base () { return &state[0]; }
147 _Jv_word* local_base () { return &state[running->max_stack]; }
148
149 friend class _Jv_InterpMethod;
150};
151
152class _Jv_InterpClass : public java::lang::Class
153{
154 _Jv_MethodBase **interpreted_methods;
155 _Jv_ushort *field_initializers;
156
157 friend class _Jv_ClassReader;
158 friend class _Jv_InterpMethod;
159 friend void _Jv_PrepareClass(jclass);
160 friend void _Jv_InitField (jobject, jclass, int);
161#ifdef JV_MARKOBJ_DECL