Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
[GR-38389] Merge in jdk-11.0.16-ga (21.3).
Browse files Browse the repository at this point in the history
PullRequest: labsjdk-ce-11/294
  • Loading branch information
marwan-hallaoui committed Jul 20, 2022
2 parents 2505ae7 + 284ac36 commit a4cf282
Show file tree
Hide file tree
Showing 17 changed files with 613 additions and 203 deletions.
9 changes: 5 additions & 4 deletions src/hotspot/share/ci/ciEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool,
ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
int pool_index, int cache_index,
ciInstanceKlass* accessor) {
bool ignore_will_link;
EXCEPTION_CONTEXT;
int index = pool_index;
if (cache_index >= 0) {
Expand Down Expand Up @@ -658,23 +657,25 @@ ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
return ciConstant(T_OBJECT, constant);
}
} else if (tag.is_klass() || tag.is_unresolved_klass()) {
// 4881222: allow ldc to take a class type
ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor);
bool will_link;
ciKlass* klass = get_klass_by_index_impl(cpool, index, will_link, accessor);
if (HAS_PENDING_EXCEPTION) {
CLEAR_PENDING_EXCEPTION;
record_out_of_memory_failure();
return ciConstant();
}
assert (klass->is_instance_klass() || klass->is_array_klass(),
"must be an instance or array klass ");
return ciConstant(T_OBJECT, klass->java_mirror());
ciInstance* mirror = (will_link ? klass->java_mirror() : get_unloaded_klass_mirror(klass));
return ciConstant(T_OBJECT, mirror);
} else if (tag.is_method_type()) {
// must execute Java code to link this CP entry into cache[i].f1
ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
ciObject* ciobj = get_unloaded_method_type_constant(signature);
return ciConstant(T_OBJECT, ciobj);
} else if (tag.is_method_handle()) {
// must execute Java code to link this CP entry into cache[i].f1
bool ignore_will_link;
int ref_kind = cpool->method_handle_ref_kind_at(index);
int callee_index = cpool->method_handle_klass_index_at(index);
ciKlass* callee = get_klass_by_index_impl(cpool, callee_index, ignore_will_link, accessor);
Expand Down
28 changes: 25 additions & 3 deletions src/hotspot/share/interpreter/linkResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1698,10 +1698,32 @@ void LinkResolver::resolve_handle_call(CallInfo& result,
assert(resolved_klass == SystemDictionary::MethodHandle_klass() ||
resolved_klass == SystemDictionary::VarHandle_klass(), "");
assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), "");
Handle resolved_appendix;
Handle resolved_method_type;
Handle resolved_appendix;
Handle resolved_method_type;
methodHandle resolved_method = lookup_polymorphic_method(link_info,
&resolved_appendix, &resolved_method_type, CHECK);
&resolved_appendix, &resolved_method_type, CHECK);

