Read Java native source before the preparation

Source: Internet
Author: User

Objective

Read Java Native source code, we will generally go to the website download openjdk8 Source (http://download.java.net/openjdk/jdk8/promoted/b132/openjdk-8-src-b132-03 _mar_2014.zip), then analyze, and then a lot of articles will let you compile. In fact, if only to analyze the source code, do not compile at all, directly find the Hotspot folder under the SRC folder to see, here is the source of the hotspot.

Note: The source code is wrong, it was written http://www.java.net/download/openjdk/jdk8/promoted/b132/openjdk-8-src-b132-03_mar_2014.zip

Problems that exist

Source in the Include path is not complete, resulting in a lot of functions can not jump, have to manually find, very inconvenient. Take the ./src/cpu/sparc/vm/assembler_sparc.cpp file as an example, the original code is this:

" precompiled.hpp "  "asm/assembler.hpp " "Asm/assembler.inline.hpp " int Abstractassembler::code_fill_byte () {  return0x00;                  // illegal instruction 0x00000000}

We hope this is the case:

" ./SRC/SHARE/VM/PRECOMPILED/PRECOMPILED.HPP "  "./src/share/vm/asm/assembler.hpp""./src/share/vm/ ASM/ASSEMBLER.INLINE.HPP"int  abstractassembler::code_fill_byte () {   return 0x00;                  // illegal instruction 0x00000000}
Analyze Problems & Solutions

Of course, we can manually find the corresponding header file and then a complete one, but the number of files is thousands, which can take a lot of time, and therefore the project-auto-complement include path. Look at the include paths in different files and discover that there are two categories, one of include "precompiled.hpp" which is the header files that are included in the folder, such as,,,, and ./src/share/vm so on asm prims oop utilities , so the steps to resolve are as follows:

    1. For "precompiled.hpp" , we can replace all of them directly with the editor include "./src/share/vm/precompiled/precompiled.hpp" ;
    2. For other header files, such as,, include "asm/assembler.hpp" #include "oops/oop.inline.hpp" #include "utilities/accessFlags.hpp" etc. that depend on different file paths, use the programs in this project to automatically complement them.
Implementation principle
    1. Traverse all the files under the SRC folder to find the file with the suffix,,, and cpp hpp c h Save it in the list At the same time, the corresponding folder path is saved in set (the reason to choose Set instead of list is because there may be many files in the same folder, and the folder is saved once);

    2. Processes the files saved in the list, each time the file is processed, reads the matching folders in the set, and replaces them with such #include "asm forms #include "./src/share/vm/asm .

Other questions

There are also some files that depend on a specific platform, such as ./src/share/vm/utilities/copy.hpp :

#ifdef target_arch_x86# include"copy_x86.hpp"#endif#ifdef target_arch_sparc# include"copy_sparc.hpp"#endif#ifdef target_arch_zero# include"copy_zero.hpp"#endif#ifdef target_arch_arm# include"copy_arm.hpp"#endif#ifdef target_arch_ppc# include"copy_ppc.hpp"#endif

This kind of code program is not processed, so the platform-dependent functions may not be found, it is necessary to be in the program

static String startInclude = "#include \"";Replace with static String startInclude = "# include \""; another run (note that there is a space between # and include).

Operating instructions

When this program runs, it is recommended that the source directory src of the hotspot be placed in a folder under the project (in this project /Resource ) to prevent confusion.

Read Java native source before the preparation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.