Skip to content

Commit bbc4dc0

Browse files
committed
Yet another documentation update
1 parent 6a8e090 commit bbc4dc0

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

doc/About JavOC/Changelog and to-do.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ In this pre-release I plan to implement readings of the constant pool and expand
1313
- [x] Access flags
1414
- [x] Constant pool
1515
### Documentation
16-
- [ ] Class Loading algorithm:
17-
- [ ] Constant pool loading procedure
18-
- [ ] Descriptors
19-
- [ ] Expand "Class File Format"
20-
- [ ] 'Magic Value'
21-
- [ ] Versions
22-
- [ ] Constant pool
16+
- [x] Expand "Class File Format"
17+
- [x] 'Magic Value'
18+
- [x] Versions
19+
- [x] Constant pool
2320
- [ ] Expand "Class structure by example"
2421
- [ ] 'Magic value'
2522
- [ ] Versions
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
# Constant pool
2-
Constant pool in Java class is a structure, that contains, well, *constants*.
2+
## Purpose of constant pool
3+
Bytecode uses data very often, and something like string literals cannot be stored into code, but instead it should be kept *somewhere* to be later referenced by bytecode:
34

4-
However,
5+
```java
6+
new #2 // Class java/lang/Object
7+
```
8+
9+
This data will never change during runtime, thus making these values **constants**! And these values are stored in a special structure called **constant pool**
10+
11+
## Structrue of constant pool
12+
That's how it looks:
13+
14+
<img src="../Diagrams/Class%20Loading%20and%20structure/Constant%20Pool.png" alt="drawing" width="90%"/>
15+
16+
The very first field of it is a `Constant pool size` - a field that, suddenly, defines the size of the constant pool, but, for some mysterious reason, it's actually *greater* than amount of constants by 1 *(So that if `constant pool size` has a value of 5, there are actually only 4 constants in the pool)*
17+
18+
As you can see, the actual length of the constant pool is unknown *(marked as X)*. That's because each constant entry has its own length - for example, `Utf8` constant may be 20 bytes long, or 200 bytes - we won't know it until we start reading constant pool values, one by one.
19+
20+
## Constant in constant pool
21+
There are actually many different constants that define different things - from float and double variables to method and class signatures.
22+
23+
In Java 6, that JavOC implements, there are 11 different constants, that I'm too lazy to describe, so you better look them up in official documentation:
24+
[Here it goes](https://docs.oracle.com/javase/specs/jvms/se6/html/ClassFile.doc.html#20080)

0 commit comments

Comments
 (0)