CAR 构件技术 及 ELASTOS 操作系统

25
CAR 构构构构 ELASTOS 构构构构构构构构构构构构构构构 2014.8

description

CAR 构件技术 及 ELASTOS 操作系统. 上海科泰华捷科技有限公司 2014.8. 题外话. 谈点理论 , 谈 点技术 理论 来源于 朴素的想法和逻辑推理 理论与 实现 间 的差距. 主要内容. CAR 构件技术 技术要点 主要功能 演进方向. 主要 内容. Elastos 操作系统 系统架构 与 Android 的关系 主要特点 演进方向. CAR 构件技术. 技术要点 主要功能 演进方向. CAR 技术要点. 面向接口编程 C++ 扩展反射. 面向接口编程. 内聚度与耦合度 ( 软件度量 ) 高内聚 低耦合 - PowerPoint PPT Presentation

Transcript of CAR 构件技术 及 ELASTOS 操作系统

Page 1: CAR 构件技术 及 ELASTOS 操作系统

CAR 构件技术 及

ELASTOS 操作系统

上海科泰华捷科技有限公司2014.8

Page 2: CAR 构件技术 及 ELASTOS 操作系统

题外话• 谈点理论 , 谈点技术• 理论来源于朴素的想法和逻辑推理• 理论与实现间的差距

Page 3: CAR 构件技术 及 ELASTOS 操作系统

主要内容• CAR 构件技术

– 技术要点– 主要功能– 演进方向

Page 4: CAR 构件技术 及 ELASTOS 操作系统

主要内容• Elastos 操作系统

– 系统架构– 与 Android 的关系– 主要特点– 演进方向

Page 5: CAR 构件技术 及 ELASTOS 操作系统

CAR 构件技术• 技术要点• 主要功能• 演进方向

Page 6: CAR 构件技术 及 ELASTOS 操作系统

CAR 技术要点• 面向接口编程• C++ 扩展反射

Page 7: CAR 构件技术 及 ELASTOS 操作系统

面向接口编程• 内聚度与耦合度 ( 软件度量 )

– 高内聚– 低耦合– 模块化 ( 独立维护与升级 )

• 调用方与具体实现解耦• 设计模式中使用

– 类型 ( 或结构 ) 抽象– 模式与实现解耦– Listener 模式

Page 8: CAR 构件技术 及 ELASTOS 操作系统

面向接口编程• 思考

– 为何是面向接口 ? 面向类 ( 或抽象类 ) 是否可行 ?

– 接口是否可以包含属性 ?

Page 9: CAR 构件技术 及 ELASTOS 操作系统

面向接口编程• 使用方与实现方的契约 (Contract)

– 已有契约任何时候都必须有效 ( 不能改变 )– 增加新契约不影响现有约定– 与语言的具体实现相关

• 对象模型• 成员变量访问和方法调用的解析方式

– 编译时绑定– 运行时解析

• C++• Java

Page 10: CAR 构件技术 及 ELASTOS 操作系统

面向接口编程• C++

– 普通函数与虚函数• 普通函数 : 静态绑定 ( 编译时绑定 , 暴露了对象实现 ) 不

符合• 虚函数 : 动态绑定 ( 运行时解析 , 隐藏对象实现 ) 符合

– 成员变量• 静态成员变量 : 不占用对象内存空间 符合• 普通成员变量 : 占用对象内存空间 , 改变对象布局 不符合

– 接口与类• 接口 ( 抽象类 ): 纯虚函数 + 静态成员变量 符合• 类 : 函数 + 成员变量 ( 改变对象布局 ) 不符合

Page 11: CAR 构件技术 及 ELASTOS 操作系统

面向接口编程• Java

– 对象模型• JVM Spec 不做具体的规定• In some of Oracle’s implementations of

the Java Virtual Machine, a reference to a class instance is a pointer to a handle that is itself a pair of pointers:

– one to a table containing the methods of the object and a pointer to the Class object that represents the type of the object,

– the other to the memory allocated from the heap for the object data.

pointer

object reference

pointer

pointer

table Class object

method 1

method2

field 1

Field 2

*The Java Virtual Machine Specification, Java SE 7 Edition (Java Series) [Tim Lindholm, Frank Yellin, Gilad Bracha, Alex Buckley]

Page 12: CAR 构件技术 及 ELASTOS 操作系统

面向接口编程• Java

– 成员变量访问• 运行时解析成员变量 ( 非编译时绑定 , C++)• getfield• http://

docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.getfield

// 128: aload_0// 129: getfield 93 com/google/android/location/internal/server/ServiceThread:context Landroid/content/Context;

...

...

run-time constant pool of the current class

...

...

