JNI Types and Data Structures

翻译自https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/types.html

Chapter   3

本章讨论JNI如何将Java类型映射到本地C类型。

Primitive Types

Table 3-1 描述Java基本类型及其与机器相关的本地代码的等价类型。

Table 3-1 Primitive Types and 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 

 jsize整型类型用于描述基数索引和大小:

typedef jint jsize; 

Reference Types

JNI包含一系列的对应于不同种类的Java对象的引用类型。 JNI引用类型按照Figure 3-1.所示的层次结构进行组织。

 

The top of the heirarchy is jobject. Subclasses of jobject are jclass, jstring, jarray and jthrowable. Subclasses of jarray are jobjectArray, jbooleanArray, jbyteArray, jcharArray, jshortArray, jintArray, jlongArray, jfloatArray, jdoubleArray.

Figure 3-1 Reference Type Hierarchy

在C语言中,所有其他JNI引用类型的定义与jobject的定义都相同。 例如:

typedef jobject jclass; 

以下摘自jni.h中,C部分定义:

/*
 * Reference types, in C.
 */
typedef void*           jobject;
typedef jobject         jclass;
typedef jobject         jstring;
typedef jobject         jarray;
typedef jarray          jobjectArray;
typedef jarray          jbooleanArray;
typedef jarray          jbyteArray;
typedef jarray          jcharArray;
typedef jarray          jshortArray;
typedef jarray          jintArray;
typedef jarray          jlongArray;
typedef jarray          jfloatArray;
typedef jarray          jdoubleArray;
typedef jobject         jthrowable;
typedef jobject         jweak;

 

在C ++中,JNI引入了一组伪类来加强子类型关系。 例如:

class _jobject {}; 
class _jclass : public _jobject {}; 
... 
typedef _jobject *jobject; 
typedef _jclass *jclass; 

以下摘自jni.h中,C++部分定义: 

/*
 * Reference types, in C++
 */
class _jobject {};
class _jclass : public _jobject {};
class _jstring : public _jobject {};
class _jarray : public _jobject {};
class _jobjectArray : public _jarray {};
class _jbooleanArray : public _jarray {};
class _jbyteArray : public _jarray {};
class _jcharArray : public _jarray {};
class _jshortArray : public _jarray {};
class _jintArray : public _jarray {};
class _jlongArray : public _jarray {};
class _jfloatArray : public _jarray {};
class _jdoubleArray : public _jarray {};
class _jthrowable : public _jobject {};

typedef _jobject*       jobject;
typedef _jclass*        jclass;
typedef _jstring*       jstring;
typedef _jarray*        jarray;
typedef _jobjectArray*  jobjectArray;
typedef _jbooleanArray* jbooleanArray;
typedef _jbyteArray*    jbyteArray;
typedef _jcharArray*    jcharArray;
typedef _jshortArray*   jshortArray;
typedef _jintArray*     jintArray;
typedef _jlongArray*    jlongArray;
typedef _jfloatArray*   jfloatArray;
typedef _jdoubleArray*  jdoubleArray;
typedef _jthrowable*    jthrowable;
typedef _jobject*       jweak;

 

Field and Method IDs

方法和字段ID是常规的C指针类型:

struct _jfieldID;                       /* opaque structure */
typedef struct _jfieldID* jfieldID;     /* field IDs */

struct _jmethodID;                      /* opaque structure */
typedef struct _jmethodID* jmethodID;   /* method IDs */
 

 

The Value Type

jvalue联合类型被用作参数数组中的元素类型。 声明如下:

typedef union jvalue {
    jboolean    z;
    jbyte       b;
    jchar       c;
    jshort      s;
    jint        i;
    jlong       j;
    jfloat      f;
    jdouble     d;
    jobject     l;
} jvalue;
 

 

Type Signatures

JNI使用Java VM的类型签名表示。 Table 3-2显示了这些类型签名。

Table 3-2 Java VM 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

举例,java方法

long f (int n, String s, int[] arr); 

有以下类型签名:

