-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from ddyblackhat/master
jvm部分数据结构作业
- Loading branch information
Showing
107 changed files
with
3,466 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...p04/1796244932/learn01/src/main/java/com/dudy/learn01/base/aop/DynamicProxy/Business.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.dudy.learn01.base.aop.DynamicProxy; | ||
|
||
/** | ||
* Created by dudy on 2017/3/22. | ||
*/ | ||
public class Business implements IBusiness,IBusiness2{ | ||
@Override | ||
public void dosomething() { | ||
System.out.println("dosomething....."); | ||
} | ||
|
||
@Override | ||
public void dosomething2() { | ||
System.out.println("dosomething2....."); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...04/1796244932/learn01/src/main/java/com/dudy/learn01/base/aop/DynamicProxy/CGlibDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.dudy.learn01.base.aop.DynamicProxy; | ||
|
||
import net.sf.cglib.proxy.Enhancer; | ||
|
||
/** | ||
* Created by dudy on 2017/3/22. | ||
*/ | ||
public class CGlibDemo { | ||
|
||
public static void main(String[] args) { | ||
byteCodeGe(); | ||
} | ||
|
||
public static void byteCodeGe(){ | ||
//创建一个织入器 | ||
Enhancer enhancer = new Enhancer(); | ||
// 设置父类 | ||
enhancer.setSuperclass(Business.class); | ||
// 设置需要织入的逻辑 | ||
enhancer.setCallback(new LogIntercept()); | ||
//使用织入器创建子类 | ||
IBusiness2 newBusiness = (IBusiness2) enhancer.create(); | ||
newBusiness.dosomething2(); | ||
|
||
} | ||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...244932/learn01/src/main/java/com/dudy/learn01/base/aop/DynamicProxy/DynamicProxyDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.dudy.learn01.base.aop.DynamicProxy; | ||
import java.lang.reflect.Proxy; | ||
|
||
/** | ||
* Created by dudy on 2017/3/22. | ||
*/ | ||
public class DynamicProxyDemo { | ||
|
||
|
||
public static void main(String[] args) { | ||
|
||
// 需要代理的接口,被代理类实现的多个接口都必须放在这里 | ||
Class[] proxyInterface = new Class[]{IBusiness.class,IBusiness2.class}; | ||
// 构建AOP的Advice,这里需要传入业务类的实例 | ||
LogInvocationHandler handler = new LogInvocationHandler(new Business()); | ||
//生成代理类的字节码加载器 | ||
ClassLoader loader = DynamicProxyDemo.class.getClassLoader(); | ||
//织入器,织入代码并生成代理类 | ||
IBusiness2 proxyBusiness = (IBusiness2) Proxy.newProxyInstance(loader, proxyInterface, handler); | ||
|
||
proxyBusiness.dosomething2(); | ||
} | ||
|
||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...04/1796244932/learn01/src/main/java/com/dudy/learn01/base/aop/DynamicProxy/IBusiness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.dudy.learn01.base.aop.DynamicProxy; | ||
|
||
/** | ||
* Created by dudy on 2017/3/22. | ||
*/ | ||
public interface IBusiness { | ||
void dosomething(); | ||
} |
9 changes: 9 additions & 0 deletions
9
...4/1796244932/learn01/src/main/java/com/dudy/learn01/base/aop/DynamicProxy/IBusiness2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.dudy.learn01.base.aop.DynamicProxy; | ||
|
||
/** | ||
* Created by dudy on 2017/3/22. | ||
*/ | ||
public interface IBusiness2 { | ||
|
||
public void dosomething2(); | ||
} |
25 changes: 25 additions & 0 deletions
25
...1796244932/learn01/src/main/java/com/dudy/learn01/base/aop/DynamicProxy/LogIntercept.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.dudy.learn01.base.aop.DynamicProxy; | ||
|
||
import net.sf.cglib.proxy.Callback; | ||
import net.sf.cglib.proxy.MethodInterceptor; | ||
import net.sf.cglib.proxy.MethodProxy; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* Created by dudy on 2017/3/22. | ||
*/ | ||
public class LogIntercept implements MethodInterceptor { | ||
@Override | ||
public Object intercept(Object o, Method method, Object[] objects, MethodProxy proxy) throws Throwable { | ||
//执行原有的逻辑,注意这里是invokeSuper | ||
Object rev = proxy.invokeSuper(o, objects); | ||
//执行织入的日志 | ||
if (method.getName().equals("dosomething2")){ | ||
System.out.println("CGlib dosometing2....."); | ||
} | ||
|
||
|
||
return rev; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...32/learn01/src/main/java/com/dudy/learn01/base/aop/DynamicProxy/LogInvocationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.dudy.learn01.base.aop.DynamicProxy; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* Created by dudy on 2017/3/22. | ||
* 打印日志的切面 | ||
*/ | ||
public class LogInvocationHandler implements InvocationHandler{ | ||
|
||
private Object targer; //目标对象 | ||
|
||
public LogInvocationHandler(Object targer) { | ||
this.targer = targer; | ||
} | ||
|
||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
|
||
// 执行原有逻辑 | ||
Object rev = method.invoke(targer, args); | ||
// 执行织入的日志,你可以控制哪些哪些方法执行切入逻辑 | ||
if (method.getName().equals("dosomething2")){ | ||
System.out.println("记录日志"); | ||
} | ||
|
||
return rev; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
group04/1796244932/learn01/src/main/java/com/dudy/learn01/base/aop/node.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## AOP 实现机制 | ||
|
||
### AOP各种实现 | ||
aop就是面向切面编程, 可以从几个层面来实现AOP | ||
编译期 | ||
字节码加载前 | ||
字节码加载后 |
2 changes: 1 addition & 1 deletion
2
...com/dudy/learn01/juc/ThreadLocalTest.java → ...udy/learn01/base/juc/ThreadLocalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.dudy.learn01.juc; | ||
package com.dudy.learn01.base.juc; | ||
|
||
/** | ||
* Created by dudy on 2017/3/9. | ||
|
5 changes: 3 additions & 2 deletions
5
...dudy/learn01/download/DownloadThread.java → ...1/coderising/download/DownloadThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...dudy/learn01/download/api/Connection.java → ...1/coderising/download/api/Connection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...n01/download/api/ConnectionException.java → ...ing/download/api/ConnectionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...arn01/download/api/ConnectionManager.java → ...ising/download/api/ConnectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...earn01/download/api/DownloadListener.java → ...rising/download/api/DownloadListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
package com.dudy.learn01.download.api; | ||
|
||
package com.dudy.learn01.coderising.download.api; | ||
public interface DownloadListener { | ||
public void notifyFinished(); | ||
} |
5 changes: 3 additions & 2 deletions
5
...learn01/download/impl/ConnectionImpl.java → ...erising/download/impl/ConnectionImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
.../download/impl/ConnectionManagerImpl.java → .../download/impl/ConnectionManagerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.../1796244932/learn01/src/main/java/com/dudy/learn01/coderising/jvm/attr/AttributeInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.dudy.learn01.coderising.jvm.attr; | ||
|
||
public abstract class AttributeInfo { | ||
public static final String CODE = "Code"; | ||
public static final String CONST_VALUE = "ConstantValue"; | ||
public static final String EXCEPTIONS = "Exceptions"; | ||
public static final String LINE_NUM_TABLE = "LineNumberTable"; | ||
public static final String LOCAL_VAR_TABLE = "LocalVariableTable"; | ||
public static final String STACK_MAP_TABLE = "StackMapTable"; | ||
int attrNameIndex; | ||
int attrLen ; | ||
public AttributeInfo(int attrNameIndex, int attrLen) { | ||
|
||
this.attrNameIndex = attrNameIndex; | ||
this.attrLen = attrLen; | ||
} | ||
|
||
|
||
} |
69 changes: 69 additions & 0 deletions
69
group04/1796244932/learn01/src/main/java/com/dudy/learn01/coderising/jvm/attr/CodeAttr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.dudy.learn01.coderising.jvm.attr; | ||
|
||
|
||
import com.dudy.learn01.coderising.jvm.clz.ClassFile; | ||
import com.dudy.learn01.coderising.jvm.cmd.ByteCodeCommand; | ||
import com.dudy.learn01.coderising.jvm.constant.ConstantPool; | ||
import com.dudy.learn01.coderising.jvm.loader.ByteCodeIterator; | ||
|
||
public class CodeAttr extends AttributeInfo { | ||
private int maxStack ; | ||
private int maxLocals ; | ||
private int codeLen ; | ||
private String code; | ||
public String getCode() { | ||
return code; | ||
} | ||
|
||
private ByteCodeCommand[] cmds ; | ||
public ByteCodeCommand[] getCmds() { | ||
return cmds; | ||
} | ||
private LineNumberTable lineNumTable; | ||
private LocalVariableTable localVarTable; | ||
private StackMapTable stackMapTable; | ||
|
||
public CodeAttr(int attrNameIndex, int attrLen, int maxStack, int maxLocals, int codeLen,String code ,ByteCodeCommand[] cmds) { | ||
super(attrNameIndex, attrLen); | ||
this.maxStack = maxStack; | ||
this.maxLocals = maxLocals; | ||
this.codeLen = codeLen; | ||
this.code = code; | ||
this.cmds = cmds; | ||
} | ||
|
||
public void setLineNumberTable(LineNumberTable t) { | ||
this.lineNumTable = t; | ||
} | ||
|
||
public void setLocalVariableTable(LocalVariableTable t) { | ||
this.localVarTable = t; | ||
} | ||
|
||
public static CodeAttr parse(ClassFile clzFile, ByteCodeIterator iter){ | ||
|
||
return null; | ||
} | ||
|
||
|
||
public String toString(ConstantPool pool){ | ||
StringBuilder buffer = new StringBuilder(); | ||
//buffer.append("Code:").append(code).append("\n"); | ||
for(int i=0;i<cmds.length;i++){ | ||
buffer.append(cmds[i].toString(pool)).append("\n"); | ||
} | ||
buffer.append("\n"); | ||
buffer.append(this.lineNumTable.toString()); | ||
buffer.append(this.localVarTable.toString(pool)); | ||
return buffer.toString(); | ||
} | ||
private void setStackMapTable(StackMapTable t) { | ||
this.stackMapTable = t; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.