blob: dbdfa68e3a6f82b26815abc21d42c440aa9e65c0 [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
Ian Rogers0571d352011-11-03 19:51:38 -070028 CompiledMethod* Compile(bool is_direct, uint32_t method_idx, const ClassLoader* class_loader,
29 const DexFile& dex_file);
Ian Rogersdf20fe02011-07-20 20:34:16 -070030
Brian Carlstrom16192862011-09-12 17:50:06 -070031 // Stub to perform native method symbol lookup via dlsym
32 // TODO: remove from JniCompiler
33 static ByteArray* CreateJniStub(InstructionSet instruction_set);
34
Ian Rogersb033c752011-07-20 12:22:35 -070035 private:
Ian Rogersdf20fe02011-07-20 20:34:16 -070036 // Copy a single parameter from the managed to the JNI calling convention
37 void CopyParameter(Assembler* jni_asm,
38 ManagedRuntimeCallingConvention* mr_conv,
39 JniCallingConvention* jni_conv,
40 size_t frame_size, size_t out_arg_size);
41
Ian Rogers2c8f6532011-09-02 17:16:34 -070042 void SetNativeParameter(Assembler* jni_asm,
43 JniCallingConvention* jni_conv,
Shih-wei Liao668512a2011-09-01 14:18:34 -070044 ManagedRegister in_reg);
45
Ian Rogerse5de95b2011-09-18 20:31:38 -070046 void ChangeThreadState(Assembler* jni_asm, Thread::State new_state,
47 ManagedRegister scratch, ManagedRegister return_reg,
48 FrameOffset return_save_location,
49 size_t return_size);
50
Ian Rogersbdb03912011-09-14 00:55:44 -070051 // Architecture to generate code for
Ian Rogers2c8f6532011-09-02 17:16:34 -070052 InstructionSet instruction_set_;
53
Ian Rogersb033c752011-07-20 12:22:35 -070054 DISALLOW_COPY_AND_ASSIGN(JniCompiler);
55};
56
57} // namespace art
58
59#endif // ART_SRC_JNI_COMPILER_H_