分类 Other 下的文章

How does the Huawei Ark compiler solve the problem? The principle of the Ark compiler

Before answering this question, let's take a look at the timeline in which Huawei works for the Ark compiler:

In 2009, Huawei started the development of 5G basic technology research and began to create a compilation group. The first batch of researchers at home and abroad joined.
In 2013, Huawei launched the self-developed compiler HCC for the field of base stations, and formally proposed the compiler framework.
In 2014, many experts at home and abroad joined Huawei and the Ark project was officially launched.
In 2016, the Compiler and Programming Language Lab was established.
In 2017, the first Java program "HelloWorld" on the Ark compiler runs.
One week before the Spring Festival in 2018, the Ark compiler ran through all the backend services of the Android system and successfully ported it to the phone.
In April 2019, the Huawei Ark compiler was announced at the domestic conference of the P30 series.

So, how is the principle of the Ark compiler implemented?

In fact, Huawei's so-called "Ark compiler" is not so much a compiler, it is a compile and run system; the operation of this system requires the cooperation environment and the terminal (that is, smart phone), the purpose is to bypass Android The virtual machine that the App must run on in the operating system, compile the mixed code such as Java/C/C++ into the machine code and run it directly on the mobile phone, completely bid farewell to the Java JNI overhead, and completely bid farewell to the virtual machine's GC memory. The application process caused by the recycling is dropped - thus ultimately achieving the smoothness of the Android operating system.

As mentioned above, in this implementation of the Ark compiler, four aspects need to be solved.

First: compile Java code directly into machine code

As far as the current situation is concerned, the problem that Java has to compile into machine code is the dynamic semantics in Java (corresponding to static semantics, which can be solved by advanced translation). Static semantics refers to Determining the language and meaning, while dynamic semantics refers to content that needs to be understood in conjunction with the context - in this case, if you want to compile dynamic semantics like compiling static semantics, many people think that it is impossible at all.

This is impossible, which is exactly what Huawei solved during the development of the Ark compiler.

Specifically, the Ark compiler solves two major difficulties in static compilation dynamic semantics through two-way blessing in the compile phase and the run phase: one is to design the data model, and the other is how to efficiently obtain dynamic information at runtime. The Ark compiler team basically traversed the dynamic semantics of Java and performed large-scale data modeling. At the same time, the precision of compile-time dynamic semantic analysis is greatly improved, especially when it involves cross-language invocation. In addition, Huawei has designed a dynamic semantic matching mechanism with core patents, which effectively reduces the overhead of dynamic semantics at runtime.

As a result, the Ark compiler can compile Java code into a language that the machine can execute directly. Huawei said that after the application of Huawei's Ark compiler, it no longer needs to be compiled on the mobile phone, and completely bid farewell to the virtual machine, which brings an Android experience that rivals or even surpasses iOS.

Second: Resolve JNI overhead for mixed languages

Since 95% of Top apps are written in mixed languages ​​such as Java/C/C++; the Ark compiler also needs to eliminate the JNI overhead of mixed language calls.

This involves a noun IR mentioned above, which is used to represent the data structure of the code. It is the "protocol and common language" used by the various modules of the compiler and related tools to transfer information. It is also a program transformation. And compile and optimize the carriers of various algorithms. It's the "brains" of the compiler, which directly determines the final effect of the compiler - so it's the most difficult.

The Huawei Ark Compiler team has been working on IR for five years, gradually exploring the signal laws of every nerve and every neuron in the "brain", and on the basis of this, invented a core patent. The different language codes can be uniformly compiled into the same set of directly executable machine code in the developer environment, thereby completely eliminating the overhead of the hybrid language calling each other.

In other words, the Huawei Ark compiler can implement a unified intermediate representation IR in a mixed language, which is equivalent to the same person able to understand the language of the world - of course, behind this is a deep understanding of the Huawei Ark compiler team based on multiple programming languages. And a lot of research and development.

Third: Code optimization outside of unified IR

Huawei's Ark compiler directly moved code optimization from the mobile phone to the developer environment, and may move to the cloud in the future. With the more powerful computing power of the developer environment, more advanced and sophisticated optimization algorithms can be implemented to achieve better optimization results. Huawei said that the optimization of code optimization in many specific scenarios is even subversive.

