Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (6)
Tags (64)
master
nightly-master
release-6.3
dashboard
release
hooks
v8.0.1
v8.0.0
v8.0.0.rc2
v8.0.0.rc1
v7.1.1
v7.1.0
v7.1.0.rc2
v7.1.0.rc1
v7.0.0
v7.0.0.rc2
v7.0.0.rc1
v6.3.0
v6.3.0.rc2
v6.3.0-rc1
v6.3.0.rc1
v6.2.0
v6.2.0.rc1
v6.1.0
v6.1.0.rc2
v6.1.0.rc1
master
Branches (6)
Tags (64)
master
nightly-master
release-6.3
dashboard
release
hooks
v8.0.1
v8.0.0
v8.0.0.rc2
v8.0.0.rc1
v7.1.1
v7.1.0
v7.1.0.rc2
v7.1.0.rc1
v7.0.0
v7.0.0.rc2
v7.0.0.rc1
v6.3.0
v6.3.0.rc2
v6.3.0-rc1
v6.3.0.rc1
v6.2.0
v6.2.0.rc1
v6.1.0
v6.1.0.rc2
v6.1.0.rc1
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (6)
Tags (64)
master
nightly-master
release-6.3
dashboard
release
hooks
v8.0.1
v8.0.0
v8.0.0.rc2
v8.0.0.rc1
v7.1.1
v7.1.0
v7.1.0.rc2
v7.1.0.rc1
v7.0.0
v7.0.0.rc2
v7.0.0.rc1
v6.3.0
v6.3.0.rc2
v6.3.0-rc1
v6.3.0.rc1
v6.2.0
v6.2.0.rc1
v6.1.0
v6.1.0.rc2
v6.1.0.rc1
VTK
/
Wrapping
/
Java
/
vtk
/
vtkJavaMemoryManagerImpl.java
VTK
/
Wrapping
/
Java
/
vtk
/
vtkJavaMemoryManagerImpl.java
vtkJavaMemoryManagerImpl.java 4.77 KB
Copy Edit Raw Blame History
package vtk;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.TreeSet;
import java.util.concurrent.locks.ReentrantLock;
/**
* Provide a Java thread safe implementation of vtkJavaMemoryManager. This does
* not make VTK thread safe. This only insure that the change of reference count
* will never happen in two concurrent thread in the Java world.
*
* @see vtkJavaMemoryManager
* @author sebastien jourdain - sebastien.jourdain@kitware.com
*/
public class vtkJavaMemoryManagerImpl implements vtkJavaMemoryManager {
private vtkJavaGarbageCollector garbageCollector;
private ReentrantLock lock;
private vtkReferenceInformation lastGcResult;
private HashMap<Long, WeakReference<vtkObjectBase>> objectMap;
private HashMap<Long, String> objectMapClassName;
public vtkJavaMemoryManagerImpl() {
this.lock = new ReentrantLock();
this.objectMap = new HashMap<Long, WeakReference<vtkObjectBase>>();
this.objectMapClassName = new HashMap<Long, String>();
this.garbageCollector = new vtkJavaGarbageCollector();
}
// Thread safe
public vtkObjectBase getJavaObject(Long vtkId) {
// Check pre-condition
if (vtkId == null || vtkId.longValue() == 0) {
throw new RuntimeException("Invalid ID, can not be null or equal to 0.");
}
// Check inside the map if the object is already there
WeakReference<vtkObjectBase> value = objectMap.get(vtkId);
vtkObjectBase resultObject = (value == null) ? null : value.get();
// If not, we have to do something
if (value == null || resultObject == null) {
try {
// Make sure no concurrency could happen inside that
this.lock.lock();
// Now that we have the lock make sure someone else didn't
// create the object in between, if so just return the created
// instance
value = objectMap.get(vtkId);
resultObject = (value == null) ? null : value.get();
if (resultObject != null) {
return resultObject;
}
// We need to do the work of the gc
if (value != null && resultObject == null) {
this.unRegisterJavaObject(vtkId);
}
// No-one did create it, so let's do it
if (resultObject == null) {
try {
String className = vtkObjectBase.VTKGetClassNameFromReference(vtkId.longValue());
Class<?> c = Class.forName("vtk." + className);
Constructor<?> cons = c.getConstructor(new Class<?>[] { long.class });
resultObject = (vtkObjectBase) cons.newInstance(new Object[] { vtkId });
} catch (Exception e) {
e.printStackTrace();
}
}
} finally {
this.lock.unlock();
}
}
return resultObject;
}
// Thread safe
public void registerJavaObject(Long id, vtkObjectBase obj) {
try {
this.lock.lock();
this.objectMap.put(id, new WeakReference<vtkObjectBase>(obj));
this.objectMapClassName.put(id, obj.GetClassName());
} finally {
this.lock.unlock();
}
}
// Thread safe
public void unRegisterJavaObject(Long id) {
try {
this.lock.lock();
this.objectMapClassName.remove(id);
WeakReference<vtkObjectBase> value = this.objectMap.remove(id);
// Prevent double deletion...
if (value != null) {
vtkObjectBase.VTKDeleteReference(id.longValue());
} else {
throw new RuntimeException("You try to delete a vtkObject that is not referenced in the Java object Map. You may have call Delete() twice.");
}
} finally {
this.lock.unlock();
}
}
// Thread safe
public vtkReferenceInformation gc(boolean debug) {
System.gc();
try {
this.lock.lock();
final vtkReferenceInformation infos = new vtkReferenceInformation(debug);
for (Long id : new TreeSet<Long>(this.objectMap.keySet())) {
vtkObjectBase obj = this.objectMap.get(id).get();
if (obj == null) {
infos.addFreeObject(this.objectMapClassName.get(id));
this.unRegisterJavaObject(id);
} else {
infos.addKeptObject(this.objectMapClassName.get(id));
}
}
this.lastGcResult = infos;
return infos;
} finally {
this.lock.unlock();
}
}
public vtkJavaGarbageCollector getAutoGarbageCollector() {
return this.garbageCollector;
}
// Thread safe
public int deleteAll() {
int size = this.objectMap.size();
try {
this.lock.lock();
for (Long id : new TreeSet<Long>(this.objectMap.keySet())) {
this.unRegisterJavaObject(id);
}
} finally {
this.lock.unlock();
}
return size;
}
public int getSize() {
return objectMap.size();
}
public vtkReferenceInformation getLastReferenceInformation() {
return this.lastGcResult;
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Mirror of Visualization Toolkit repository
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/devstone/VTK.git
git@gitee.com:devstone/VTK.git
devstone
VTK
VTK
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /