forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 13
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 #56 from cmhello88/master
删掉多余的test文件
- Loading branch information
Showing
45 changed files
with
2,308 additions
and
2 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
68 changes: 68 additions & 0 deletions
68
group03/345943980/mini-jvm-0330/src/main/java/com/coderising/jvm/loader/ClassFileLoader.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,68 @@ | ||
package com.coderising.jvm.loader; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class ClassFileLoader { | ||
|
||
private List<String> clzPaths = new ArrayList<String>(); | ||
|
||
public byte[] readBinaryCode(String className) { | ||
className = className.replace(".", File.separator) + ".class"; | ||
for (String path : clzPaths) { | ||
String clzFileName = path + File.separator + className; | ||
byte[] codes = this.loadClassFile(clzFileName); | ||
if (codes != null) { | ||
return codes; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private byte[] loadClassFile(String clzFileName){ | ||
try { | ||
return IOUtils.toByteArray(new FileInputStream(clzFileName)); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
public void addClassPath(String path) { | ||
clzPaths.add(path); | ||
} | ||
|
||
public String getClassPath() { | ||
return StringUtils.join(clzPaths, ";"); | ||
} | ||
|
||
public String getClassPath_V1() { | ||
StringBuffer sb = new StringBuffer(); | ||
/* | ||
* for (int i = 0; i < clzPaths.size(); i++) | ||
{ | ||
if (i == clzPaths.size() - 1) { | ||
sb.append(clzPaths.get(i)); | ||
break; | ||
} | ||
sb.append(clzPaths.get(i)); | ||
sb.append(";"); | ||
* | ||
* } | ||
*/ | ||
for (int i = 0; i < clzPaths.size(); i++) { | ||
sb.append(clzPaths.get(i)); | ||
if (i < clzPaths.size() - 1) { | ||
sb.append(";"); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
group03/345943980/mini-jvm-0330/src/main/java/com/coding/basic/linklist/CmLRUPageFrame.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.coding.basic.linklist; | ||
|
||
/** | ||
* | ||
* @author chenming E-mail:[email protected] | ||
* @version 创建时间:2017年4月10日 上午12:35:03 | ||
*/ | ||
public class CmLRUPageFrame { | ||
|
||
private static class Node { | ||
Node prev; | ||
Node next; | ||
int pageNum; | ||
|
||
Node() { | ||
} | ||
} | ||
|
||
private int capacity; | ||
|
||
private Node first;// 链表头 | ||
private Node last;// 链表尾 | ||
|
||
public CmLRUPageFrame(int capacity) { | ||
this.capacity = capacity; | ||
|
||
} | ||
|
||
/** | ||
* 获取缓存中对象 | ||
* | ||
* @param pageNum | ||
*/ | ||
public void access(int pageNum) { | ||
Node node = first; | ||
Node foundNode = null; | ||
while(node!=null){ | ||
if(node.pageNum==pageNum){ | ||
foundNode = node; | ||
} | ||
node = node.next; | ||
} | ||
|
||
//在该队列中存在, 则提到队列头 | ||
if(foundNode!=null){ | ||
|
||
}else{ | ||
|
||
} | ||
|
||
|
||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder buffer = new StringBuilder(); | ||
Node node = first; | ||
while (node != null) { | ||
buffer.append(node.pageNum); | ||
node = node.next; | ||
if (node != null) { | ||
buffer.append(";"); | ||
} | ||
} | ||
return buffer.toString(); | ||
} | ||
|
||
} |
163 changes: 163 additions & 0 deletions
163
group03/345943980/mini-jvm-0330/src/main/java/com/coding/basic/linklist/LRUPageFrame.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,163 @@ | ||
package com.coding.basic.linklist; | ||
|
||
|
||
/** | ||
* 实现一个简单的LRU算法,即是 Least Recently Used 近期最少使用算法 | ||
* 作用:需要维护一个页面中的栈,并且需要把某一个页面从栈中提到栈顶,用硬件实现的话,开销比较大,注意:实际上并不是一个真正的栈 | ||
* @author Administrator | ||
* | ||
*/ | ||
public class LRUPageFrame { | ||
|
||
private static class Node { | ||
|
||
Node prev; | ||
Node next; | ||
int pageNum; | ||
|
||
Node() { | ||
} | ||
} | ||
|
||
private int capacity; | ||
|
||
private int currentSize; | ||
private Node first;// 链表头 | ||
private Node last;// 链表尾 | ||
|
||
|
||
public LRUPageFrame(int capacity) { | ||
this.currentSize = 0; | ||
this.capacity = capacity; | ||
|
||
} | ||
|
||
/** | ||
* 获取缓存中对象 | ||
* | ||
* @param key | ||
* @return | ||
*/ | ||
public void access(int pageNum) { | ||
|
||
Node node = find(pageNum); | ||
//在该队列中存在, 则提到队列头 | ||
if (node != null) { | ||
|
||
moveExistingNodeToHead(node); | ||
|
||
} else{ | ||
|
||
node = new Node(); | ||
node.pageNum = pageNum; | ||
|
||
// 缓存容器是否已经超过大小. | ||
if (currentSize >= capacity) { | ||
removeLast(); | ||
|
||
} | ||
|
||
addNewNodetoHead(node); | ||
|
||
|
||
|
||
|
||
} | ||
} | ||
|
||
private void addNewNodetoHead(Node node) { | ||
|
||
if(isEmpty()){ | ||
|
||
node.prev = null; | ||
node.next = null; | ||
first = node; | ||
last = node; | ||
|
||
} else{ | ||
node.prev = null; | ||
node.next = first; | ||
first.prev = node; | ||
first = node; | ||
} | ||
this.currentSize ++; | ||
} | ||
|
||
private Node find(int data){ | ||
|
||
Node node = first; | ||
while(node != null){ | ||
if(node.pageNum == data){ | ||
return node; | ||
} | ||
node = node.next; | ||
} | ||
return null; | ||
|
||
} | ||
|
||
|
||
/** | ||
* 删除链表尾部节点 表示 删除最少使用的缓存对象 | ||
*/ | ||
private void removeLast() { | ||
Node prev = last.prev; | ||
prev.next = null; | ||
last.prev = null; | ||
last = prev; | ||
this.currentSize --; | ||
} | ||
|
||
/** | ||
* 移动到链表头,表示这个节点是最新使用过的 | ||
* | ||
* @param node | ||
*/ | ||
private void moveExistingNodeToHead(Node node) { | ||
|
||
if (node == first) { | ||
|
||
return; | ||
} | ||
else if(node == last){ | ||
//当前节点是链表尾, 需要放到链表头 | ||
Node prevNode = node.prev; | ||
prevNode.next = null; | ||
last.prev = null; | ||
last = prevNode; | ||
|
||
} else{ | ||
//node 在链表的中间, 把node 的前后节点连接起来 | ||
Node prevNode = node.prev; | ||
prevNode.next = node.next; | ||
|
||
Node nextNode = node.next; | ||
nextNode.prev = prevNode; | ||
|
||
|
||
} | ||
|
||
node.prev = null; | ||
node.next = first; | ||
first.prev = node; | ||
first = node; | ||
|
||
} | ||
private boolean isEmpty(){ | ||
return (first == null) && (last == null); | ||
} | ||
|
||
public String toString(){ | ||
StringBuilder buffer = new StringBuilder(); | ||
Node node = first; | ||
while(node != null){ | ||
buffer.append(node.pageNum); | ||
|
||
node = node.next; | ||
if(node != null){ | ||
buffer.append(","); | ||
} | ||
} | ||
return buffer.toString(); | ||
} | ||
} |
Oops, something went wrong.