[Java] JVM Runtime Data Area

Gยท2024๋…„ 6์›” 22์ผ
0

Java

๋ชฉ๋ก ๋ณด๊ธฐ
3/21
post-thumbnail

โœ๏ธโ€‚Runtime Data Area

๐Ÿ’ก Java ํ”„๋กœ๊ทธ๋žจ์ด ์‹คํ–‰๋  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„

1. Method Area
2. Heap
3. Stack
4. PC Register
5. Native Method Stack

Stack, PC Register, Native Method Stack์€ Thread๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ๋งˆ๋‹ค ์ƒˆ๋กœ ์ƒ์„ฑ๋˜์–ด Thread์— ํ• ๋‹น๋˜๊ณ , Heap๊ณผ Method Area๋Š” JVM์ด ์‹œ์ž‘๋  ๋•Œ ํ•œ ๋ฒˆ ํ• ๋‹น๋˜์–ด ๋ชจ๋“  Thread๊ฐ€ ๊ณต์œ ํ•œ๋‹ค.


โœ๏ธโ€‚Method Area

โœ๏ธ โ€‚๋ฉ”์„œ๋“œ ์˜์—ญ (Method Area) ์ด๋ž€?

๐Ÿ’ก ํด๋ž˜์Šค ๋กœ๋”์— ์˜ํ•ด ๋กœ๋“œ๋œ ํด๋ž˜์Šค ์ •๋ณด๊ฐ€ ์ €์žฅ๋˜๋Š” ๊ณต๊ฐ„

  • JVM์ด ์‹œ์ž‘๋  ๋•Œ ์ƒ์„ฑ๋˜๋ฉฐ, JVM์ด ์ข…๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค.
  • ํด๋ž˜์Šค์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ์–ด ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Method Area๋ฅผ ์ฐธ์กฐํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ๋”ฐ๋ผ์„œ ๋ชจ๋“  Thread๊ฐ€ Method Area๋ฅผ ๊ณต์œ ํ•˜์—ฌ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • Method Area๋Š” Type Information, Runtime Constant Pool, Field Information, Method Information, Class Variable์ด Metadata๋กœ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
    โ“Metadata ๋ž€


โœ๏ธโ€‚Heap

Heap

โœ๏ธ โ€‚ํž™ ์˜์—ญ (Heap) ์ด๋ž€?

๐Ÿ’ก new ํ‚ค์›Œ๋“œ๋กœ ์ƒ์„ฑ๋œ ๊ฐ์ฒด์™€ ๋ฐฐ์—ด์ด ๋™์ ์œผ๋กœ ํ• ๋‹น๋˜๋Š” ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ

  • JVM์ด ์‹œ์ž‘๋  ๋•Œ ์ƒ์„ฑ๋˜๋ฉฐ, JVM์ด ์ข…๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค.
  • ๋ชจ๋“  Thread๊ฐ€ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค.
  • GC(Garbage Collector) ์˜ ๋Œ€์ƒ์ด ๋˜๋Š” ๊ณต๊ฐ„์ž…๋‹ˆ๋‹ค.
    Person person = new Person("GilDong", 30); 



โœ๏ธโ€‚Stack

โœ๏ธ โ€‚์Šคํƒ ์˜์—ญ (Stack)์ด๋ž€?

๐Ÿ’ก ๊ฐ ์Šค๋ ˆ๋“œ๋งˆ๋‹ค ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ๊ณผ ๊ด€๋ จ๋œ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ๊ณต๊ฐ„

  • ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ ์‹œ๋งˆ๋‹ค ํ”„๋ ˆ์ž„(Frame)์ด๋ผ ๋ถˆ๋ฆฌ๋Š” ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๊ฐ€ ์Šคํƒ์— push๋˜๊ณ , ๋ฉ”์„œ๋“œ ์ข…๋ฃŒ ์‹œ pop๋ฉ๋‹ˆ๋‹ค.
    โ“ํ”„๋ ˆ์ž„ ์ด๋ž€
  • ๊ฐ ์Šค๋ ˆ๋“œ๋Š” ๋ณ„๋„์˜ ์Šคํƒ์„ ๊ฐ€์ง€๋ฉฐ, ์Šค๋ ˆ๋“œ๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ ํ•จ๊ป˜ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • ์Šคํƒ์€ ํ›„์ž…์„ ์ถœ(LIFO, Last In First Out) ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์žฌ๊ท€ ํ˜ธ์ถœ๊ณผ ๊ฐ™์€ ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ์ด ์Šคํƒ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.



