复制法中:
Eden :
from :
to :
space_require :需要分配的空间
.rest 剩余的空间
.put() 放入
.size 占据空间大小
history_space_array : 每次今生到老年代的空间大小
if( space_require < Eden.rest){
Eden.put(space_require)
}else if(space_require < from.require){
from.put(space_require)
}else{
#history_space_array : 每次今生到老年代的空间大小
if(history_space_array.average > old.rest){
if(HandlePromotionFailure is allowed){//允许担保失败
MinorGC_允许担保失败();
}else{
FullGC();
if( space_require < Eden.rest){
Eden.put(space_require)
}else if(space_require < from.require){
from.put(space_require)
}else{
if(old.rest > alive.space){
old.put(alive);
}else{
throws new OutOfMemoryException();
}
}
}else{
MinorGC();
}
}
MinorGC(){
alive = Eden.alive + from.alive
for(object in alive){
object.age++;
if(object.age>=limitAge){
if(old.rest > object.space ){
old.put(alive);//
}else{
throw OOMException();
}
}else if(object.size < to.rest){
to.put(object)
}else if(old.rest > object.space ){
old.put(alive);//
}else{
throw OOMException();
}
}
Eden.clear()
from.clear()
from,to= to,from; //二者交换
}
}
MinorGC_允许担保失败(){
//alive存活的对象
alive = Eden.alive + from.alive
for(object in alive){
object.age++;
if(object.age>=limitAge){
if(old.rest > object.space ){
old.put(alive);//
}else{
MinorGC2FullGC();
}
}else if(object.size < to.rest){
to.put(object)
}else if(old.rest > object.space ){
old.put(alive);//
}else{
MinorGC2FullGC();
}
}
Eden.clear()
from.clear()
from,to= to,from; //二者交换
}
MinorGC2FullGC(){
FullGC();//此时发生一次全GC
if(old.rest > object.space){
old.put(alive);
}else{
throws new OutOfMemoryException();
}
}