Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对第49页,小标题:1.如何判断TLAB满了有点疑惑。 #4

Closed
justdingqh opened this issue Apr 4, 2020 · 1 comment
Closed

Comments

@justdingqh
Copy link

1,书中写到,当请求对象大于refill_waste时会选择在堆中分配,请问这个堆具体是指的什么,是TLAB吗?
2,当一个1MB的TLAB使用16K,还剩1008K时,为什么内存是直接分配一个新的TLAB,那这1008K的空间岂不是浪费了。个人觉得是否应该是如果新的对象小于refill_waste则继续使用TLAB,否则分配一个新的?

@chenghanpeng
Copy link
Owner

TLAB其实就是从堆中拿到,你可以参考书中的图理解,简单的说多个线程都从heap中取一块空间,这个空间就是TLAB,每个TLAB都不会重叠,所以线程可以无锁分配。当使用TLAB的时候,JVM要考虑内存的浪费(也就是TLAB),当发现TLAB不能满足请求的对象大小,这就涉及到一个问题:是把当前的TLAB直接认为满了,还是新分配一个新的TLAB来进行无锁的分配?如果直接认为满了,则进行填充;如果认为存在浪费,则直接把对象分配在heap中,因为涉及到多线程,所以此时分配要进行加锁。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants