Dcevm,java class Dynamic Substitution primary experiment description

Source: Internet
Author: User
Tags tomcat server

Overview

DCEVM, full name dynamic Code Evolution, a JVM patch, is designed to implement class substitution at runtime. The latest project address is: https://dcevm.github.io/

The following will be from the installation, validation, build test environment, testing and other aspects of a brief description.

Installation

First login URL: https://dcevm.github.io/, the site explicitly gave the binaries (binary program) download link, the project is divided into two versions of the release program, one is light version, the other is full, The difference is that the full version supports more features, but for general development, the light version is sufficient, for more details please refer to the original article.

Binary files can be extracted from the file after downloading a jar file with installer, which is used to install the patch file installation program, run as follows:

Java-jar Installer.jar
If running in a Linux/unix environment, please add sudo to the front of the command. After the program runs, the following installation screen will appear:


Next click on the button "Add installation directory" To select the Java_home directory to patch, select Finish, click "Replace by Dcevm" and "Install DCEVM as ALTJVM" To make DCEVM patches for the target JDK.

Verify

After the installation is complete, the effect should be similar, and then we can verify the installation through the console. Open the console terminal program, and then type the following command:

Java-version

If the installation is correct, the following message will appear, focusing on the last word "Dynamic Code Evolution".

Java version "1.7.0_71" Java (TM) SE Runtime Environment (build 1.7.0_71-b14) Dynamic Code Evolution 64-bit Server VM (build 24.71-b01-dcevmlight-2, Mixed mode)

Build a test environment

Next we can test the effect of dynamic loading by a specific experiment, and we need to prepare the test environment before testing.

Tomcat

Go to http://tomcat.apache.org to download a Tomcat server program, the version chosen here is 7. After extracting, create a DCEVM directory under the WebApps of its home directory, and then create a web app with the following structure:

dcevm/

├──meta-inf

└──web-inf

└──lib

The Java project creates a Java project from eclipse with the following directory structure:

/users/i318043/z/workspace/eclipse/experimentdcevm

├──webcontent

│└──web-inf

│└──classes

│└──com

│└──github

│└──dcevm

│└──test

└──src

└──com

└──github

└──dcevm

└──test

The contents of the. project.xml and. classpath files are as follows, the content is for reference only and the specific environment needs to be adjusted as needed:

<?xml version= "1.0" encoding= "UTF-8"?>

<classpath>

<classpathentry kind= "src" path= "src"/>

<classpathentry kind= "Con" path= "org.eclipse.jdt.launching.jre_container/ org.eclipse.jdt.internal.debug.ui.launcher.standardvmtype/javase-1.7 "/>

<classpathentry kind= "Output" path= "Webcontent/web-inf/classes"/>

</classpath>

The note here is linkedresources, which is a virtual directory that points to the DCEVM in Tomcat in order to have the compiled binary class file output directly to Tomcat.

<?xml version= "1.0" encoding= "UTF-8"?>

<projectDescription>

<name>ExperimentDCEVM</name>

<comment></comment>

<projects>

</projects>

<buildSpec>

<buildCommand>

<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>

<triggers>auto,full,incremental,</triggers>

<arguments>

<dictionary>

<key>LaunchConfigHandle</key>

<VALUE>&LT;PROJECT&GT;/.EXTERNALTOOLBUILDERS/EXPERIMENTDCEVM Build.xml [Builder].launch</value >

</dictionary>

</arguments>

</buildCommand>

<buildCommand>

<name>org.eclipse.wst.common.project.facet.core.builder</name>

<arguments>

</arguments>

</buildCommand>

<buildCommand>

<name>org.eclipse.jdt.core.javabuilder</name>

<arguments>

</arguments>

</buildCommand>

</buildSpec>

<natures>

<nature>org.eclipse.jdt.core.javanature</nature>

<nature>org.eclipse.wst.common.project.facet.core.nature</nature>

</natures>

<linkedResources>

<link>

<name>WebContent</name>

<type>2</type>

<location> /USERS/WOODY/Z/APACHE-TOMCAT-7.0.61/WEBAPPS/DCEVM </location>

</link>

</linkedResources>

</projectDescription>

At this point, the environment is set up, and then the coding test can be done. Testing during the test, we need to prepare three program files, two Java and a JSP, and a configuration file, Web. XML, if you need to compile with ant, right-click on the icon of the Java project, select Export, and select Ant Buildfiles can automatically generate Build.xml. Source list Web. xml
<?xml version= "1.0" encoding= "iso-8859-1"?><!--Licensed to the Apache software Foundation (ASF) under one or Mo  Re contributor license agreements.  See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License");  You are not a use of this file except in compliance with the License.  Obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 unless required by applicable or agreed to writing, software distributed under the License are distributed on a "as is" BASIS, without warranties  or CONDITIONS of any KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.--><web-app xmlns = "Http://java.sun.com/xml/ns/javaee" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "          Http://java.sun.com/xml/ns/javaee            Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "version=" 3.0 "metadata-complete=" true "> <welcome -file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.xhtml</welco Me-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-fil E> <welcome-file>welcome.jsp</welcome-file> </welcome-file-list></web-app>
welcome.jsp
Helloworld.java
Package Com.github.dcevm.test;public class HelloWorld/*4.2*/extends Abstracthelloworld {public String getgreetings () { /*5.0, 5.2*/System.out.println ("... | x| | ... ");/*1*/return" Hello tricky? ". Concat (""). Concat (_getgreeting1 ()). Concat (""). Concat (_getgreeting2 ()). Concat (Getabstractgreeting ()); /*2.1*/private String _getgreeting1 () {return "Damn it!";} /*2.2*/private String _getgreeting2 () {return "Why nobody mentions this trap!";}} /*4.1*/Abstract class Abstracthelloworld {protected String getabstractgreeting () {return "<abstract y=good=y Greeting> ";}} /*5.1*///==> redefine Auto-build approach
Newclass.java
Package Com.github.dcevm.test;public class Newclass {public String Getword () {return "Hmm ...";}}
Test target
    1. Modify the existing class method body to implement class auto-substitution
    2. Adding new methods for existing classes, implementing class auto-substitution
    3. Create a new abstract class, as the parent class of the existing class, and investigate the parent class method in the subclass to implement the automatic substitution of the parent class and the subclass
    4. Create a new class and invoke the method of the new class in the JSP to implement the automatic loading of the new class
Test steps
    • Comment out all <jsp> tags in the JSP file
    • Delete Newclass
    • Comment out code for 2.1, 2.2, and 4.1, 4.2 tags
    • Debug mode starts tomcat with the command:sudo./catalina.sh jpda Run
    • Enable remote debugging in eclipse
    • JSP Open with Hwbean, and the code with a tag 1 method to modify, complete the test target 1
    • Turn on the 2.1 and 2.2 tagging methods in the code to complete the test target 2
    • Turn on 4.1 and 4.2 to complete the test target 3
    • Open the JSP with Ncbean related code, and add the Newclass.java file, complete the test target 4
About Builders

The source has added ant compilation, right click on the project, select "Properties", enter "Builder", tick off "EXPERIMENTDCEVM build.xml [Builder]" can disable Ant compilation. Ps:ant compilation is primarily for projects that are not well suited for Java builder using Eclipse.

Document Source Download

http://download.csdn.net/detail/rcom10002/8612013

Dcevm,java class Dynamic Substitution primary experiment description

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.