It is worth mentioning that developers use the Ark compiler and do not need to change the original coding habits. Developers can develop their own code optimization algorithms or code optimizations only through algorithms preset by the Ark compiler. In the future, Huawei will also provide code tuning tools. Developers can choose to adjust the code according to the optimization suggestions of the tool, and cooperate with the Ark compiler to obtain better execution results.

Fourth: Solve the problem of Caton caused by Android memory recycling

In order to solve this problem, the Ark compiler uses the reference counting method (RC, Reference Counting) to perform real-time memory recovery, and uses a special elimination ring algorithm (to eliminate the problem of unrecyclable problems caused by mutual reference of objects) to avoid System Caton brought by GC centralized recycling. Compared to GC, Ark's memory reclamation is real-time rather than centralized, and there is no need to suspend the application process, which greatly eliminates the jam.

In addition, the software has an infinite loop that everyone is familiar with, that is, the computer is occupied by computer resources by an infinite loop of running programs. This “infinite loop” is called “ring reference” in the software. In order to avoid the "eat" of the phone memory from the mechanism by the mechanism, the Ark compiler introduces the "alarm" flag of the annotation to mark the ring of the base class.

Of course, Java programmers can also mark rings in business code. After extensive practice verification, the Ark mechanism can reduce the occurrence of most of the program loops. On the other hand, the Ark compiler introduces an efficient loop recovery mechanism in the running state, allowing selective intelligent recovery of the memory footprint of an APP, which is an improvement over the traditional loop recovery algorithm.

In summary, in the face of the existing Android system in the code compilation, operation, IR, memory recovery and other four levels of problems, Huawei Ark compiler gave their own solutions, the core innovation is mixed language The unified intermediate representation and complete static compilation, but more importantly, Huawei's new ideas for solving the Android operating system App problem, and the courage to dare to invest in order to achieve this kind of thinking.

2019 Huawei Global Developers Conference will be held at the Songshan Lake Base in Huawei from August 9th to 11th. It will be officially opened this afternoon. According to the Shanghai Securities News, the Huawei EMUI10.0 system, the "Glory Smart Screen" equipped with Haisi Hongjun 818 smart chip and the new "Digital Reality" black technology based on virtual and real integration will be announced. Among them, EMUI10.0 will be the first to appear this afternoon.
07313-7zjszn6ms9i.png

According to the report, the market believes that the Huawei EMUI10.0 system will introduce "distributed technology" to solve the inter-terminal collaboration problem and realize the interoperability of multi-terminal full scenarios. Recently, Huawei EMUI officially began to warm up EMUI 10, saying that “EMUI 10 meets you at the developer conference, breaking the terminal boundary!” and EMUI 10 will use the details to achieve quality. And said that the beauty of quality lies in the details, the comfort in the details, everything is just right.

According to Huawei's "Glory HONOR" official microblogging spoiler, the glory wisdom screen will be officially released on the second day of this developer conference. The possibility of carrying the Hongmeng system is very large, and the latter may appear on August 10 with the glory and wisdom screen.

In addition, according to the agenda of the meeting, on August 11th, Huawei will uncover a black technology, and participants can sign up and participate in the black technology experience tour in batches for a 30-minute period. “Bringing consumers a new interactive experience. And the visual experience, seeing never before, knowing that the future has come." According to the official website of Huawei Developers Conference.

Huawei's developer conference invited 1,500 partners and 5,000 global developers, which will be Huawei's largest ever conference.

According to the latest news from Huawei's official website, the compiler tool Ark compiler has been released. According to reports, the Ark compiler is a cross-compiler suite developed by GCC. It includes front-ends for C, C++, and Fortran, as well as libraries for these languages (such as libstdc++, libgcc, etc.). HCC runs on an X86 linux architecture server and the generated binary runs on the Aarch64 architecture server.

15390-hpyqz8grq87.png

Preparation before installation

1) Environmental requirements

The Ark compiler supports the following 64-bit operating systems.

SUSE12sp4 and above.

Ubuntu 16.04 and above.

Other glibc versions are available in Linux distributions 2.22 and above.

2) Get the package

Installing the Ark compiler requires an open source package as shown in Table 2-1.

  GCC 7.3.0 编译器源码包  https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
  Binutils 2.31.1 汇编器、链接器等二进制工具集源码包  https://ftp.gnu.org/gnu/binutils/binutils-2.31.1.tar.gz
  Glibc 2.29 GNU libc 库源码包 https://git.linaro.org/toolchain/glibc.git/snapshot/glibc-2.29.tar.gz
  Mpc 1.1.0 复数运算库  https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz
  GNU MPFR 4.0.2 多精度浮点计算库  https://www.mpfr.org/mpfr-current/mpfr-4.0.2.tar.gz
  isl 0.21 集和线性约束范围内整数点关系的操作库  http://isl.gforge.inria.fr/isl-0.21.tar.gz

