Skip to content

Commit

Permalink
Merge branch 'master' into JDK-8273553
Browse files Browse the repository at this point in the history
  • Loading branch information
bradfordwetmore committed Mar 18, 2022
2 parents 26de26a + ff0b092 commit 4395301
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 202 deletions.
9 changes: 6 additions & 3 deletions make/common/JarArchive.gmk
@@ -1,5 +1,5 @@
#
# Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -193,7 +193,8 @@ define SetupJarArchiveBody
$1_UPDATE_CONTENTS=\
if [ "`$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'`" -gt "0" ]; then \
$(ECHO) " updating" `$(WC) -l $$($1_BIN)/_the.$$($1_JARNAME)_contents | $(AWK) '{ print $$$$1 }'` files && \
$$($1_JAR_CMD) --update $$($1_JAR_OPTIONS) --file $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents; \
$(SORT) $$($1_BIN)/_the.$$($1_JARNAME)_contents > $$($1_BIN)/_the.$$($1_JARNAME)_contents_sorted && \
$$($1_JAR_CMD) --update $$($1_JAR_OPTIONS) --file $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents_sorted; \
fi $$(NEWLINE)
# The s-variants of the above macros are used when the jar is created from scratch.
# NOTICE: please leave the parentheses space separated otherwise the AIX build will break!
Expand All @@ -212,7 +213,9 @@ define SetupJarArchiveBody
| $(SED) 's|$$(src)/|-C $$(src) |g' >> \
$$($1_BIN)/_the.$$($1_JARNAME)_contents) $$(NEWLINE) )
endif
$1_SUPDATE_CONTENTS=$$($1_JAR_CMD) --update $$($1_JAR_OPTIONS) --file $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents $$(NEWLINE)
$1_SUPDATE_CONTENTS=\
$(SORT) $$($1_BIN)/_the.$$($1_JARNAME)_contents > $$($1_BIN)/_the.$$($1_JARNAME)_contents_sorted && \
$$($1_JAR_CMD) --update $$($1_JAR_OPTIONS) --file $$@ @$$($1_BIN)/_the.$$($1_JARNAME)_contents_sorted $$(NEWLINE)

# Use a slightly shorter name for logging, but with enough path to identify this jar.
$1_NAME:=$$(subst $$(OUTPUTDIR)/,,$$($1_JAR))
Expand Down
12 changes: 11 additions & 1 deletion src/java.base/share/classes/java/util/zip/Deflater.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -895,6 +895,16 @@ private void ensureOpen() {
throw new NullPointerException("Deflater has been closed");
}

/**
* Returns the value of 'finish' flag.
* 'finish' will be set to true if def.finish() method is called.
*/
boolean shouldFinish() {
synchronized (zsRef) {
return finish;
}
}