(ILjava/lang/String;[I)J

 

Modified UTF-8 Strings(改良的UTF-8字符串?)

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 represented using 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:

JNI使用改良的UTF-8字符串来表示各种字符串类型。 改良的UTF-8字符串与Java VM使用的字符串相同。 改良的UTF-8字符串经过编码,对于仅包含非空ASCII字符的字符序列的每个字符都只用一个字节表示,但是可以表示所有Unicode字符。

\ u0001到\ u007F范围内的所有字符都由一个字节表示,如下所示:

0bits 6-0

 

字节中的七个数据位表示所表示字符的值。

空字符('\ u0000')和范围从'\ u0080'到'\ u07FF'的字符由一对字节x和y表示:

x:

110bits 10-6

y:

10bits 5-0

The bytes represent the character with the value ((x & 0x1f) << 6) + (y & 0x3f).

'\ u0800'到'\ uFFFF'范围内的字符由3个字节x,y和z表示:

x:

1110bits 15-12

y:

10bits 11-6

z:

10bits 5-0

The character with the value ((x & 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 + FFFF的字符(所谓的补充字符)可以用两个UTF-16形式的代理代码单元表示。 每个代理代码单元由三个字节表示。 这意味着,补充字符由u,v,w,x,y和z六个字节表示:

u:

11101101

v:

1010(bits 20-16) - 1

w:

10bits 15-10

x:

11101101

y:

1011bits 9-6

z:

10bits 5-0

The character with the value 0x10000+((v&0x0f)<<16)+((w&0x3f)<<10)+(y&0x0f)<<6)+(z&0x3f) is represented by the six bytes.

多字节字符的字节以big-endian(高字节在前)的顺序存储在类文件中。

此格式与标准UTF-8格式有两个区别。 首先,空字符(char)0使用两字节格式而不是一字节格式进行编码。 这意味着修改后的UTF-8字符串永远不会嵌入空值null。 其次,标准UTF-8有一字节,两字节和三字节格式被使用。 Java VM无法识别四字节格式的标准UTF-8。 它使用自己的2乘3字节格式替代。

有关标准UTF-8格式的更多信息,请参见Unicode标准版本4.0的3.9 Unicode编码形式。

数据治理是确保数据准确性、可靠性、安全性、可用性和完整性的体系和框架。它定义了组织内部如何使用、存储、保护和共享数据的规则和流程。数据治理的重要性随着数字化转型的加速而日益凸显,它能够提高决策效率、增强业务竞争力、降低风险,并促进业务创新。有效的数据治理体系可以确保数据在采集、存储、处理、共享和保护等环节的合规性和有效性。 数据质量管理是数据治理中的关键环节,它涉及数据质量评估、数据清洗、标准化和监控。高质量的数据能够提升业务决策的准确性,优化业务流程,并挖掘潜在的商业价值。随着大数据和人工智能技术的发展,数据质量管理在确保数据准确性和可靠性方面的作用愈发重要。企业需要建立完善的数据质量管理和校验机制,并通过数据清洗和标准化提高数据质量。 数据安全与隐私保护是数据治理中的另一个重要领域。随着数据量的快速增长和互联网技术的迅速发展,数据安全与隐私保护面临前所未有的挑战。企业需要加强数据安全与隐私保护的法律法规和技术手段,采用数据加密、脱敏和备份恢复等技术手段,以及加强培训和教育,提高安全意识和技能水平。 数据流程管理与监控是确保数据质量、提高数据利用率、保护数据安全的重要环节。有效的数据流程管理可以确保数据流程的合规性和高效性,而实时监控则有助于及时发现并解决潜在问题。企业需要设计合理的数据流程架构,制定详细的数据管理流程规范,并运用数据审计和可视化技术手段进行监控。 数据资产管理是将数据视为组织的重要资产,通过有效的管理和利用,为组织带来经济价值。数据资产管理涵盖数据的整个生命周期,包括数据的创建、存储、处理、共享、使用和保护。它面临的挑战包括数据量的快速增长、数据类型的多样化和数据更新的迅速性。组织需要建立完善的数据管理体系,提高数据处理和分析能力,以应对这些挑战。同时,数据资产的分类与评估、共享与使用规范也是数据资产管理的重要组成部分,需要制定合理的标准和规范,确保数据共享的安全性和隐私保护,以及建立合理的利益分配和权益保障机制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值