if (link_info.check_access()) {
Symbol* name = link_info.name();
vmIntrinsics::ID iid = MethodHandles::signature_polymorphic_name_id(name);
if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) {
// Check if method can be accessed by the referring class.
// MH.linkTo* invocations are not rewritten to invokehandle.
assert(iid == vmIntrinsics::_invokeBasic, "%s", vmIntrinsics::name_at(iid));

Klass* current_klass = link_info.current_klass();
assert(current_klass != NULL , "current_klass should not be null");
check_method_accessability(current_klass,
resolved_klass,
resolved_method->method_holder(),
resolved_method,
CHECK);
} else {
// Java code is free to arbitrarily link signature-polymorphic invokers.
assert(iid == vmIntrinsics::_invokeGeneric, "not an invoker: %s", vmIntrinsics::name_at(iid));
assert(MethodHandles::is_signature_polymorphic_public_name(resolved_klass, name), "not public");
}
}
result.set_handle(resolved_klass, resolved_method, resolved_appendix, resolved_method_type, CHECK);
}

Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/net/HostPortrange.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 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 @@ -137,7 +137,7 @@ public int hashCode() {
}
this.ipv4 = this.literal = ipv4;
if (ipv4) {
byte[] ip = IPAddressUtil.textToNumericFormatV4(hoststr);
byte[] ip = IPAddressUtil.validateNumericFormatV4(hoststr);
if (ip == null) {
throw new IllegalArgumentException("illegal IPv4 address");
}
Expand Down
18 changes: 14 additions & 4 deletions src/java.base/share/classes/java/net/InetAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,11 @@ private String removeComments(String hostsEntry) {
private byte [] createAddressByteArray(String addrStr) {
byte[] addrArray;
// check if IPV4 address - most likely
addrArray = IPAddressUtil.textToNumericFormatV4(addrStr);
try {
addrArray = IPAddressUtil.validateNumericFormatV4(addrStr);
} catch (IllegalArgumentException iae) {
return null;
}
if (addrArray == null) {
addrArray = IPAddressUtil.textToNumericFormatV6(addrStr);
}
Expand Down Expand Up @@ -1324,13 +1328,19 @@ private static InetAddress[] getAllByName(String host, InetAddress reqAddr)
}

// if host is an IP address, we won't do further lookup
if (Character.digit(host.charAt(0), 16) != -1
if (IPAddressUtil.digit(host.charAt(0), 16) != -1
|| (host.charAt(0) == ':')) {
byte[] addr = null;
byte[] addr;
int numericZone = -1;
String ifname = null;
// see if it is IPv4 address
addr = IPAddressUtil.textToNumericFormatV4(host);
try {
addr = IPAddressUtil.validateNumericFormatV4(host);
} catch (IllegalArgumentException iae) {
var uhe = new UnknownHostException(host);
uhe.initCause(iae);
throw uhe;
}
if (addr == null) {
// This is supposed to be an IPv6 literal
// Check if a numeric or string zone id is present
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/net/SocketPermission.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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 @@ -463,7 +463,7 @@ private void init(String host, int mask) {
if (!host.isEmpty()) {
// see if we are being initialized with an IP address.
char ch = host.charAt(0);
if (ch == ':' || Character.digit(ch, 16) != -1) {
if (ch == ':' || IPAddressUtil.digit(ch, 16) != -1) {
byte ip[] = IPAddressUtil.textToNumericFormatV4(host);
if (ip == null) {
ip = IPAddressUtil.textToNumericFormatV6(host);
Expand Down
64 changes: 42 additions & 22 deletions src/java.base/share/classes/jdk/internal/util/xml/impl/Parser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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 @@ -30,6 +30,7 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import jdk.internal.org.xml.sax.InputSource;
Expand All @@ -42,7 +43,11 @@ public abstract class Parser {

public static final String FAULT = "";
protected static final int BUFFSIZE_READER = 512;
// Initial buffer (mBuff) size
protected static final int BUFFSIZE_PARSER = 128;
// Max buffer size
private static final int MAX_ARRAY_SIZE = 1024 << 16;

/**
* The end of stream character.
*/
Expand Down Expand Up @@ -525,6 +530,10 @@ private void dtd() throws Exception {
mPh = PH_DTD; // DTD
for (short st = 0; st >= 0;) {
ch = getch();
// report error if EOS is reached while parsing the DTD
if (ch == EOS) {
panic(FAULT);
}
switch (st) {
case 0: // read the document type name
if (chtyp(ch) != ' ') {
Expand Down Expand Up @@ -1664,6 +1673,10 @@ private void cdat()
mBuffIdx = -1;
for (short st = 0; st >= 0;) {
ch = getch();
// report error if EOS is reached while parsing the DTD
if (ch == EOS) {
panic(FAULT);
}
switch (st) {
case 0: // the first '[' of the CDATA open
if (ch == '[') {
Expand Down Expand Up @@ -1871,7 +1884,7 @@ protected String eqstr(char flag) throws Exception {
}

/**
* Resoves an entity.
* Resolves an entity.
*
* This method resolves built-in and character entity references. It is also
* reports external entities to the application.
Expand Down Expand Up @@ -2529,7 +2542,7 @@ private char bkeyword()
}

/**
* Reads a single or double quotted string in to the buffer.
* Reads a single or double quoted string into the buffer.
*
* This method resolves entities inside a string unless the parser parses
* DTD.
Expand Down Expand Up @@ -2664,7 +2677,7 @@ protected abstract void bflash_ws()
* @param ch The character to append to the buffer.
* @param mode The normalization mode.
*/
private void bappend(char ch, char mode) {
private void bappend(char ch, char mode) throws Exception {
// This implements attribute value normalization as
// described in the XML specification [#3.3.3].
switch (mode) {
Expand Down Expand Up @@ -2714,16 +2727,9 @@ private void bappend(char ch, char mode) {
*
* @param ch The character to append to the buffer.
*/
private void bappend(char ch) {
try {
mBuff[++mBuffIdx] = ch;
} catch (Exception exp) {
// Double the buffer size
char buff[] = new char[mBuff.length << 1];
System.arraycopy(mBuff, 0, buff, 0, mBuff.length);
mBuff = buff;
mBuff[mBuffIdx] = ch;
}
private void bappend(char ch) throws Exception {
ensureCapacity(++mBuffIdx);
mBuff[mBuffIdx] = ch;
}

/**
Expand All @@ -2733,14 +2739,9 @@ private void bappend(char ch) {
* @param cidx The character buffer (mChars) start index.
* @param bidx The parser buffer (mBuff) start index.
*/
private void bcopy(int cidx, int bidx) {
private void bcopy(int cidx, int bidx) throws Exception {
int length = mChIdx - cidx;
if ((bidx + length + 1) >= mBuff.length) {
// Expand the buffer
char buff[] = new char[mBuff.length + length];
System.arraycopy(mBuff, 0, buff, 0, mBuff.length);
mBuff = buff;
}
ensureCapacity(bidx + length + 1);
System.arraycopy(mChars, cidx, mBuff, bidx, length);
mBuffIdx += length;
}
Expand Down Expand Up @@ -3327,7 +3328,7 @@ protected char chtyp(char ch) {
}

/**
* Retrives the next character in the document.
* Retrieves the next character in the document.
*
* @return The next character in the document.
*/
Expand Down Expand Up @@ -3433,4 +3434,23 @@ protected Pair del(Pair pair) {

return next;
}

private void ensureCapacity(int minCapacity) throws Exception {
if (mBuff == null) {
int newCapacity = minCapacity > BUFFSIZE_PARSER ?
minCapacity + BUFFSIZE_PARSER : BUFFSIZE_PARSER;
mBuff = new char[newCapacity];
return;
}

if (mBuff.length <= minCapacity) {
int size = mBuff.length << 1;
int newCapacity = size > minCapacity ? size : minCapacity + BUFFSIZE_PARSER;
if (newCapacity < 0 || newCapacity > MAX_ARRAY_SIZE) {
panic(FAULT);
}

mBuff = Arrays.copyOf(mBuff, newCapacity);
}
}
}
Loading

0 comments on commit a4cf282

Please sign in to comment.