93 com/google/android/location/internal/server/ServiceThread:context Landroid/content/Context;

Page 13: CAR 构件技术 及 ELASTOS 操作系统

面向接口编程• Java

– 方法调用• 运行时解析成员变量 ( 非编译时绑定 , C++)• invokeinterface, invokevirtual• http://

docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokeinterface

• http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.invokevirtual

Page 14: CAR 构件技术 及 ELASTOS 操作系统

面向接口编程• Java

– 接口 (interface)• 成员变量是 static, final 和 public 符合• 方法是 abstract 和 public 符合

– 类 不符合– OSGI

• The Dynamic Module System for Java• http://www.osgi.org/Main/HomePage

Page 15: CAR 构件技术 及 ELASTOS 操作系统

面向接口编程• 接口升级

– 不能改变已有的方法以及它们的顺序– 从尾部增加方法– 不能改变接口 ID

Page 16: CAR 构件技术 及 ELASTOS 操作系统

C++ 扩展反射• 反射 : 描述以及操纵程序本身

– 程序设计语言– 反射

Page 17: CAR 构件技术 及 ELASTOS 操作系统

程序设计语言• 范型 (Paradigm)

• 函数式语言 (functional language)– Lisp, Scheme, Haskell– λ 演算 (lambda calculus): 替换与归约

– 函数也可作为参数 (first class object)– 绑定 (binding) 与赋值 (assign)

» 绑定后值不再改变 , 无副作用 (side effect)» 赋值后值可以改变 , 有副作用

– 副作用 : 影响计算顺序 ( 违背函数的性质 )» 引入单子 (monad)» 抽象为多个函数 , 通过函数传递 (cps, Continuation Programming

Style) 确定计算顺序

Page 18: CAR 构件技术 及 ELASTOS 操作系统

程序设计语言• 范型 (Paradigm)

• 结构化语言 (structural language)– C, Pascal

• 面向对象语言 (object-oriented language)– C++, Java, Smalltalk, Ruby

Page 19: CAR 构件技术 及 ELASTOS 操作系统

面向对象语言• 静态类型与动态类型

– 静态类型 (static typing): C++, Java• String name;

– 动态类型 (dynamic typing): Smalltalk, JavaScript

• name := String new asValue.

• 基于类与基于原型– 基于类 (Class-based): C++, Java, Smalltalk– 基于原型 (Prototype-based): Self, JavaScript

Page 20: CAR 构件技术 及 ELASTOS 操作系统

面向对象语言• 动态类型语言

– 对象模型– 方法调用

• 运行时解析

object

(1) Object model

idle tag

reference count

idle tag

object handle

reference count

...

object table

object handle

mark tag

mark tag

hash value

class

object size

fields

head

(2) The structure of class and method

superclass

method table

class name

object head

field number

fields

class method name

nativeness tag

bytecode

object head

literals

stack size

method

variable number

class

text

tagthe highest 31bits

32bits

(3) The structure of a variable value

Page 21: CAR 构件技术 及 ELASTOS 操作系统

面向对象语言• 动态类型

– 优点• 支持参数化多态 (Parametric polymorphism)• 无需模板 (template)• 例如 : AutoPtr<T>

– 缺点• 不支持静态类型检测• 类型错误需运行时才能发现• 例如 : str := obj toString.

Page 22: CAR 构件技术 及 ELASTOS 操作系统

面向对象语言• 基于类 (Class-based)

– 有类 (Class) 和对象 (Object)– 任何对象都是类的实例– 通过类间的继承实现代码重用– 例如 : C++, Java, Smalltalk

Page 23: CAR 构件技术 及 ELASTOS 操作系统

面向对象语言• 基于原型 (Prototype-based)

• 只有对象 (Object), 没有类 (Class)• 任何对象的产生是通过克隆另一个对象 ( 称为原型 ),

然后初始化自己• 通过对象间的代理 (delegation) 实现代码重用• 例如 : Self, JavaScript

Page 24: CAR 构件技术 及 ELASTOS 操作系统

• Ungar, Smith: SELF The Power of Simplicity, Journal of Lisp and Symbolic Computation, 4/1991

Page 25: CAR 构件技术 及 ELASTOS 操作系统

面向对象语言• Alan C. Kay’s principle (2003 Turing Award)

– Everything is an object– Objects communicate by sending and receiving messages

(in terms of objects)– Objects have their own memory (in terms of objects)Every object is an instance of a class (which must be an

object)The class holds the shared behavior for its instances (in

term of objects in a program list)To eval a program list, control is passed to the first object

and the remainder is treated as its message

* Kay A C. The Early History of Smalltalk[J]. ACM SIGPLAN Notices, 1993, 28(3): 69-95.