Rambling: how to explain to his girlfriend obscurity OS is how to achieve cross-platform?


Weekend resting at home, his girlfriend in the brush circle of friends, she suddenly asked me:

Hong Meng OS Review

August 9, 2019 Huawei Developers Conference, CEO Yu Chengdong, Huawei's consumer business officially announced the release of its own operating system obscurity, kernel Linux kernel, microkernel obscurity and LiteOS. The future will get rid of the Linux kernel and LiteOS, only obscurity microkernel.

Hong Meng (English: Harmony OS, codenamed Ark) is a Huawei since 2012, the development could be compatible Android app cross-platform operating system.

Figure: Four technical characteristics of obscurity OS
1. Distributed architecture for the first time for the terminal OS, to achieve seamless collaboration experience across terminal
2. Determine the IPC latency and high-performance engine technology to achieve smooth natural systems
3. remodeling the terminal device trusted security based microkernel architecture
4. The development of a unified IDE support, multi-terminal deployment, cross-terminal Ecological share

What is cross-platform

In the 平台 ≈ 操作系统past, . Therefore, cross-platform in the traditional sense that is not dependent on the operating system does not rely on the hardware environment. Application of an operating system under development, into another operating system can still run.

But with the development of science and technology, 平台 ≈ 操作系统it has not established, like Huawei launched obscurity OS, he can support a wide variety of devices, such as mobile phones, watches, computers, cars, smart home devices.

So, today we are talking about cross-platform, cross-device refers to. which is平台 ≈ 设备

Therefore, Huawei hopes obscurity OS can run on a variety of equipment, so the obscurity OS necessarily need to have cross-platform capabilities.

Moreover, Hong Meng wanted to do more than just cross-platform operating system, is more important is to let users and developers really feel across platforms.

Therefore, cross-platform operating system obscurity objectives are: to enable developers to focus their business logic, such as the development of the same terminal as the development of distributed applications across the terminal, but also to the final consumer to enjoy the powerful cross-business collaboration capability for the terminal usage scenarios bring seamless experience.

Java cross-platform

First is that Java is how to achieve cross-platform.

Java for cross-platform support, as support for security and mobility networks, are distributed throughout Java architecture. Java language specification in which the actor has an important role, Class files, Java Virtual Machine (JVM) and so on.

First, in the Java language specification defines the ranges and behavior of the Java language primitive data types. Secondly, all Java files to be compiled into a single Class file. Finally, the Java virtual machine will turn into a binary file corresponding to Class platform.

Java's platform independence is built on the basis of sexual Java virtual machine on top of the platform, because the Java virtual machine shield the differences of the underlying operating system and hardware.

Want to run some Java code to go through multiple steps, the Java source code into machine code into machine can perform, this process is mainly done by the virtual machine.

In the famous HotSpot virtual machine, there are interpreted and time compilation in two forms:

  • Interpreted

    • Translate the byte codes one by one to execute machine code and

  • Time compiler (Just-in-time, JIT)

    • All methods contained in bytecodes a compiled into machine code before execution.

HotSpot default mixed mode, combines the advantages of both interpretation and execution time compilation. It will first interpreted byte code, the code is hot (hot spot detection) is repeatedly performed after which, in a method performed in units of time compilation.

Android across platforms

In fact, Android Java-based, so the same token, you want to run some Android code is also subject to a number of steps, the Android source code into machine code into machine can perform.

But to achieve this conversion process is different in different versions of Android:

Android 1.0 (2008): Using a virtual machine called Dalvik, and integrates an interpreter. When the App is running, it will call the interpreter, the code sentence by sentence to explain, very slow.

Android 2.2 (2010): The introduction of JIT (Just In Time) compiler immediate mechanism, when App is running, users will often use the compiler function is 010101 machine machine code can be executed directly, without sentence by sentence to translate. When not commonly used functions appear, and then call the interpreter to translate; so faster, but every time you start App to be recompiled once, not once and for all.

Android 5.0 (2014 Nian October): the Dalvik virtual machine into ART (Android Run Time), will replace the JIT compiler to AOT (Ahead of Time). So, App after download and install onto the phone while the compiled code can be compiled into machine could understand 101010; the rest of the code is not a good translation, it then wake up when the user is using an interpreter to translate. So, you do not need to compile each time you open App, App installation time but a bit long, but also takes up space on your phone.

