Introductory slides on what is OpenJDK and why and how we should contribute to it. Given to the Bulgarian JUG before the first real adopt OpenJDK hackathon
2. Agenda of the hackathon
Build OpenJDK
Improve OpenJDK
Write some tests
Create patch
Submit patch
3. Agenda of the hackathon
Build OpenJDK
Improve OpenJDK
Write some tests
Create patch
Submit patch
While building…
◦ Intro to OpenJDK
4. Let’s get it going
Import VM and login
Change to openjdk directory
cd $SOURCE_CODE/jdk9
Get the sources
bash get_sources.sh
Configure
bash configure
Make images
make clean images
5. OpenJDK overview
Free and open-source implementation of
the Java Platform, Standard Edition
Base for the Oracle VM
GPL v2 for the VMs and GPL v2 +
classpath exception for class libraries
Major contributors:
◦ IBM
◦ Apple
◦ RedHat
◦ SAP
◦ A lot of JUGs
6. Why bother?
Move Java forward
Give back something to the platform
Help our JUG gain its own identity and
focus
Acquire new knowledge
Have some fun and socialize
7. How can we help?
Introductory level
◦ Fix compiler warnings
◦ Generify, coinify and labdify internal APIs
◦ Add new tests, convert existing tests
◦ Fix typos, add javadoc
Next level
◦ Affiliate with an existing project (Jigsaw,
Nashorn)
◦ Help with new stuff in project Valhalla
8. Development process
Sign OCA
Find interesting bug or enhancement
Discuss with sponsoring project
mailing list
Get together and create a patch
◦ Don’t forget the tests!
Upload the patch and contact ML
again
Be proud of yourself!
9. Task selection (1)
Add getStackTraceString() to
Throwable
Usually people do:
catch (MyException e) {
StringWriter sw = new StringWriter();
e.printStackTrace(
new PrintWriter(sw));
}
Look at existing solutions (Apache
Commons)
https://bugs.openjdk.java.net/browse/JD
K-5050783
10. Task selection (2)
Generic support to Collection bulk
methods
addAll, containsAll, removeAll,
retainAll can only receive other
collections
You have to an intermediate
Arrays.asList:
collection.addAll(Arrays.asList("a", "b",
"c"));
Consider using default methods
https://bugs.openjdk.java.net/browse/J
DK-6201180
11. Task selection (3)
Replace array parameters with
varargs
Look throughout all internal APIs
Supported since JDK 1.5
Discuss with Joe Darcy and team
https://bugs.openjdk.java.net/browse/J
DK-4974893
12. Write some tests
JTreg: the legacy
◦ Java program with main method
◦ If test fails, testcase should throw an exception
◦ If it succeeds, testcase should return normally
/* @test
* @summary StringBuffer.isEmpty();
* @run main IsEmptyTest
*/
public class IsEmptyTest {
public static void main(String[] args) {
StringBuffer buffer = new StringBuffer();
if (!buffer.isEmpty()) {
throw new RuntimeException("StringBuffer isEmpty on new
object failed");
}
}
}
13. Test “docklets”
@test – defines a test. Mandatory.
@run – tells how to perform a test.
@summary – text description.
@library – reference library source files.
@build – compile class or library before
running test
@bug – bug number reference
@key – keywords
14. TestNG support
TestNG is cool and nicely supported
TestNG test cases are run through jtreg
Two types of tests
Type 1
◦ Describe the test in JTreg “docklets”
◦ No main method required
/* @test
* @summary comments about your test;
* @run testng YourTest
*/
Type 2
◦ Describe the test in TEST.ROOT or TESTS.properties
TestNG.dirs = .
othervm.dirs = tck/java/time/chrono
test/java/time/chrono test/java/time/format
15. Create a patch
Let’s contribute
cd $SOURCE_CODE/jdk9
Commit in Mercurial
hg status
hg commit
Run webrev
ksh ../webrev.ksh
Upload to web server
$SOURCE_CODE/jdk9/webrev