
ChatGPT is down
https://status.openai.com/
It is operational now

https://status.openai.com/
It is operational now
The code was:
long parallelSum(int[] ar, int threadCount) throws InterruptedException {
int n = ar.length;
long[] result = new long[threadCount];
Thread[] threads = new Thread[threadCount];
int chunk = n / threadCount;
for (int i = 0; i < threadCount; i++) {
int index = i;
int start = i * chunk;
int end = (i == threadCount - 1) ? n : start + chunk;
threads[i] = new Thread(() -> result[index] = sum(ar, start, end));
threads[i].start();
}
for (Thread thread : threads) thread.join();
long total = 0;
for (long value : result) total += value;
return total;
}
Which I benchmarked using JMH to see how it will behave under increase thread. But It's gets better and better until 24 thread that the reason I know my P-core are Hyperthreaded so maximum improvement is seen at 24. But after that why is'nt it constant as the law stated when N-> increases it becomes directly 1/S.
The Benchmark was performed with 3 warmup 5 iteration 1sec each and 100M dataset. I did use first 1K to see how it behaves but I forgot that until the thread get created sequential would have finished that. So after rigrously increasing dataset to 100M this was my result:
| Thread Count | Score (ns/op) | Error (ns/op) |
|---|---|---|
| 1 | 36,386,448.214 | ±1,198,308.768 |
| 2 | 19,973,254.073 | ±1,647,022.164 |
| 4 | 11,605,188.001 | ±409,298.394 |
| 8 | 8,493,406.418 | ±439,947.023 |
| 16 | 8,070,964.770 | ±101,846.828 |
| 24 | 7,880,208.459 | ±179,094.210 |
| 32 | 8,075,411.516 | ±211,717.162 |
| 64 | 8,256,737.790 | ±282,807.150 |
| 128 | 8,855,717.582 | ±121,931.514 |
| 256 | 10,475,522.486 | ±258,283.333 |
| 512 | 29,275,816.985 | ±9,028,465.533 |
Is my benchmark wrong or I am understanding different??
Before knowing anything I just jumped directly to the source code of jdk25u. I have just started to read the javaDocs of Thread class it was so deep that all my connected logic mapped very well but now I want to code and I can't code ahhhh... Why is this problem. I can call the syntax what to use but I don't know how to apply, why to apply is there any guide for java Concurrency ??. And there is so much .. still to know. Do any dev have any guide??
Recently I have been doing the benchmark test without knowing my System Multiprocessing architecture where I got to know that I have 6P + 4E core. L3 is shared among all and one instance of L2(level 2) cache is shared for E core (12-15) and it's capped at 3.2 Ghz. While my P have 2 cores paried as [(0,1),(2,3)...(10,11)] which is capped at 4.6 Ghz. each have it's own L2 instance.
Caches (sum of all):
L1d: 416 KiB (10 instances)
L1i: 448 KiB (10 instances)
L2: 9.5 MiB (7 instances)
L3: 20 MiB (1 instance)
From /sys/devices/system/cpu/.../shared_cpu_list, I found:
P-core 0 → CPU 0,1
P-core 1 → CPU 2,3
P-core 2 → CPU 4,5
P-core 3 → CPU 6,7
P-core 4 → CPU 8,9
P-core 5 → CPU 10,11
E-cores → CPU 12,13,14,15
When I did benchmark I have noticed my benchmark showing cpu_atom -> which is for E core
and the P-core by cpu there is major change in benchmark. So how do I perform benchmark? use taskset -c 0-11 java -jar target/benchmarks.jar so that it run only only on my physical core? or simply data java -jar target/benchmarks.jar?
chaos.tree.nary.BTreeNode object internals:
OFF SZ TYPE DESCRIPTION VALUE
0 8 (object header: mark) N/A
8 4 (object header: class) N/A
12 4 int NaryNode.keyCount N/A
16 1 boolean NaryNode.isLeaf N/A
17 3 (alignment/padding gap)
20 4 java.lang.Object[] NaryNode.keys N/A
24 4 chaos.tree.core.searchtree.nary.NaryNode[] NaryNode.children N/A
28 4 (object alignment gap)
Instance size: 32 bytes
Space losses: 3 bytes internal + 4 bytes external = 7 bytes total
ExactByte : 32
Heading mistake 7 bit -> byte
There is 7byte of extra padding
25 byte If I made somehow 24byte JVM would not do padding.
Link: https://github.com/Chaos-vy/ChaosTree/blob/main/src/main/java/chaos/tree/core/searchtree/nary/NaryNode.java
What is ChaosTree?
ChaosTree is a zero dependency Java Search Tree library. It currently features:
>BinaryFamily : Binary Tree, AVL Tree, RBT, Splay and Treap.
NaryFamily : B-Tree and B+Tree
NavigableSet<T> API (unsupported view operations fail fast)[v1.1.0] -Latest:
NavigableSet compatibilityComparable<? super T>)An example
NavigableSet<Integer> rbt = new RBT<>();
NavigableSet<Integer> bplustree = new BPlusTree<>(32); // degree CLRS method 31min key 63 max key default:32
//For Rich API use
for (int i = 0; i < 20; i++) {rbt.add(i);}
NaryTree<Integer> bplustree0 = new BPlusTree<>(3,rbt);//Useful constructor API
BinaryTree<Integer> rbt0 = new RBT<>(rbt);
List<Integer> list = rbt0.stream().filter(v->v%2==0).collect(Collectors.toList());
System.out.println(list);
System.out.println();
rbt.retainAll(list);
System.out.println(rbt);
rbt0.retainAllElements(list); //Renamed due to ambiguous situation
System.out.println(rbt0.toString(PrintStyle.UNICODE));
Output:
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
8(B)
+-- 4(B)
| +-- 2(B)
| | \-- 0(R)
| \-- 6(B)
\-- 16(B)
+-- 12(R)
| +-- 10(B)
| \-- 14(B)
\-- 18(B)
8(B)
├── 4(B)
│ ├── 2(B)
│ │ └── 0(R)
│ └── 6(B)
└── 16(B)
├── 12(R)
│ ├── 10(B)
│ └── 14(B)
└── 18(B)
My Github Repo: https://github.com/Chaos-vy/ChaosTree
BinaryFamily: https://github.com/Chaos-vy/ChaosTree/tree/main/docs/BinaryFamily
NaryFamily: https://github.com/Chaos-vy/ChaosTree/tree/main/docs/NaryFamily
NavigableSet: https://github.com/Chaos-vy/ChaosTree/blob/main/docs/NavigableSet.md
Feedback, suggestions, and code reviews are always welcome!
Feel free to guide me this is my first project.
Can anyone tell why should I use JPMS(Java Platform module System) when I have Encapsulation? I also read docs but the answer is directing to reflection if Encapsulation is not safe how JPMS safe it?
Edited:
I got the answer https://blogs.oracle.com/javamagazine/java-quiz-jpms-package-management/ so JPMS provide true encapsulation, does that mean encapsulation is partial without JPMS?
I have Knowledge of Jdk17+ currently moving to Jdk21+. I have essentially completed Java.utils.*; and concurrent library to deep. I have also used jdk tools and understand the concepts of JVM, JMM. OOPs is completed from beginner to F-Form polymorphism. I also made project based on Java SE knowledge. The project is tested on JUnit6, JCStress, JMH- with Linux profilers and Java Flight recorder too. It's my first time I am going Outside domain of Java SE to Java EE. What is way should I start?
First JDBC->SQL->PostgressSQL?
Network?
SpringBoot?
or learn while learning SpringBoot?
Can you tell me what beginners mistake I should avoide?
I have also took helped from many other AI but I did not got the optimum way.
The question seems to be simple but it hides a very deep concept, Many of us will say it's same, some will say 1-D or N-D. The question is Which array will be faster in terms of traversal operation: case1: with non-primitive data type case2: with primitive data type.
The answer is subjected to Java only: 1-D array wins in both cases.
The Reason:
Pointer chasing is the process of repeatedly following references (pointers) in memory to reach the actual data. More the pointer less the speed, Less the pointer more the speed.
>Non-primitive data type are structured in this format [pointer |-> value] , Since array is also non-primitive type it is also stored as [pointer |-> array]
Primitive data type are raw value with no pointer overhead.
1-D array: When the array is formed it has only one pointer that is of Array when the non-primitive datatype are added from 1-N it become ~ (N+1) pointer. for primitive it's only 1-pointer.
N-D array: When the array is formed it becomes arrays of array so suppose a 2-D array[][] = 1 outer + K inner + N for primitive data type => N+K+1 for primitive it becomes K+1 pointer
We can see clearly that in both cases that 1-D array always has less pointer, So it wins to other every dimension type of array.
JMM behind array:
Every Java array is an object with its own header.
A primitive array (int[]) is laid out roughly as:
+----------------------+
| Mark Word |
| Klass Pointer |
| Array Length |
| Padding (if needed) |
| int | int | int ... |
+----------------------+
The primitive values are stored contiguously immediately after the header.
Java Does NOT Have True Multidimensional Arrays:
A 2-D array (int[][]) is not one large block:
Outer Array
+---------------------------+
| Header |
| ref | ref | ref | ... |
+---------------------------+
↓ ↓
+---------+ +---------+
| Header | | Header |
| int... | | int... |
+---------+ +---------+
Each row is a separate array object with its own header, allocated independently on the heap.
Modern CPUs load memory in cache lines (typically 64 bytes).
1-D array:One object, contiguous primitive values, excellent spatial locality, minimal pointer chasing.N-D array:Array of arrays, extra object headers, one additional pointer dereference per row, and rows may be scattered across the heap.First of all I did not watch that 10h23min video I just wanted to test my knowledge. From my POV test are basics and foundational part of Java. The Test duration was 60min consisting of 20 question. The question that were asked were related to this topic:
I got 95% accuracy. (qualification threshold 80%)
So, If you mates wanted to know how is your basics of foundation java is ?, you can check over there.
This test is very easy ,it does not involve any library function. You can just enroll in Oracle free certication program, Get your First Oracle badge(they don't provide certificate){ You can put on linked in, X, Email and facebook.} Making account on oracle is notorius be patient.
If anyone has any resource that is for test(free) please do put in comment.
Link: https://mylearn.oracle.com/ou/learning-path/oracle-java-foundations-training-and-assessment/152239
After reading all the String documentation and exact code of String class, I find the main engine that makes String in Java (study of deep knowledge) i.e., String constant pool. when we say String s0 = "example1" , String s1 = "example1" and String s2 = "example2" what happens is exactly:
Now the example case:
After reading and analysing there is also a issue of massive garbage I see:
suppose if 4 thread are runnable and they are trying to intern() the object in SCP that creates garbage according to your data size suppose , we used latin-1 type 256B data so total thread is 4 but in CAS only one thread execute rest all thread dumps the object so out of 1KB storage 768B is garbage. if the String was in UTF-16 it would cost 2*768B.
Now my question is ?
Having grasped of Java SE I cannot completely write mechanical sympathy code from it. Can you suggest how should I start C++ language? I want to get ready with syntax first is there any critics or guide is so when i start my C++ journey I need to be clear of it.
IDE suggestion ? (VsCode | CLion)
The point is Syntax is not problem for me, the problem is, how can I maximize my knowledge in grasping, how internally the C works under the hood?
I want to write a library with mechanical sympathy and see how L1,L2,L3 modern CPU architecture does work.
The bookish langugae states "hiding complex implementation details and exposing only the essential features of an object"
However, after reading the Java Collections Framework and other parts of the JDK, I noticed that many abstract classes contain substantial shared implementation rather than just abstract method declarations. I noticed that only an "interface class" 100% abstraction(ignoring default methods)
This made me wonder:
I also noticed that the JDK sometime relies on encapsulation (and in Java9+, JPMS) to hide implementation details. So I'm in dilemma if the textbook explanation oversimplifies what abstraction means in practice.
Am I misunderstanding abstraction, or is the textbook definition incomplete?
To be clear, this isn't about what abstract does in Java — it's about the SE term. abstract class is one syntax tool for expressing abstraction, same as interfaces are. The question is whether "abstraction = hiding implementation" is even a good definition of the concept, given it's indistinguishable from encapsulation under that definition.
I am literally confused what is meant by Core Java?
I have become familiar with java. IDK exactly at which phase I am doing. I can do OOPs easily ( have also understood F-form polymorphism) I can easily use stream , collection, iterator API . I can also integrate to them in my project. I started delving into deep JLS, JVMs but after seeing them I am confused are they core java because seeing those topics I felt like I did only basics of java.