进入Eden()->clean()函数

void EdenSpace::clear(bool mangle_space) {
ContiguousSpace::clear(mangle_space);
set_soft_end(end());
}

进入

void ContiguousSpace::clear(bool mangle_space) {
set_top(bottom());
set_saved_mark();
CompactibleSpace::clear(mangle_space);
}

打印对象,这个是eden

(gdb) p this
$154 = (EdenSpace * const) 0x7f4780020328
(gdb) p * this
$155 = (EdenSpace) {
<ContiguousSpace> = {
<CompactibleSpace> = {
<Space> = {
<CHeapObj<1280u>> = {
<AllocatedObj> = {
_vptr.AllocatedObj = 0x7f4788515a90 <vtable for EdenSpace+16>
}, <No data fields>},
members of Space:
_bottom = 0xf3800000,
_end = 0xf5600000,
_saved_mark_word = 0xf4dccdb8,
_preconsumptionDirtyCardClosure = 0x0,
_par_seq_tasks = {
<StackObj> = {
<AllocatedObj> = {
_vptr.AllocatedObj = 0x7f47884fb650 <vtable for SequentialSubTasksDone+16>
}, <No data fields>},
members of SequentialSubTasksDone:
_n_tasks = 0,
_n_claimed = 0,
_n_threads = 0,
_n_completed = 0
}
},
members of CompactibleSpace:
_compaction_top = 0xf3800000,
_next_compaction_space = 0x7f4780020438,
_first_dead = 0xf1f1f1f1f1f1f1f1,
_end_of_live = 0xf1f1f1f1f1f1f1f1
},
members of ContiguousSpace:
_top = 0xf4dccdb8,
_concurrent_iteration_safe_limit = 0xf3800000,
_mangler = 0x7f47800203e8
},
members of EdenSpace:
_gen = 0x7f478001f1c8,
_soft_end = 0xf5600000
}

看实现

(gdb) p bottom()
$156 = (HeapWord *) 0xf3800000
(gdb) p top()
$157 = (HeapWord *) 0xf4dccdb8

将top清空

设置mark

 virtual void set_saved_mark()    { _saved_mark_word = top();    }

清理完之后的对象

(gdb) p *this
$159 = (EdenSpace) {
<ContiguousSpace> = {
<CompactibleSpace> = {
<Space> = {
<CHeapObj<1280u>> = {
<AllocatedObj> = {
_vptr.AllocatedObj = 0x7f4788515a90 <vtable for EdenSpace+16>
}, <No data fields>},
members of Space:
_bottom = 0xf3800000,
_end = 0xf5600000,
_saved_mark_word = 0xf3800000,
_preconsumptionDirtyCardClosure = 0x0,
_par_seq_tasks = {
<StackObj> = {
<AllocatedObj> = {
_vptr.AllocatedObj = 0x7f47884fb650 <vtable for SequentialSubTasksDone+16>
}, <No data fields>},
members of SequentialSubTasksDone:
_n_tasks = 0,
_n_claimed = 0,
_n_threads = 0,
_n_completed = 0
}
},
members of CompactibleSpace:
_compaction_top = 0xf3800000,
_next_compaction_space = 0x7f4780020438,
_first_dead = 0xf1f1f1f1f1f1f1f1,
_end_of_live = 0xf1f1f1f1f1f1f1f1
},
members of ContiguousSpace:
_top = 0xf3800000,
_concurrent_iteration_safe_limit = 0xf3800000,
_mangler = 0x7f47800203e8
},
members of EdenSpace:
_gen = 0x7f478001f1c8,
_soft_end = 0xf5600000
}

接着看

CompactibleSpace::clear(mangle_space);
----------------------------------------------
void CompactibleSpace::clear(bool mangle_space) {
Space::clear(mangle_space);
_compaction_top = bottom();
}
----------------------------------------------
void Space::clear(bool mangle_space) {
if (ZapUnusedHeapArea && mangle_space) {
mangle_unused_area();
}
} -------------------------------------------------
void ContiguousSpace::mangle_unused_area() {
mangler()->mangle_unused_area();
}
-----------------------------------------------------
void SpaceMangler::mangle_unused_area() {
assert(ZapUnusedHeapArea, "Mangling should not be in use");
// Mangle between top and the high water mark. Safeguard
// against the space changing since top_for_allocations was
// set.
HeapWord* mangled_end = MIN2(top_for_allocations(), end());
if (top() < mangled_end) {
MemRegion mangle_mr(top(), mangled_end);
SpaceMangler::mangle_region(mangle_mr);
// Light weight check of mangling.
check_mangled_unused_area(end());
}
// Complete check of unused area which is functional when
// DEBUG_MANGLING is defined.
check_mangled_unused_area_complete();
}