โœ๏ธโ€‚PC Register

โœ๏ธ โ€‚PC ๋ ˆ์ง€์Šคํ„ฐ (Program Counter Register) ๋ž€?

๐Ÿ’ก ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ JVM ๋ช…๋ น์–ด์˜ ์ฃผ์†Œ๋ฅผ ์ €์žฅ

  • ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ๋ช…๋ น์–ด์˜ ์ฃผ์†Œ๋ฅผ ๊ฐ€๋ฆฌํ‚ต๋‹ˆ๋‹ค.
  • ๋ช…๋ น์–ด๊ฐ€ ์‹คํ–‰๋œ ํ›„, ๋‹ค์Œ ์‹คํ–‰ํ•  ๋ช…๋ น์–ด์˜ ์ฃผ์†Œ๋กœ ๊ฐฑ์‹ ๋ฉ๋‹ˆ๋‹ค.
  • ๊ฐ Thread ๋งˆ๋‹ค ๋ณ„๋„์˜ ํ”„๋กœ๊ทธ๋žจ ์นด์šดํ„ฐ ๋ ˆ์ง€์Šคํ„ฐ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค.
  • JVM ๋ช…๋ น์–ด์˜ ์‹คํ–‰ ์ˆœ์„œ๋ฅผ ์ œ์–ดํ•ฉ๋‹ˆ๋‹ค.
    public class Example {
        public static void main(String[] args) {
            int a = 5;  // PC: 0x0001 (ํ˜„์žฌ ๋ช…๋ น์–ด์˜ ์ฃผ์†Œ)
            int b = 10; // PC: 0x0002 (๋ช…๋ น์–ด ์‹คํ–‰ ํ›„ ๊ฐฑ์‹ )
            int sum = a + b; // PC: 0x0003 (๋ช…๋ น์–ด ์‹คํ–‰ ํ›„ ๊ฐฑ์‹ )
            System.out.println(sum); // PC: 0x0004 (๋ช…๋ น์–ด ์‹คํ–‰ ํ›„ ๊ฐฑ์‹ )
        }
    }



โœ๏ธโ€‚Native Method Stack

โœ๏ธ โ€‚๋„ค์ดํ‹ฐ๋ธŒ ๋ฉ”์„œ๋“œ ์Šคํƒ (Native Method Stack) ์ด๋ž€?

๐Ÿ’ก Java ํ”„๋กœ๊ทธ๋žจ์ด C, C++ ๋“ฑ ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋กœ ์ž‘์„ฑ๋œ ๋„ค์ดํ‹ฐ๋ธŒ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ

  • Java ํ”„๋กœ๊ทธ๋žจ์ด C, C++ ๋“ฑ ๋‹ค๋ฅธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋กœ ์ž‘์„ฑ๋œ ๋„ค์ดํ‹ฐ๋ธŒ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ
  • ์„ฑ๋Šฅ์ด๋‚˜ ํŠน์ • ๊ธฐ๋Šฅ ๋•Œ๋ฌธ์— Java๋งŒ์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ธฐ ์–ด๋ ค์šด ์ž‘์—…์„ ๋‹ค๋ฅธ ์–ธ์–ด(C, C++ ๋“ฑ)๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ์ˆ˜ํ–‰ํ•ด์•ผ ํ•  ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
  • JVM์ด ๋„ค์ดํ‹ฐ๋ธŒ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ, JNI๋ฅผ ํ†ตํ•ด ๋„ค์ดํ‹ฐ๋ธŒ ๋ฉ”์„œ๋“œ ์Šคํƒ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋„ค์ดํ‹ฐ๋ธŒ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.




์ฐธ์กฐ

profile
๊ธฐ!์ˆ ! ๋ธ”๋กœ๊ทธ

0๊ฐœ์˜ ๋Œ“๊ธ€