Install the HCC compiler

1) Operation steps

You can use the HCC tarball to install HCC anywhere under the current user privilege without affecting the use of other compilers.

a) Introduce the operation portal, for example, log in to the XX environment with the XX account.

b) Login HCC download address to download the compressed package

Hcc_arm64le.tar.gz

c) Copy the tarball to the directory you want to install.

The command script is as follows.

Cp hcc_arm64le.tar.gz /path/to/your/dir

d) Unzip the package.

The command script is as follows.

Tar zxvf hcc_arm64le.tar.gz

e) Set environment variables.

The environment variable command script is set as shown below.

Export PATH=/path/to/your/dir/hcc_arm64le/bin:$PATH

The build tools provided by the HCC compiler are in the =/path/to/your/dir/hcc_arm64le/bin directory.

2) Check after installation

After the HCC compiler is installed, you can run the aarch64-linux-gnu-gcc -v command to query the HCC version.

software download

Download source code:Download now

According to Huawei's official introduction, the Ark compiler is the first static compiler to completely replace the language virtual machine, completely without an interpreter. A compiler that takes into account Java development efficiency and C language runtime efficiency. Compared to the existing compilation mechanism:

  1. The Ark compiler is a static compilation method. In the existing Android system, running an application first starts the virtual machine, then reads the application code and interprets the execution one by one. It will occupy more processing resources and affect the efficiency of program execution. Of course, there are also early or runtime compilation techniques, such as AOT or JIT, that convert some of the programs into machine code and execute them directly on the CPU. However, it is still not possible to do 100% to get rid of virtual machine execution, which is the key to the current Android camp is not as good as the IOS camp.
  2. The static compilation mode of the Huawei Ark compiler can directly translate the dynamic features in the language into machine code. After the application is installed, the mobile phone can run the program at full speed, completely eliminating the drawbacks of the virtual machine and bringing about great improvement in efficiency.
  3. The Ark compiler is a compiler deployed in the development environment, and the existing compilation process mainly occurs on the mobile phone, which brings additional resource consumption.

At present, the Ark compiler is compiled and optimized for the general-purpose ARM chip architecture. In the future, the capabilities of the Kirin chip will be maximized through software and hardware co-design. At the same time, the Ark compiler supports Java standard usage, and the three-party application can be compiled directly without modifying the code. But if you want to get better performance or memory improvements, you can adjust the code structure and optimize with the Ark compiler.

This shows the number of connections per each DB:

SELECT 
    DB_NAME(dbid) as DBName, 
    COUNT(dbid) as NumberOfConnections,
    loginame as LoginName
FROM
    sys.sysprocesses
WHERE 
    dbid > 0
GROUP BY 
    dbid, loginame

show total Connections

SELECT 
    COUNT(dbid) as TotalConnections
FROM
    sys.sysprocesses
WHERE 
    dbid > 0
    

If you need more detail, run:

sp_who2 'Active'

Note: The SQL Server account used needs the 'sysadmin' role (otherwise it will just show a single row and a count of 1 as the result)

Have you ever needed to view your chat messages while reading an article within WeChat or playing a Mini Game? It’s a hassle to back out of your article mid-stream in order to check your messages.

Floating Window was initially introduced in 2017 as a way for you to save your place and minimize an article while checking other parts of WeChat like chats. We’ve now greatly expanded Floating Window so that you can “float” up to 10 different windows. Windows can be articles, document previews, or nearly any other type of content. When viewing a music or audio Mini Program, you’ll also be able to see what’s playing via our new music display in Floating Window. Floating Window makes multi-tasking within WeChat a breeze.
34732-jq0tp1373wn.png
When viewing an article, document preview, or other content, simply swipe right and hold to minimize the article to your Floating Window.

25929-cdj1scvk6.png

about more features,refer to:
https://blog.wechat.com/2019/07/17/wechat-7-0-5-for-ios-and-android/

免责声明
本博客部分内容来自于互联网,不代表作者的观点和立场,如若侵犯到您的权益,请联系[email protected]。我们会在24小时内进行删除。