由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Where does Java Store Static Variable?
相关主题
basic java question求教:Facade Pattern vs Static Variable
static getInstance()JAVA 求解
Singleton vs. static class?Converge of languages and design pattern
thread safe Singleton 的几种方法?OutofMemoryError: Java Heap Space
一个关于generics的问题今天被老印grill了
Suggestion Re: 发现 synchronized 的一个问题loaded classes 问题
anyone saw this on code?Java Object 一定在 Heap 里吗
自己管理session要每次手动释放么Re: about promotion (question from novice)
相关话题的讨论汇总
话题: permgen话题: stored话题: static话题: variable话题: singleton
进入Java版参与讨论
1 (共1页)
r*****l
发帖数: 2859
1
I got conflicting answers online. I think it should be stored in permgen
space since the variable is part of the class definition.
What's your opinion?
g**e
发帖数: 6127
2
vote for permgen

【在 r*****l 的大作中提到】
: I got conflicting answers online. I think it should be stored in permgen
: space since the variable is part of the class definition.
: What's your opinion?

b******y
发帖数: 9224
3
I did some research. It seems to me that static variables, if they are
primitives, are stored in permgen, also object references.
Objects could be allocated in any heap.
r*****l
发帖数: 2859
4
This is inline with what I thought. Thanks.
Now there is something more interesting. If I have a class Singleton, look
at the code below:
private static final Singleton instance_ = new Singleton();
Suppose reference to the Singleton class (value of "instance_") is stored in
permgen, then what about the Singleton object. It has the same life cycle
as instance_ so it makes sense to store it in permgen. However, I do believe
they will be stored in normal heap (finally tenured) cause otherwise the
permgen may become very congested with normal objects there.

【在 b******y 的大作中提到】
: I did some research. It seems to me that static variables, if they are
: primitives, are stored in permgen, also object references.
: Objects could be allocated in any heap.

g**e
发帖数: 6127
5
Storing the object in heap makes sense. But a full collection will clean
perm gen too.

in
believe

【在 r*****l 的大作中提到】
: This is inline with what I thought. Thanks.
: Now there is something more interesting. If I have a class Singleton, look
: at the code below:
: private static final Singleton instance_ = new Singleton();
: Suppose reference to the Singleton class (value of "instance_") is stored in
: permgen, then what about the Singleton object. It has the same life cycle
: as instance_ so it makes sense to store it in permgen. However, I do believe
: they will be stored in normal heap (finally tenured) cause otherwise the
: permgen may become very congested with normal objects there.

r*****l
发帖数: 2859
6
I know that but generally permgen size is quite small compared to normal
heap so it makes sense to store as less data as possible.

【在 g**e 的大作中提到】
: Storing the object in heap makes sense. But a full collection will clean
: perm gen too.
:
: in
: believe

r*****l
发帖数: 2859
7
Although my understanding is like yours, I have not found concrete evidence
to support this. Do you have a link?

【在 b******y 的大作中提到】
: I did some research. It seems to me that static variables, if they are
: primitives, are stored in permgen, also object references.
: Objects could be allocated in any heap.

g**e
发帖数: 6127
8
不一定呀,如果有的程序需要大量操作字符串,perm gen还是需要适当调整一下的

【在 r*****l 的大作中提到】
: I know that but generally permgen size is quite small compared to normal
: heap so it makes sense to store as less data as possible.

r*****l
发帖数: 2859
9
In normal case, production system may have >1.5G Xmx. And 256M PermSize is
large enough.
This is always case by case however.

【在 g**e 的大作中提到】
: 不一定呀,如果有的程序需要大量操作字符串,perm gen还是需要适当调整一下的
b******y
发帖数: 9224
10

evidence
Sorry, no.
I read several sites online, but none of the sites could give definitive
answer. I guess it is just per VM implementation maybe.
But, your question about the "dangling" reference in the permgen sounds
interesting I guess maybe the java vm has some way to keep track of that?
I guess what I would do in that case, before garbage collect any object from
the heap, I would check if that object is referenced by any from the
permgen.
Maybe a question for Oracle ;-)

【在 r*****l 的大作中提到】
: Although my understanding is like yours, I have not found concrete evidence
: to support this. Do you have a link?

r*****l
发帖数: 2859
11
Read the JVM Specs. All field metadata is stored in the permgen (method area
). Static variable each has a reference to a ConstanceValue data structure,
also in permgen. The value can be of type long, float, double, int (short,
char, etc.), and string. The Specs does not specify how a object reference
is stored (or at least I did not find it). Maybe it's like this: if the type
of the field is not primitive, then the value stored in the ConstantValue
data structure is interpreted as an object reference?

from

【在 b******y 的大作中提到】
:
: evidence
: Sorry, no.
: I read several sites online, but none of the sites could give definitive
: answer. I guess it is just per VM implementation maybe.
: But, your question about the "dangling" reference in the permgen sounds
: interesting I guess maybe the java vm has some way to keep track of that?
: I guess what I would do in that case, before garbage collect any object from
: the heap, I would check if that object is referenced by any from the
: permgen.

k******p
发帖数: 21
12
perm generation as part of meta data of classes, methods.
r*****l
发帖数: 2859
13
This is too vague and most people know it.
My two specific questions are:
1, If static variable is stored in permgen
2, Proof whether the answer is yes or no.

【在 k******p 的大作中提到】
: perm generation as part of meta data of classes, methods.
1 (共1页)
进入Java版参与讨论
相关主题
Re: about promotion (question from novice)一个关于generics的问题
Urgent!Suggestion Re: 发现 synchronized 的一个问题
Help Cookie getMaxAge() always return -1anyone saw this on code?
急问:weblogic 高手自己管理session要每次手动释放么
basic java question求教:Facade Pattern vs Static Variable
static getInstance()JAVA 求解
Singleton vs. static class?Converge of languages and design pattern
thread safe Singleton 的几种方法?OutofMemoryError: Java Heap Space
相关话题的讨论汇总
话题: permgen话题: stored话题: static话题: variable话题: singleton