[Android JNI] JNI Types and Data Structures
2013-11-22 15:04
399 查看
Primitive Types
Table 3-1 describes Java primitive types and their machine-dependent native equivalents.Java Type | Native Type | Description |
---|---|---|
boolean | jboolean | unsigned 8 bits |
byte | jbyte | signed 8 bits |
char | jchar | unsigned 16 bits |
short | jshort | signed 16 bits |
int | jint | signed 32 bits |
long | jlong | signed 64 bits |
float | jfloat | 32 bits |
double | jdouble | 64 bits |
void | void | N/A |
#define JNI_FALSE 0 #define JNI_TRUE 1
The
jsizeinteger type is used to describe cardinal indices and sizes:
typedef jint jsize;
Reference Types
The JNI includes a number of reference types that correspond to different kinds of Java objects. JNI reference types are organized in the hierarchy shown in Figure 3-1.Figure 3-1 Reference Type Hierarchy
In C, all other JNI reference types are defined to be the same as jobject. For example:
typedef jobject jclass;
In C++, JNI introduces a set of dummy classes to enforce the subtyping relationship. For example:
class _jobject {}; class _jclass : public _jobject {}; ... typedef _jobject *jobject; typedef _jclass *jclass;
Field and Method IDs
Method and field IDs are regular C pointer types:struct _jfieldID; /* opaque structure */ typedef struct _jfieldID *jfieldID; /* field IDs */ struct _jmethodID; /* opaque structure */ typedef struct _jmethodID *jmethodID; /* method IDs */
The Value Type
The jvalueunion type is used as the element type in argument arrays. It is declared as follows:
typedef union jvalue { jboolean z; jbyte b; jchar c; jshort s; jint i; jlong j; jfloat f; jdouble d; jobject l; } jvalue;
Type Signatures
The JNI uses the Java VM’s representation of type signatures. Table 3-2 shows these type signatures.Type Signature | Java Type |
---|---|
Z | boolean |
B | byte |
C | char |
S | short |
I | int |
J | long |
F | float |
D | double |
L fully-qualified-class ; | fully-qualified-class |
[ type | type[] |
( arg-types ) ret-type | method type |
long f (int n, String s, int[] arr);
has the following type signature:
(ILjava/lang/String;[I)J
Modified UTF-8 Strings
The JNI uses modified UTF-8 strings to represent various string types. Modified UTF-8 strings are the same as those used by the Java VM. Modified UTF-8 strings are encoded so that character sequences that contain only non-null ASCII characters can be representedusing only one byte per character, but all Unicode characters can be represented.
All characters in the range \u0001 to \u007F are represented by a single byte, as follows:
0 | bits 6-0 |
The null character (
'\u0000') and characters in the range
'\u0080'to
'\u07FF'are represented by a pair of bytes x and y:
x:
1 | 1 | 0 | bits 10-6 |
1 | 0 | bits 5-0 |
0x1f) <<
6) + (y &
0x3f).
Characters in the range
'\u0800'to
'\uFFFF'are represented by 3 bytes x, y, and z:
x:
1 | 1 | 1 | 0 | bits 15-12 |
1 | 0 | bits 11-6 |
1 | 0 | bits 5-0 |
0xf) <<
12) + ((y &
0x3f) <<
6) + (z &
0x3f) is represented by the bytes.
Characters with code points above U+FFFF (so-called supplementary characters) are represented by separately encoding the two surrogate code units of their UTF-16 representation. Each of the surrogate
code units is represented by three bytes. This means, supplementary characters are represented by six bytes, u, v, w, x, y, and z:
u:
1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |
1 | 0 | 1 | 0 | (bits 20-16) - 1 |
1 | 0 | bits 15-10 |
1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |
1 | 0 | 1 | 1 | bits 9-6 |
1 | 0 | bits 5-0 |
The bytes of multibyte characters are stored in the
classfile in big-endian (high byte first) order.
There are two differences between this format and the standard UTF-8 format. First, the null character
(char)0is encoded using the two-byte format rather than the one-byte format. This means
that modified UTF-8 strings never have embedded nulls. Second, only the one-byte, two-byte, and three-byte formats of standard UTF-8 are used. The Java VM does not recognize the four-byte format of standard UTF-8; it uses its own two-times-three-byte format
instead.
For more information regarding the standard UTF-8 format, see section 3.9 Unicode Encoding Forms of The Unicode Standard, Version 4.0.
相关文章推荐
- JNI Types and Data Structures----JAVA和C语言 c++之间转换的对照表
- JNI Types and Data Structures
- JNI Types and Data Structures
- Data structures and types
- java-jni-03-JNI Types and Data Structure
- Data Types and Data Structures (数据类型和数据结构)
- android 打开各种文件(setDataAndType)
- using iscroll.js and iscroll jquery plugin in android webview to scroll div and ajax load data.
- [Immutable.js] Converting Immutable.js Structures to Javascript and other Immutable Types
- Data structures for game programming learning notes (六)——stack and queue
- Lengths of Primitive Java and C++ Data Types on Linux and Windows 32-bit/64-bit (Linux和Windows上Java和C++基本数据类型的长度对比32位/64位)
- •data structures using c: 3.3: expanding and contracting lists-(2013/11/20)
- (转)SQL Server Data Types and Their .NET Framework Equivalents
- android 打开各种文件(setDataAndType)
- Android中Intent的setData,setType和setDataAndType的区别
- More on Variables and Data Types(Chapter 10 of Programming in Objective-C 2.0)
- android 打开各种文件(setDataAndType)
- Android中Intent的setData,setType和setDataAndType的用法
- Android Intent通过setDataAndType(uri, "type")打开文件方式
- XSD Date and Time Data Types