blob: a6d56026ab26634fea6a8aec49461ca9cdbf84bc [file] [log] [blame]
Ian Rogersb033c752011-07-20 12:22:35 -07001// Copyright 2011 Google Inc. All Rights Reserved.
Carl Shapiroad107ab2011-08-14 15:54:24 -07002
Ian Rogersb033c752011-07-20 12:22:35 -07003#ifndef ART_SRC_JNI_COMPILER_H_
4#define ART_SRC_JNI_COMPILER_H_
5
Brian Carlstrom3320cf42011-10-04 14:58:28 -07006#include "compiled_method.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -07007#include "constants.h"
Brian Carlstromf3eb61f2011-07-23 20:22:26 -07008#include "macros.h"
Shih-wei Liao31384c52011-09-06 15:27:45 -07009#include "object.h"
Ian Rogersb033c752011-07-20 12:22:35 -070010
11namespace art {
12
13class Assembler;
Brian Carlstrom3320cf42011-10-04 14:58:28 -070014class Compiler;
Ian Rogers2c8f6532011-09-02 17:16:34 -070015class JniCallingConvention;
16class ManagedRegister;
17class ManagedRuntimeCallingConvention;
Ian Rogersb033c752011-07-20 12:22:35 -070018class Method;
19
20// A JNI compiler generates code that acts as the bridge between managed code
21// and native code.
22// TODO: move the responsibility of managing memory to somewhere else
23class JniCompiler {
24 public:
Brian Carlstrom3320cf42011-10-04 14:58:28 -070025 explicit JniCompiler(InstructionSet instruction_set);
Ian Rogersb033c752011-07-20 12:22:35 -070026 ~JniCompiler();
Ian Rogers2c8f6532011-09-02 17:16:34 -070027
Brian Carlstrom3320cf42011-10-04 14:58:28 -070028 CompiledMethod* Compile(const Method* method);
Ian Rogersdf20fe02011-07-20 20:34:16 -070029
Brian Carlstrom16192862011-09-12 17:50:06 -070030 // Stub to perform native method symbol lookup via dlsym
31 // TODO: remove from JniCompiler
32 static ByteArray* CreateJniStub(InstructionSet instruction_set);
33
Ian Rogersb033c752011-07-20 12:22:35 -070034 private:
Ian Rogersdf20fe02011-07-20 20:34:16 -070035 // Copy a single parameter from the managed to the JNI calling convention
36 void CopyParameter(Assembler* jni_asm,
37 ManagedRuntimeCallingConvention* mr_conv,
38 JniCallingConvention* jni_conv,
39 size_t frame_size, size_t out_arg_size);
40
Ian Rogers2c8f6532011-09-02 17:16:34 -070041 void SetNativeParameter(Assembler* jni_asm,
42 JniCallingConvention* jni_conv,
Shih-wei Liao668512a2011-09-01 14:18:34 -070043 ManagedRegister in_reg);
44
Ian Rogerse5de95b2011-09-18 20:31:38 -070045 void ChangeThreadState(Assembler* jni_asm, Thread::State new_state,
46 ManagedRegister scratch, ManagedRegister return_reg,
47 FrameOffset return_save_location,
48 size_t return_size);
49
Ian Rogersbdb03912011-09-14 00:55:44 -070050 // Architecture to generate code for
Ian Rogers2c8f6532011-09-02 17:16:34 -070051 InstructionSet instruction_set_;
52
Ian Rogersb033c752011-07-20 12:22:35 -070053 DISALLOW_COPY_AND_ASSIGN(JniCompiler);
54};
55
56} // namespace art
57
58#endif // ART_SRC_JNI_COMPILER_H_