1 / 183

CAR 构件技术 及 ELASTOS 操作系统

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

romeo
Download Presentation

CAR 构件技术 及 ELASTOS 操作系统

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CAR构件技术及ELASTOS操作系统 上海科泰华捷科技有限公司 2014.8

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

  3. 主要内容 • CAR构件技术 • 技术要点 • 主要功能 • 演进方向

  4. 主要内容 • Elastos操作系统 • 系统架构 • 与Android的关系 • 主要特点 • 演进方向

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

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

  7. 面向接口编程 • 内聚度与耦合度(软件度量) • 高内聚 • 低耦合 • 模块化(独立维护与升级) • 调用方与具体实现解耦 • 设计模式中使用 • 类型(或结构)抽象 • 模式与实现解耦 • Listener模式

  8. 面向接口编程 • 思考 • 为何是面向接口?面向类(或抽象类)是否可行? • 接口是否可以包含属性?

  9. 面向接口编程 • 使用方与实现方的契约(Contract) • 已有契约任何时候都必须有效(不能改变) • 增加新契约不影响现有约定 • 与语言的具体实现相关 • 对象模型 • 成员变量访问和方法调用的解析方式 • 编译时绑定 • 运行时解析 • C++ • Java

  10. 面向接口编程 • C++ • 普通函数与虚函数 • 普通函数:静态绑定(编译时绑定,暴露了对象实现)不符合 • 虚函数:动态绑定(运行时解析,隐藏对象实现)符合 • 成员变量 • 静态成员变量:不占用对象内存空间 符合 • 普通成员变量:占用对象内存空间,改变对象布局 不符合 • 接口与类 • 接口(抽象类):纯虚函数+静态成员变量符合 • 类:函数+成员变量(改变对象布局) 不符合

  11. 面向接口编程 • 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. • *The Java Virtual Machine Specification, Java SE 7 Edition (Java Series) [Tim Lindholm, Frank Yellin, GiladBracha, Alex Buckley]

  12. 面向接口编程 • Java • 成员变量访问 • 运行时解析成员变量(非编译时绑定, C++) • getfield • http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.getfield // 128: aload_0 // 129: getfield93 com/google/android/location/internal/server/ServiceThread:contextLandroid/content/Context;

  13. 面向接口编程 • 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

  14. 面向接口编程 • Java • 接口(interface) • 成员变量是static, final和public 符合 • 方法是abstract和public 符合 • 类 不符合 • OSGI • The Dynamic Module System for Java • http://www.osgi.org/Main/HomePage

  15. 面向接口编程 • 接口升级 • 不能改变已有的方法以及它们的顺序 • 从尾部增加方法 • 不能改变接口ID

  16. C++扩展反射 • 反射:描述以及操纵程序本身 • 程序设计语言 • 反射

  17. 程序设计语言 • 范型(Paradigm) • 函数式语言(functional language) • Lisp, Scheme, Haskell • λ演算(lambda calculus):替换与归约 • 函数也可作为参数(first class object) • 绑定(binding)与赋值(assign) • 绑定后值不再改变,无副作用(side effect) • 赋值后值可以改变,有副作用 • 副作用:影响计算顺序(违背函数的性质) • 引入单子(monad) • 抽象为多个函数,通过函数传递(cps, Continuation Programming Style)确定计算顺序

  18. 程序设计语言 • 范型(Paradigm) • 结构化语言(structural language) • C, Pascal • 面向对象语言(object-oriented language) • C++, Java, Smalltalk, Ruby

  19. 面向对象语言 • 静态类型与动态类型 • 静态类型(static typing): C++, Java • String name; • 动态类型(dynamic typing): Smalltalk, JavaScript • name := String new asValue. • 基于类与基于原型 • 基于类(Class-based): C++, Java, Smalltalk • 基于原型(Prototype-based): Self, JavaScript

  20. 面向对象语言 • 动态类型语言 • 对象模型 • 方法调用 • 运行时解析

  21. 面向对象语言 • 动态类型 • 优点 • 支持参数化多态(Parametric polymorphism) • 无需模板(template) • 例如: AutoPtr<T> • 缺点 • 不支持静态类型检测 • 类型错误需运行时才能发现 • 例如: str := objtoString.

  22. 面向对象语言 • 基于类(Class-based) • 有类(Class)和对象(Object) • 任何对象都是类的实例 • 通过类间的继承实现代码重用 • 例如: C++, Java, Smalltalk

  23. 面向对象语言 • 基于原型(Prototype-based) • 只有对象(Object),没有类(Class) • 任何对象的产生是通过克隆另一个对象(称为原型),然后初始化自己 • 通过对象间的代理(delegation)实现代码重用 • 例如: Self, JavaScript

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

  25. 面向对象语言 • 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.

  26. 计算反射 • 基本概念 • 计算反射(Computational reflection, Brian Cantwell Smith, 1982) • 计算反射是系统具有的一种能力, 使得它能够像处理问题域一样来表述, 操作和处理系统本身 • 反射系统: 一种运行时能够与自身因果关联的程序 • 运行时程序可以根据实际情况修改自身 • 修改后的程序反过来改变原有的运行过程。 B.C. Smith. Informal Proceedings of the First Workshop on Reflection and Metalevel Architectures in Object-Oriented Programming. OOPSLA-ECOOP'90, Ottawa.

  27. 计算反射

  28. 计算反射 • 反射程度 • 内省(introspection):指程序对自描述信息只能读不能修改 • 例如:Java • 调解(intercession):指程序对自描述信息可读也可以修改 • 例如:Smalltalk

  29. 计算反射 • 反射内容 • 结构反射:指自描述信息与语言语法,程序结构相关 • 譬如面向对象语言中的类, 类的属性和方法等信息 • 例如:Java, Smalltalk • 行为反射:指自描述信息与语言语义,程序行为相关 • 譬如面向对象语言中的对象实例化行为,消息传递行为,对象输出行为以及控制流等信息 • 例如:Smalltalk

  30. 计算反射 • 反射体系结构 • 元类(metaclass, class-based OOPL, SmallTalk-80) • 类的类,提供了类本身的定义, 包括类的内部结构以及类(作为对象时)的行为(譬如如何处理New消息) • 问题域计算由类描述,而反射计算由元类描述

  31. 计算反射 Jacques Ferber. Computational reflection in class based object oriented languages. In OOPSLA 89, pages 317-326. ACM SIGPLAN Notices, 24(10).

  32. 计算反射 • 反射体系结构 • 元对象(metaobject, prototype-based OOPL, 3-KRS, Pattie Maes) • 将语言的构成元素,譬如类,方法,属性,消息,消息的响应行为等都实现为对象, 此类对象称之为元对象 • 对象与元对象相互关联 • 问题域计算由对象描述,而反射计算由元对象描述 • Pattie Maes. Concepts and Experiments in Computational Reflection. In OOPLSA 87 Proceedings, pages 147-155, 1987.

  33. 计算反射 Jacques Ferber. Computational reflection in class based object oriented languages. In OOPSLA 89, pages 317-326. ACM SIGPLAN Notices, 24(10).

  34. 计算反射 • 作用 • 程序运行时可配置 • 应用程序框架 • 应用与框架的接合 • 例如应用activity的创建 • Web服务 • jsp, java servlet, web container • 软件服务 • 软件模块按需组装

  35. 计算反射 • 应用Activity的创建 • 应用apk部署时, PackageManagerService(pms)扫描其AndroidManifest.xml, 在系统中记录下应用包含的Activity及其所响应的intent种类 • 发起StartActivity命令后, ActivityManagerService(ams)根据intent通过pms找到合适的Activity以及其所在apk的信息 • Ams创建应用进程, 并向该进程发起Activity启动命令 • 应用进程的ActivityThread解析参数后加载apk相应的jar包,并通过反射的方式创建Activity

  36. 计算反射 • 典型实现 • 3-Lisp • 3-KRS • CLOS • Smalltalk-80

  37. 计算反射 • 3-Lisp • 反射体系结构是由用户程序,反射解释程序(RPP),非反射解释器G组成的塔式结构 • 解释器G是用其它语言实现的非反射的Lisp解释程序 • RPP是基于控制流传递的反射的元循环解释程序(meta-circular interpreter) • 用户程序处于反射塔的底端,G处于顶端,RPP则组成了塔的中间部分 • 反射塔的层数根据用户程序的运行情况可以从2层动态的变化到任意层 • Brian Cantwell Smith, Procedural Reflection in Programming Languages, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, PhD Thesis, 1982

  38. 计算反射 • 3-Lisp • 区分普通函数(类型为”simple”的函数)与反射函数(类型为”reflective”的函数, 用于定义反射计算) • 假定用户程序处于0层,则普通函数由1层的RPP(或G)解释执行,而反射函数则由2层的RPP(或G)解释执行 • 反射函数与1层的RPP在同一层次上运行,并可嵌入其中 • 由此反射函数可以操纵RPP中的数据结构,从而控制RPP对程序自身的解释

  39. 计算反射 • 3-Lisp 用户程序首先由非反射解释器G解释执行.当遇到反射函数时,则在G和用户程序间插入一层RPP,此时由G解释执行RPP和用户程序中的反射函数,再由RPP解释执行用户程序的其它部分.如果反射函数执行期间,又遇到反射函数,则再次插入一层RPP.新的反射函数与2层的RPP由G解释执行,旧的反射函数与1层的RPP由2层的RPP解释执行,用户程序的其它部分则由1层的RPP解释执行.当反射函数执行完毕时,则减去一层RPP.3-Lisp程序运行中,每当增加了一层RPP以后,不需要重新运行用户程序,而是将之前位于最上面的RPP所保存的用户程序执行时的环境信息和控制流信息传递给新增加的一层RPP.

  40. 计算反射 • 3-KRS • 基于原型的面向对象语言,一切都是对象 • 问题域计算由普通对象实现,反射计算由元对象实现 • 普通对象通过”meta”指针指向元对象,后者定义了其所关联对象(通过”referent”指针)的行为 • Pattie Maes, Concepts and experiments in computation reflection, ACM SIGPLAN Notices, 22(12):147-155, December 1987

  41. 计算反射 • 3-KRS • 系统定义了一组基本的元对象 • 元对象参与了解释器对程序的解释

  42. 计算反射 • CLOS(Common Lisp Object System) • 元对象协议(metaobject protocol):是语言中所有元对象的接口定义,程序通过这些接口访问,操作元对象 • 语言对外开放的api, 通过它用户可以修改语言的结构和行为 • Gregor Kiczales, Jim des Rivieres, and Daniel G. Bobrow, The Art of the Metaobject Protocol, 1991, MIT Press.

  43. 计算反射 • Smalltalk • 元类(metaclass):类的类 • 完善了面向对象理论,消除了基于类的面向对象语言中类和对象的差别 • 建立了反射体系结构,类定义目标对象,元类定义了类对象,反射计算由元类描述 • Goldberg A. and Robson D. (1983) “Smalltalk-80: The Language and its Implementation”. Addison-Wesley. Reading, Massachusetts.

  44. 计算反射 • Smalltalk-80

  45. 计算反射 • Alan C. Kay’s principle (2003 Turing Award) p1. Everything is an object p2. Objects communicate by sending and receiving messages (in terms of objects) p3. Objects have their own memory (in terms of objects) p4. Every object is an instance of a class (which must be an object) p5. The class holds the shared behavior for its instances (in term of objects in a program list) p6. 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.

  46. 计算反射 • Class-based OOPL的Object与Class推导 • meta的无限递归 • Premise I: Everything is an object(p1) • Premise II: Class belongs to everything(axiom) • Conclusion I: Every class is an object(c1) • Premise III: Every object is an instance of a class(p4) • Conclusion II: Every class is an instance of a class (called metaclass)(c2) … recursively

  47. 计算反射

  48. 计算反射 • Class-based OOPL的Object与Class推导 • Object与Class的基本结构 • Premise I:Class的元类是自身, Class的父类是Object, Object的元类是Class, Object没有父类 • Premise II:Theclass holds the shared behavior for its instances(p5)

  49. 计算反射 SOM Metaclass Framework, Putting Metaclasses to Work

  50. 计算反射 • 元类兼容性问题 • 类之间的继承与各自元类之间的继承不协调

More Related