The reason why Java is promoted is actually a big reason because it is cross-platform, and its big role is because of the virtual machine relationship.
Generally speaking, developers do not need to pay attention to the internal implementation of virtual machines to develop daily, but sometimes when it comes to performance, they need to understand the implementation mechanism of virtual machines.
So what I wrote today is more about compiling a set of your own virtual machines to pave the way for understanding the underlying principles of virtual machines in the future.
Compiling virtual machines may encounter many pitfalls and it will take time. Due to the differences in our environment, the problems we may encounter are inconsistent.
I can only say that I have listed all the problems I have encountered, just like to make a splash.
1 First of all, we should download the source code of openjdk. This openjdk actually has a version history. You can learn about it.
Then most of the source code content here is the same as oracle jdk content, and a few contents are different.
The source code of openjdk I downloaded here is openjdk-7u75-src-b13-18_dec_2014.zip. Everyone's version may be different, but it's the source code of openjdk.
2 In addition to preparing the above things, you also need to prepare an oracle jdk. I use jdk-6u32-linux-x64.bin for this jdk.
3 Then prepare various dependencies on linux first. These dependencies will be obtained later. In addition, I want to talk about the Linux system here.
It is ubuntu's 16.04LTS 64-bit, so it is best to prepare 64-bit for the previous things.
Everything is ready, now we'll start working! ! ! !
1If you set the java_home or classpath environment variable before, please comment out first.
2 Unzip openjdk-7u75-src-b13-18_dec_2014.zip and get the openjdk folder. We put it under /usr.
3Execute jdk-6u32-linux-x64.bin to get the jdk1.6.0_32 folder. Let's talk about putting this folder in /usr/java.
4 Enter vim /etc/profile and add the following content at the end:
export LANG=C#BootStrap-JDK installation path, replace it with the path of bootstrap-JDK export ALT_BOOTDIR=/usr/java/jdk1.6.0_32#Same as above, I used openjdk to compile, and when I ran hotspot, I replaced it with oracleJDK. Readers can directly replace it with OracleJDKexport ALT_JDK_IMPORT_PATH=/usr/java/jdk1.6.0_32#Specify several threads to execute this script export HOTSPOT_BUILD_JOBS=4export ALT_PARALLEL_COMPILE_JOBS=4#The content to be compiled, readers can choose to export BUILD_LANGTOOLS=true#export BUILD_JAXWS=false#export BUILD_JAXP=false#export BUILD_CORBA=falseexport BUILD_HOTSPOT=trueexport BUILD_JDK=trueexport SKIP_COMPARE_IMAGES=trueBUILD_DEPLOY=falseBUILD_INSTALL=false#The path to the compiled result is recommended to be stored in the build folder in the openjdk source code. Export ALT_OUTPUTDIR=/usr/openjdk/buildexport ALLOW_DOWNLOADS=true#The two environment variables need to be removed, otherwise there will be problems unset JAVA_HOMEunset CLASSPATHmake 2>&1 | tee $ALT_OUTPUTDIR/build.log
Note that source /etc/profile is required to update the configuration. But after input, it will run immediately, but it will not succeed now because it depends on those that have not been done yet. Press ctrl+c immediately to pause.
5 Execute some commands in the terminal to install the necessary dependencies, the commands are as follows:
sudo apt-get install build-essential gawk m4 libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev binutils libmotif-common ant
Some places also have openjdk-6-jdk installed. In fact, it is better not to install this here. We use oracle jdk to compile our openjdk source code. It is not recommended to use openjdk-6-jdk to compile the openjdk source code. That is why the jdk address pointed to in my build.sh script is export ALT_BOOTDIR=/usr/java/jdk1.6.0_32.
6 Now we go to the /usr/openjdk directory to execute the make sanity command, and check whether the configuration is OK. If there is no problem, it will be displayed
70,000 things are available, only the east wind is needed, enter make and start compiling. The compiled things will be generated in the /usr/openjdk/build directory.
This is the process, but some problems will occur during this period. According to the errors reported by him, we need to correct some errors. After correction, we will continue to make the command and then compile.
Here are some errors and solutions I encountered.
1>
echo "*** This OS is not supported:" `uname -a`; exit 1;
openjdk/hotspot/make/linux/Makefile:240: recipe for target 'check_os_version' failed
solve:
Comment out the following three lines of check_os_version in /openjdk/hotspot/make/linux/Makefile
check_os_version:
#ifeq ($(DISABLE_HOTSPOT_OS_VERSION_CHECK)$(EMPTY_IF_NOT_SUPPORTED),)
# $(QUIETLY) >&2 echo "*** This OS is not supported:" `uname -a`; exit 1;
#endif
2>
undefined reference to `void G1SATBCardTableModRefBS::write_ref_array_pre_work<oopDesc*>(oopDesc**, int)'
Solution: Set g1SATBCardTableModRefBS.cpp in hotspot/src/share/vm/gc_implementation/g1
template <class T> void G1SATBCardTableModRefBS::write_ref_array_pre_work(T* dst, int count) { if (!JavaThread::satb_mark_queue_set().is_active()) return; T* elem_ptr = dst; for (int i = 0; i < count; i++, elem_ptr++) { T heap_oop = oopDesc::load_heap_oop(elem_ptr); if (!oopDesc::is_null(heap_oop)) { enqueue(oopDesc::decode_heap_oop_not_null(heap_oop)); } } } Add the following content to the content
//2017-10-19 Vicent_Chen added void G1SATBCardTableModRefBS::write_ref_array_pre(oop* dst, int count, bool dest_uninitialized) { if (!dest_uninitialized) { write_ref_array_pre_work(dst, count); } } void G1SATBCardTableModRefBS::write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized) { if (!dest_uninitialized) { write_ref_array_pre_work(dst, count); } } //2017-10-19 Vicent_Chen added
Put the g1SATBCardTableModRefBS.hpp in hotspot/src/share/vm/gc_implementation/g1 as follows
virtual void write_ref_array_pre(oop* dst, int count, bool dest_uninitialized) { if (!dest_uninitialized) { write_ref_array_pre_work(dst, count); } } virtual void write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized) { if (!dest_uninitialized) { write_ref_array_pre_work(dst, count); } }
Comment out, and then add virtual void write_ref_array_pre(oop* dst, int count, bool dest_uninitialized); virtual void write_ref_array_pre(narrowOop* dst, int count, bool dest_unintialized);
3>
Error: time is more than 10 years from present: 1136059200000
solve:
The following time in the openjdk/jdk/src/share/classes/java/util/CurrencyData.properties file is changed to within 10 years.
AZ=AZM;2005-12-31-20-00-00;AZN
MZ=MZM;2006-06-30-22-00-00;MZN
RO=ROL;2005-06-30-21-00-00;RON
TR=TRL;2004-12-31-22-00-00;TRY
VE=VEB;2008-01-01-04-00-00;VEF
4> In the future, when compiling RMIServerImpl_Stub.class, it is likely that the memory is insufficient, because I observed through the system monitor that the memory has increased sharply during this period. I don’t know the specific reason, but I have been re-entering the make command several times in a row, until the last time
Success again. So when you encounter this situation, you can do it again many times. The last time the memory did not skyrocket.
Compilation is successful as follows:
Then you can find your compiled jdk in the build folder.
Thank you everyone, if you have any questions, please ask me.
The above detailed explanation of the compilation based on the compilation virtual machine jvm-openjdk is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.