打印这个spaceMangler对象

(gdb) p _mangler
$162 = (GenSpaceMangler *) 0x7f47800203e8
(gdb) p *_mangler
$163 = (GenSpaceMangler) {
<SpaceMangler> = {
<CHeapObj<1280u>> = {
<AllocatedObj> = {
_vptr.AllocatedObj = 0x7f47885163d0 <vtable for GenSpaceMangler+16>
}, <No data fields>},
members of SpaceMangler:
_top_for_allocations = 0xf4dccdb8
},
members of GenSpaceMangler:
_sp = 0x7f4780020328
}

查看紫色函数

(gdb) p end()
$164 = (HeapWord *) 0xf5600000
(gdb) p _top_for_allocations
$165 = (HeapWord *) 0xf4dccdb8

进入棕色函数

// Simply mangle the MemRegion mr.
void SpaceMangler::mangle_region(MemRegion mr) {
assert(ZapUnusedHeapArea, "Mangling should not be in use");
#ifdef ASSERT
if(TraceZapUnusedHeapArea) {
gclog_or_tty->print("Mangling [0x%x to 0x%x)", mr.start(), mr.end());
}
Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord);
if(TraceZapUnusedHeapArea) {
gclog_or_tty->print_cr(" done");
}
#endif
}

进入函数

  // Fill methods

  // Fill word-aligned words, not atomic on each word
// set_words
static void fill_to_words(HeapWord* to, size_t count, juint value = 0) {
assert_params_ok(to, LogHeapWordSize);
pd_fill_to_words(to, count, value);
}

进入

static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
#ifdef AMD64
julong* to = (julong*) tohw;
julong v = ((julong) value << 32) | value;
while (count-- > 0) {
*to++ = v;
}
#else..无用..
#endif // AMD64
}

看badHeapWord的值

(gdb) p/x value
$171 = 0xbaadbabe

那么上述过程就是将heap的值全部设置成了0xbaadbabe

接着就是对from区域

(gdb) p from()
$175 = (ContiguousSpace *) 0x7f4780020438

重要的交换空间

    swap_spaces();

交换之前