private static native long init(int level, int strategy, boolean nowrap);
private static native void setDictionary(long addr, byte[] b, int off,
int len);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -220,9 +220,15 @@ public void write(byte[] b, int off, int len) throws IOException {
*/
public void finish() throws IOException {
if (!def.finished()) {
def.finish();
while (!def.finished()) {
deflate();
try{
def.finish();
while (!def.finished()) {
deflate();
}
} catch(IOException e) {
if (usesDefaultDeflater)
def.end();
throw e;
}
}
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -314,7 +314,7 @@ public void closeEntry() throws IOException {
crc.reset();
current = null;
} catch (IOException e) {
if (usesDefaultDeflater && !(e instanceof ZipException))
if (def.shouldFinish() && usesDefaultDeflater && !(e instanceof ZipException))
def.end();
throw e;
}
Expand Down
11 changes: 11 additions & 0 deletions src/java.base/share/native/libjava/ClassLoader.c
Expand Up @@ -99,7 +99,12 @@ Java_java_lang_ClassLoader_defineClass1(JNIEnv *env,
return 0;
}

// On AIX malloc(0) returns NULL which looks like an out-of-memory condition; so adjust it to malloc(1)
#ifdef _AIX
body = (jbyte *)malloc(length == 0 ? 1 : length);
#else
body = (jbyte *)malloc(length);
#endif

if (body == 0) {
JNU_ThrowOutOfMemoryError(env, 0);
Expand Down Expand Up @@ -239,7 +244,13 @@ Java_java_lang_ClassLoader_defineClass0(JNIEnv *env,
return 0;
}

// On AIX malloc(0) returns NULL which looks like an out-of-memory condition; so adjust it to malloc(1)
#ifdef _AIX
body = (jbyte *)malloc(length == 0 ? 1 : length);
#else
body = (jbyte *)malloc(length);
#endif

if (body == 0) {
JNU_ThrowOutOfMemoryError(env, 0);
return 0;
Expand Down
Expand Up @@ -109,14 +109,19 @@ private ChunkHeader(RecordingInput input, long absoluteChunkStart, long id) thro
input.position(absoluteEventStart);
}

private byte readFileState() throws IOException {
byte fs;
input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
while ((fs = input.readPhysicalByte()) == UPDATING_CHUNK_HEADER) {
Utils.takeNap(1);
input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
}
return fs;
}

public void refresh() throws IOException {
while (true) {
byte fileState1;
input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
while ((fileState1 = input.readPhysicalByte()) == UPDATING_CHUNK_HEADER) {
Utils.takeNap(1);
input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
}
byte fileState1 = readFileState();
input.positionPhysical(absoluteChunkStart + CHUNK_SIZE_POSITION);
long chunkSize = input.readPhysicalLong();
long constantPoolPosition = input.readPhysicalLong();
Expand Down Expand Up @@ -169,10 +174,9 @@ public void awaitFinished() throws IOException {
}
long pos = input.position();
try {
input.positionPhysical(absoluteChunkStart + FILE_STATE_POSITION);
while (true) {
byte filestate = input.readPhysicalByte();
if (filestate == 0) {
byte fileState = readFileState();
if (fileState == 0) {
finished = true;
return;
}
Expand Down
Expand Up @@ -41,7 +41,7 @@
import jdk.jfr.internal.MetadataDescriptor;
import jdk.jfr.internal.Type;
import jdk.jfr.internal.Utils;
import jdk.jfr.internal.consumer.filter.CheckPointEvent;
import jdk.jfr.internal.consumer.filter.CheckpointEvent;
import jdk.jfr.internal.consumer.filter.ChunkWriter;

/**
Expand Down Expand Up @@ -77,7 +77,7 @@ public boolean isOrdered() {
}
}

private enum CheckPointType {
private enum CheckpointType {
// Checkpoint that finishes a flush segment
FLUSH(1),
// Checkpoint contains chunk header information in the first pool
Expand All @@ -87,7 +87,7 @@ private enum CheckPointType {
// Checkpoint contains thread related information
THREAD(8);
private final int mask;
private CheckPointType(int mask) {
private CheckpointType(int mask) {
this.mask = mask;
}

Expand Down Expand Up @@ -267,7 +267,7 @@ public RecordedEvent readEvent() throws IOException {
// Not accepted by filter
} else {
if (typeId == 1) { // checkpoint event
if (CheckPointType.FLUSH.is(parseCheckpointType())) {
if (CheckpointType.FLUSH.is(parseCheckpointType())) {
input.position(pos + size);
return FLUSH_MARKER;
}
Expand Down Expand Up @@ -317,9 +317,9 @@ private void fillConstantPools(long abortCP) throws IOException {
long delta = -1;
boolean logTrace = Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE);
while (thisCP != abortCP && delta != 0) {
CheckPointEvent cp = null;
CheckpointEvent cp = null;
if (configuration.chunkWriter != null) {
cp = configuration.chunkWriter.newCheckPointEvent(thisCP);
cp = configuration.chunkWriter.newCheckpointEvent(thisCP);
}
input.position(thisCP);
lastCP = thisCP;
Expand Down
Expand Up @@ -35,36 +35,36 @@
* <p>
* All positional values are relative to file start, not the chunk.
*/
public final class CheckPointEvent {
public final class CheckpointEvent {
private final ChunkWriter chunkWriter;
private final LinkedHashMap<Long, CheckPointPool> pools = new LinkedHashMap<>();
private final LinkedHashMap<Long, CheckpointPool> pools = new LinkedHashMap<>();
private final long startPosition;

public CheckPointEvent(ChunkWriter chunkWriter, long startPosition) {
public CheckpointEvent(ChunkWriter chunkWriter, long startPosition) {
this.chunkWriter = chunkWriter;
this.startPosition = startPosition;
}

public PoolEntry addEntry(Type type, long id, long startPosition, long endPosition, Object references) {
long typeId = type.getId();
PoolEntry pe = new PoolEntry(startPosition, endPosition, type, id, references);
var cpp = pools.computeIfAbsent(typeId, k -> new CheckPointPool(typeId));
var cpp = pools.computeIfAbsent(typeId, k -> new CheckpointPool(typeId));
cpp.add(pe);
chunkWriter.getPool(type).add(id, pe);
return pe;
}

public long touchedPools() {
int count = 0;
for (CheckPointPool cpp : pools.values()) {
for (CheckpointPool cpp : pools.values()) {
if (cpp.isTouched()) {
count++;
}
}
return count;
}

public Collection<CheckPointPool> getPools() {
public Collection<CheckpointPool> getPools() {
return pools.values();
}

Expand All @@ -74,7 +74,7 @@ public long getStartPosition() {

public String toString() {
StringBuilder sb = new StringBuilder();
for (CheckPointPool p : pools.values()) {
for (CheckpointPool p : pools.values()) {
for (var e : p.getEntries()) {
if (e.isTouched()) {
sb.append(e.getType().getName() + " " + e.getId() + "\n");
Expand Down
Expand Up @@ -29,11 +29,11 @@
/**
* Represents a constant pool in a checkpoint, both entries and type id
*/
final class CheckPointPool {
final class CheckpointPool {
private final List<PoolEntry> entries = new ArrayList<>();
private final long typeId;

public CheckPointPool(long typeId) {
public CheckpointPool(long typeId) {
this.typeId = typeId;
}

Expand Down
Expand Up @@ -51,15 +51,15 @@
*/
public final class ChunkWriter implements Closeable {
private LongMap<Constants> pools = new LongMap<>();
private final Deque<CheckPointEvent> checkPoints = new ArrayDeque<>();
private final Deque<CheckpointEvent> checkpoints = new ArrayDeque<>();
private final Path destination;
private final RecordingInput input;
private final RecordingOutput output;
private final Predicate<RecordedEvent> filter;

private long chunkStartPosition;
private boolean chunkComplete;
private long lastCheckPoint;
private long lastCheckpoint;

public ChunkWriter(Path source, Path destination, Predicate<RecordedEvent> filter) throws IOException {
this.destination = destination;
Expand All @@ -78,9 +78,9 @@ Constants getPool(Type type) {
return pool;
}

public CheckPointEvent newCheckPointEvent(long startPosition) {
CheckPointEvent event = new CheckPointEvent(this, startPosition);
checkPoints.add(event);
public CheckpointEvent newCheckpointEvent(long startPosition) {
CheckpointEvent event = new CheckpointEvent(this, startPosition);
checkpoints.add(event);
return event;
}

Expand Down Expand Up @@ -120,16 +120,16 @@ public void writeEvent(long startPosition, long endPosition) throws IOException

// Write check point events before a position
private void writeCheckpointEvents(long before) throws IOException {
CheckPointEvent cp = checkPoints.peek();
CheckpointEvent cp = checkpoints.peek();
while (cp != null && cp.getStartPosition() < before) {
checkPoints.poll();
checkpoints.poll();
long delta = 0;
if (lastCheckPoint != 0) {
delta = lastCheckPoint - output.position();
if (lastCheckpoint != 0) {
delta = lastCheckpoint - output.position();
}
lastCheckPoint = output.position();
lastCheckpoint = output.position();
write(cp, delta);
cp = checkPoints.peek();
cp = checkpoints.peek();
}
}

Expand Down Expand Up @@ -174,10 +174,10 @@ public void endChunk(ChunkHeader header) throws IOException {
writeCheckpointEvents(Long.MAX_VALUE);
long metadata = output.position();
writeMetadataEvent(header);
updateHeader(output.position(), lastCheckPoint, metadata);
updateHeader(output.position(), lastCheckpoint, metadata);
pools = new LongMap<>();
chunkComplete = true;
lastCheckPoint = 0;
lastCheckpoint = 0;
}

private void writeMetadataEvent(ChunkHeader header) throws IOException {
Expand All @@ -190,7 +190,7 @@ private void writeMetadataEvent(ChunkHeader header) throws IOException {
}
}

private void write(CheckPointEvent event, long delta) throws IOException {
private void write(CheckpointEvent event, long delta) throws IOException {
input.position(event.getStartPosition());
long startPosition = output.position();

Expand All @@ -205,7 +205,7 @@ private void write(CheckPointEvent event, long delta) throws IOException {

// Write even if touched pools are zero, checkpoint works as sync point
output.writeLong(event.touchedPools()); // Pool count
for (CheckPointPool pool : event.getPools()) {
for (CheckpointPool pool : event.getPools()) {
if (pool.isTouched()) {
output.writeLong(pool.getTypeId());
output.writeLong(pool.getTouchedCount());
Expand Down
Expand Up @@ -100,7 +100,7 @@ private void printInformation(Path p) throws IOException {
}
HashMap<Long, Statistics> stats = new HashMap<>();
stats.put(0L, new Statistics(eventPrefix + "Metadata"));
stats.put(1L, new Statistics(eventPrefix + "CheckPoint"));
stats.put(1L, new Statistics(eventPrefix + "Checkpoint"));
int minWidth = 0;
while (true) {
long chunkEnd = ch.getEnd();
Expand Down
Expand Up @@ -179,7 +179,7 @@ public synchronized void write(byte[] bytes) throws IOException {
bufferIndex = 0;
break;
case CHECKPOINT_EVENT_HEADER_BYTE_ARRAY_CONTENT:
processCheckPointHeader();
processCheckpointHeader();
break;
case CHECKPOINT_EVENT_FLUSH_TYPE:
processFlush();
Expand Down Expand Up @@ -286,10 +286,10 @@ private void processInitialHeader() throws IOException {
}
}

private void processCheckPointHeader() throws IOException {
private void processCheckpointHeader() throws IOException {
buffer.put(bufferIndex, nextByte(true));
if (bufferIndex == HEADER_SIZE) {
writeCheckPointHeader();
writeCheckpointHeader();
state = State.EVENT_PAYLOAD;
bufferIndex = 0;
}
Expand Down Expand Up @@ -321,7 +321,7 @@ private void completePrevious(DiskChunk previous) throws IOException {
}
}

private void writeCheckPointHeader() throws IOException {
private void writeCheckpointHeader() throws IOException {
Objects.requireNonNull(raf);
byte state = buffer.get(HEADER_FILE_STATE_POSITION);
boolean complete = state == COMPLETE_STATE;
Expand Down

0 comments on commit 4395301

Please sign in to comment.