当前位置:网站首页>Implementation of hotspot reference
Implementation of hotspot reference
2022-06-12 09:19:00 【symop】
One .referencePolicy
share.vm.memory.referencePolicy Is used for java.lang.SoftReference Instance cleanup .should_clear_reference Method parameters p Refer to SoftReference object .
class ReferencePolicy : public CHeapObj<mtGC> {
public:
virtual bool should_clear_reference(oop p, jlong timestamp_clock) {
ShouldNotReachHere();
return true;
}
// Capture state (of-the-VM) information needed to evaluate the policy
virtual void setup() { /* do nothing */ }
};
should_clear_reference Method to determine whether a soft reference object needs to be cleaned up ,ReferencePolicy Parent class , There are four subclasses , Namely
class NeverClearPolicy : public ReferencePolicy {
public:
virtual bool should_clear_reference(oop p, jlong timestamp_clock) {
return false;
}
};
class AlwaysClearPolicy : public ReferencePolicy {
public:
virtual bool should_clear_reference(oop p, jlong timestamp_clock) {
return true;
}
};
class LRUCurrentHeapPolicy : public ReferencePolicy {
private:
jlong _max_interval;
public:
LRUCurrentHeapPolicy();
void setup();
virtual bool should_clear_reference(oop p, jlong timestamp_clock);
};
class LRUMaxHeapPolicy : public ReferencePolicy {
private:
jlong _max_interval;
public:
LRUMaxHeapPolicy();
// Capture state (of-the-VM) information needed to evaluate the policy
void setup();
virtual bool should_clear_reference(oop p, jlong timestamp_clock);
};
NeverClearPolicy should_clear_reference Method directly returns false,AlwaysClearPolicy should_clear_reference Method directly returns true.
The main explanation is LRUCurrentHeapPolicy and LRUMaxHeapPolicy.LRUMaxHeapPolicy Using the largest amount of free space MB Count ,LRUCurrentHeapPolicy Using the free space of the current heap MB Count .
LRUCurrentHeapPolicy::LRUCurrentHeapPolicy() {
setup();
}
// Capture state (of-the-VM) information needed to evaluate the policy
void LRUCurrentHeapPolicy::setup() {
// The current heap is the largest free MB Count ,SoftRefLRUPolicyMSPerMB each 1M Free space can be maintained SoftReference The length of time an object will survive , The default value is 1000
_max_interval = (Universe::get_heap_free_at_last_gc() / M) * SoftRefLRUPolicyMSPerMB;
assert(_max_interval >= 0,"Sanity check");
}
// The oop passed in is the SoftReference object, and not
// the object the SoftReference points to.
bool LRUCurrentHeapPolicy::should_clear_reference(oop p,
jlong timestamp_clock) {
//timestamp Method returns SoftReference Class timestamp attribute , This property is called every time get Method to get the soft reference object will be updated to a clock
jlong interval = timestamp_clock - java_lang_ref_SoftReference::timestamp(p);
assert(interval >= 0, "Sanity check");
// The interval will be zero if the ref was accessed since the last scavenge/gc.
if(interval <= _max_interval) {
return false;
}
return true;
}
/// MaxHeap //
LRUMaxHeapPolicy::LRUMaxHeapPolicy() {
setup();
}
// Capture state (of-the-VM) information needed to evaluate the policy
void LRUMaxHeapPolicy::setup() {
size_t max_heap = MaxHeapSize;
// Of the current remaining free space MB Count
max_heap -= Universe::get_heap_used_at_last_gc();
max_heap /= M;
_max_interval = max_heap * SoftRefLRUPolicyMSPerMB;
assert(_max_interval >= 0,"Sanity check");
}
// The oop passed in is the SoftReference object, and not
// the object the SoftReference points to.
bool LRUMaxHeapPolicy::should_clear_reference(oop p,
jlong timestamp_clock) {
//timestamp Method returns SoftReference Class timestamp attribute , This property is called every time get Method to get the soft reference object will be updated to a clock
jlong interval = timestamp_clock - java_lang_ref_SoftReference::timestamp(p);
assert(interval >= 0, "Sanity check");
// The interval will be zero if the ref was accessed since the last scavenge/gc.
if(interval <= _max_interval) {
return false;
}
return true;
}
2.referenceProcessor
reference processor ,referenceProcessor.hpp in DiscoveredList Is stored Reference The linked list of ,DiscoveredListIterator Is traversal DiscoveredList The iterator .
referenceProcessor.cpp in process_discovered_references The method is actually used to handle the different types of DiscoveredList Medium Reference example , The underlying actual call process_discovered_reflist( Handling strong references ) and process_phaseJNI Method ( Deal with weak quotes ), Respectively in gc After the call , Here's the picture .
Specific methods are not analyzed , Because I won't .
边栏推荐
- Unittest测试框架
- Four steps for sending rockertmq producer messages
- Basic knowledge of Linear Algebra -- concepts and relationships of common matrices
- Quick sort
- What are the software testing requirements analysis methods? Let's have a look
- SQL basic syntax II
- Filters and listeners
- Load the source code of 2D 3D virtual anchor in the web page (1: project introduction and source code)
- 软件测试面试官问这些问题的背后意义你知道吗?
- Unittest test framework
猜你喜欢
What are the software testing requirements analysis methods? Let's have a look
![Sword finger offer:[day 9 dynamic planning (medium)] --- > maximum sum of continuous subarrays](/img/6b/6dcc86bfe0f48103ef8420b9996c1e.jpg)
Sword finger offer:[day 9 dynamic planning (medium)] --- > maximum sum of continuous subarrays
Test case and bug description specification reference

More than 90% of the software companies will ask the software test interview questions. Hurry to recite them

After receiving the picture, caigou was very happy and played with PDF. The submission format was flag{xxx}, and the decryption characters should be in lowercase
软件测试基础知识分享,写点你不知道的

The database doesn't know what went wrong
软件测试报告中常见的疏漏,给自己提个醒

Distributed transactions - Theoretical Overview

Tool classes for extracting zip files
随机推荐
MySQL learning record - II. MySQL create table command
Subtractive integer (number theory)
Technology cloud report: how will the industrial Internet rebuild the security boundary in 2022?
MFS explanation (IV) -- MFS management server installation and configuration
抓取屏幕与毛玻璃效果
Diff prime pairs
mySql学习记录——三、mysql查询语句
top命令含义
Flink CheckPoint : Exceeded checkpoint tolerable failure threshold
Share the basic knowledge of software testing and write something you don't know
Latex common symbols summary
The classic dog contract of smart contract (I)
ABC253F Operations on a Matrix
软件测试报告中常见的疏漏,给自己提个醒
Visualization of two-dimensional feature logistic regression prediction results
功能测试面试常见的技术问题,总结好了你不看?
Unittest test framework
Semaphore flow control semaphore
Thread deadlock and its solution
Swagger documentation details