(gdb) p this
$181 = (DefNewGeneration * const) 0x7f478001f1c8
(gdb) p* this
$182 = (DefNewGeneration) {
<Generation> = {
<CHeapObj<1280u>> = {
<AllocatedObj> = {
_vptr.AllocatedObj = 0x7f47884ff590 <vtable for DefNewGeneration+16>
}, <No data fields>},
members of Generation:
_time_of_last_gc = -1012762419733073423,
_prev_used_region = {
_start = 0x0,
_word_size = 0
},
_reserved = {
_start = 0xf3800000,
_word_size = 6553600
},
....略部分
_promo_failure_drain_in_progress = false,
_gen_counters = 0x7f4780020638,
_eden_counters = 0x7f478000d678,
_from_counters = 0x7f4780021888,
_to_counters = 0x7f4780021d78,
_max_eden_size = 31457280,
_max_survivor_size = 10485760,
_should_allocate_from_space = false,
_eden_space = 0x7f4780020328,
_from_space = 0x7f4780020438,
_to_space = 0x7f4780020538,
_gc_timer = 0x7f4780022268
}

代码为

void DefNewGeneration::swap_spaces() {
ContiguousSpace* s = from();
_from_space = to();
_to_space = s;
eden()->set_next_compaction_space(from());
// The to-space is normally empty before a compaction so need
// not be considered. The exception is during promotion
// failure handling when to-space can contain live objects.
from()->set_next_compaction_space(NULL); if (UsePerfData) {
CSpaceCounters* c = _from_counters;
_from_counters = _to_counters;
_to_counters = c;
}
}

这个函数为  eden()->set_next_compaction_space(from());

  void set_next_compaction_space(CompactibleSpace* csp) {
_next_compaction_space = csp;
}

将eden()的值设置为新的from值,(即原来的from空间已经变为了to空间)

  if (UsePerfData) {
CSpaceCounters* c = _from_counters;
_from_counters = _to_counters;
_to_counters = c;
}

设置完成后就结束了

jvm源码解读--14 defNewGeneration.cpp gc标记复制之后,进行空间清理的更多相关文章

  1. JVM 源码解读之 CMS 何时会进行 Full GC

    t点击上方"涤生的博客",关注我 转载请注明原创出处,谢谢!如果读完觉得有收获的话,欢迎点赞加关注. 前言 本文内容是基于 JDK 8 在文章 JVM 源码解读之 CMS GC 触 ...

  2. jvm源码解读--17 Java的wait()、notify()学习

    write and debug by 张艳涛 wait()和notify()的通常用法 A线程取得锁,执行wait(),释放锁; B线程取得锁,完成业务后执行notify(),再释放锁; B线程释放锁 ...

  3. jvm源码解读--08 创建oop对象,将static静态变量放置在oop的96 offset处

    之前分析的已经加载的.Class文件中都没有Static 静态变量,所以也就没这部分的解析,自己也是不懂hotspot 将静态变量放哪里去了,追踪源码之后,看清楚了整个套路,总体上来说,可以举例来说对 ...

  4. jvm源码解读--13 gc_root中的栈中oop的mark 和copy 过程分析

    粘贴源码 package com.test; import java.util.Random; public class Test { static int number=12; private in ...

  5. jvm源码解读--11 ldc指令的解读

    写一个java文件 public static void main(String[] args) { String str1="abc"; String str2 ="a ...

  6. jvm源码解读--10 enum WKID 枚举

    源码中对于枚举类型WKID的使用 static bool initialize_wk_klass(WKID id, int init_opt, TRAPS); static void initiali ...

  7. jvm源码解读--16 cas 用法解析

    CAS的意思是campare and sweep比较交换 这个如果不用代码会比较抽象,那么在源码中进行解释 void ATTR ObjectMonitor::enter(TRAPS) { // The ...

  8. jvm源码解读--06 Method 方法解析

    进入 // Methods bool has_final_method = false; AccessFlags promoted_flags; promoted_flags.set_flags(0) ...

  9. jvm源码解读--15 oop对象详解

    (gdb) p obj $15 = (oopDesc *) 0xf3885d08 (gdb) p * obj $16 = { _mark = 0x70dea4e01, _metadata = { _k ...

随机推荐

  1. 【C++】共用体\联合体(union)

    共用体的用法与结构体差不多,只不过将关键字由struct变成了union.共用体使不同的类型变量存放到同一段内存单元中,所以共用体在同一时刻只能存储一个数据成员的值,共用体的大小等于最大成员的大小(结 ...

  2. 为什么Mongodb索引用B树,而Mysql用B+树?

    引言 好久没写文章了,今天回来重操旧业. 今天讲的这个主题,是<面试官:谈谈你对mysql索引的认识>,里头提到的一个坑. 也就是说,如果面试官问的是,为什么Mysql中Innodb的索引 ...

  3. 排查bug:竟然是同事把Redis用成这鬼样子,坑了我

    首先说下问题现象:内网sandbox环境API持续1周出现应用卡死,所有api无响应现象 刚开始当测试抱怨环境响应慢的时候 ,我们重启一下应用,应用恢复正常,于是没做处理.但是后来问题出现频率越来越频 ...

  4. 【codeforces841A】Generous Kefa

    原题 A. Generous Kefatime limit per test:2 secondsmemory limit per test:256 megabytes input:standard i ...

  5. 管理后台Vue

    管理后台 遇到的问题 搭建 基于vue 3.0 Vue CLI 4.x Ant Design Vue 2.0 搭建后台管理系统 Ant Design Vue 2.0 npm i --save ant- ...

  6. 精通Proteus仿真器件制作(3)DLL仿真模型创建

    有些人可能会想:什么叫做"DLL仿真模型之原理图符号"?我想学高级的C++创建DLL(动态链接库)仿真模型的方式,你别拦着我,不然,我可就人挡Kill人,佛挡Kill佛啦!原理图符 ...

  7. Weblogic下的servlet内存马注入-无参照纯调试

    目录 1.寻找servlet注入方法 1.1 调试 1.2 servletMapping添加servlet 2.获取request 2.1 从当前线程寻找信息 2.2 JNDI注入到内存马注入 3.关 ...

  8. 阿里P7大佬带你解密Sentinel

    概述 在接连写了两篇关于限流的文章(<面试补习>- 你来说说什么是限流?, 限流神器Sentinel,不了解一下吗?)后,总感觉还差最后一点内容来闭环整个限流相关的内容,这两天在翻查相关文 ...

  9. ESCMScript(2)Module语法

    严格模式 ES6 的模块自动采用严格模式,不管你有没有在模块头部加上"use strict";. 严格模式的限制如下 变量必须声明后再使用 函数的参数不能有同名属性,否则报错 不能 ...

  10. 互联网时代CRM软件帮助企业销售升级

    随着信息技术的发展,互联网+的浪潮逐渐改变了我们的生活.对于企业来说,他们的管理模式和服务模式也需要作出改变,企业不再满足只进行内部业务的优化和管理,传统CRM开始不再符合企业的需求.由此可见,在网络 ...