Android 7.0 (2016): The mixed compilation mechanism, the installation does not compile the first intermediate code, but when the user is idle parts of the code can be compiled into machine code, through the AOT compiler to statically compiled. If AOT not had time to compile or not compile, then call JIT + interpreter. This mechanism, which is equivalent with time for space, which shortens the waiting time users to install APP, and in turn can do to optimize virtual machine compiler and interpreter elevated to the maximum efficiency.

Android build problem

It can be seen from the beginning of 2008 Android 1.0, Android has been in the above compiler optimization efforts.

Current Android adoption is interpreted + JIT + AOT integrated mode, the space occupied by the installation of speed + + running speed has reached a good balance.

But Android compiler issues has been criticized. Despite improvements in the subsequent explanation Android 8.0, a model to explain the efficiency dramatically; Providing pre-positioned manner on the hot code Android 10.0, applied in the installation will be able to know in advance common code compiled.

But, for now, anyway, Android failed to get rid of such a premise: that the application being packaged into APK, when used or Java code. In other words, the user can process becomes APK applications, it is also experienced within a compilation Android system, which is a wound, but the sill.

Hong Meng across platforms

So, the code is compiled Hong Meng OS is kind of how it? He is how to solve the problem of cross-platform it?

We can see from the figure above, in obscurity OS architecture, Ark compiler and multi-terminal IDE development plays an important position.

Cross-platform there is a major challenge, and that is adapted to each platform issues, especially now that more and more variety of device types, how the same application, mobile phones, watches, cars, televisions above can be adapted to show it? This is what multi-terminal development IDE done.

Huawei provides terminal using multiple IDE, multi-language compiler unified, distributed architecture provides Kit screen layout controls, and automatic adaptation of interactive support drag and drop controls, preview oriented visual programming so that developers can build efficient many-fold based on the same project autorun App, a true development, deployment multiport, shared between ecology across devices.

The figure is provided by Huawei IDE, which can drag the graphical interface control, and the IDE can help fit a variety of terminal devices automatically.

With IDE, target can easily develop a code which automatically adapted to a variety of devices, but a variety of machine instructions executed by the device is not the same, how to set these codes are compiled into respective devices require machine instructions it?

Android devices are carried out by the built-in virtual machines on different devices compiled, so we know what the equipment before compiling specifically, then, Hong Meng OS is how to do it? This is the Ark compiler doing things.

Huawei's Ark compiler is the first Android virtual machine model to replace the static compiler, available for developers in the development environment will be a one-time high-level language compiled to machine code. In addition, the future of the Ark compiler will compile a unified multi-language support, can greatly improve development efficiency.

The reason why Android "slow" because of his build process is carried out in the end, that is required on the user's mobile phone, were compiled into machine code executable by a virtual machine.

The use of Hong Meng OS Ark compiler can be high-level language (Java) directly into machine code, thus bypassing the virtual machine. This compilation process and not on the user's phone to complete, but in the application development stage is complete.

By Ark compilers, application developers before downloading has been transformed into machine code that can be recognized, and thus can be quickly installed on the phone, get up and running, without having compiled a VM - to some extent, Ark compilation the compilation process is to advance the application development stage, thus significantly reducing the burden of running smart phones and operating systems.

Huawei official reports, Ark compiler is the first completely replace the static language compiler virtual machine, all without an interpreter. Both Java development productivity and operational efficiency of the C language compiler.

In addition to code compilation, the compiler Ark also provides a more efficient memory mechanism, it is recovered and Android memory except that:

Android adoption in the memory recovery mechanism to focus on recycling, sounding more necessary to suspend the application when the global recovery, which is one of random Caton root cause. The Ark compiler uses a real-time reference counting method to recover memory, and with the use of a special algorithm to eliminate ring (objects refer to each other can not be recycled to eliminate problems caused by), to avoid the GC centralized recovery system brings Caton . Compared to GC, the Ark of the memory recovery is real-time, rather than centralized, and does not need to suspend the application process, thus greatly eliminating Caton.

In addition, as the same JVM actually supports multiple languages, Huawei said, Ark compiler will support more in the future through the development of language. In other words, developers in other languages, the future can obscurity OS-based application development.

References:

https://www.jishuwen.com/d/2NN3

https://www.zhihu.com/question/339567108 https://www.cnbeta.com/articles/tech/876171.htm https://www.cnbeta.com/articles/tech/876919.htm https://juejin.im/post/5cb07000f265da037d4f9be6



Guess you like

Origin juejin.im/post/5d50d05ee51d4561da620117