RFR (XS) 8241462: StripNativeDebugSymbols jlink plugin allocates huge arrays

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

RFR (XS) 8241462: StripNativeDebugSymbols jlink plugin allocates huge arrays

Aleksey Shipilev-3
RFE:
  https://bugs.openjdk.java.net/browse/JDK-8241462

In some of my testing pipelines that deal with huge .so-s due to specific build configuration, tests
that use the StripNativeDebugSymbols plugin fail with OOME. It can be fixed by using the method that
copies the InputStream straight to destination file without instantiating the huge array. The only
wrinkle is that we need to close the InputStream after we are done.

diff -r c456587e7ef4
src/jdk.jlink/linux/classes/jdk/tools/jlink/internal/plugins/StripNativeDebugSymbolsPlugin.java
---
a/src/jdk.jlink/linux/classes/jdk/tools/jlink/internal/plugins/StripNativeDebugSymbolsPlugin.java
Mon Mar 23 19:14:01 2020 +0100
+++
b/src/jdk.jlink/linux/classes/jdk/tools/jlink/internal/plugins/StripNativeDebugSymbolsPlugin.java
Mon Mar 23 20:13:15 2020 +0100
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2019, Red Hat, Inc.
+ * Copyright (c) 2019, 2020, Red Hat, Inc.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -25,4 +25,5 @@
 package jdk.tools.jlink.internal.plugins;

+import java.io.InputStream;
 import java.io.IOException;
 import java.lang.ProcessBuilder.Redirect;
@@ -314,5 +315,8 @@
                 String relativeDbgFileName = relativeFileName + "." + debugExt;

-                Files.write(resourceFileBinary, resource.contentBytes());
+                try (InputStream in = resource.content()) {
+                    Files.copy(in, resourceFileBinary);
+                }
+
                 Path resourceFileDebugSymbols;
                 if (includeDebug) {


Testing: tools/jlink, tools/jpackage, jdk-submit (running)

--
Thanks,
-Aleksey

Reply | Threaded
Open this post in threaded view
|

Re: RFR (XS) 8241462: StripNativeDebugSymbols jlink plugin allocates huge arrays

Alan Bateman
On 23/03/2020 19:22, Aleksey Shipilev wrote:

> :
>
> +import java.io.InputStream;
>   import java.io.IOException;
>   import java.lang.ProcessBuilder.Redirect;
> @@ -314,5 +315,8 @@
>                   String relativeDbgFileName = relativeFileName + "." + debugExt;
>
> -                Files.write(resourceFileBinary, resource.contentBytes());
> +                try (InputStream in = resource.content()) {
> +                    Files.copy(in, resourceFileBinary);
> +                }
> +
>                   Path resourceFileDebugSymbols;
>                   if (includeDebug) {
>
This looks okay.

-Alan.
Reply | Threaded
Open this post in threaded view
|

Re: RFR (XS) 8241462: StripNativeDebugSymbols jlink plugin allocates huge arrays

Aleksey Shipilev-3
On 3/23/20 9:35 PM, Alan Bateman wrote:

> On 23/03/2020 19:22, Aleksey Shipilev wrote:
>> +import java.io.InputStream;
>>   import java.io.IOException;
>>   import java.lang.ProcessBuilder.Redirect;
>> @@ -314,5 +315,8 @@
>>                   String relativeDbgFileName = relativeFileName + "." + debugExt;
>>
>> -                Files.write(resourceFileBinary, resource.contentBytes());
>> +                try (InputStream in = resource.content()) {
>> +                    Files.copy(in, resourceFileBinary);
>> +                }
>> +
>>                   Path resourceFileDebugSymbols;
>>                   if (includeDebug) {
>>
> This looks okay.

Thanks Alan.

Severin, you're good with this?

--
-Aleksey

Reply | Threaded
Open this post in threaded view
|

Re: RFR (XS) 8241462: StripNativeDebugSymbols jlink plugin allocates huge arrays

Severin Gehwolf
On Tue, 2020-03-24 at 12:03 +0100, Aleksey Shipilev wrote:

> On 3/23/20 9:35 PM, Alan Bateman wrote:
> > On 23/03/2020 19:22, Aleksey Shipilev wrote:
> > > +import java.io.InputStream;
> > >   import java.io.IOException;
> > >   import java.lang.ProcessBuilder.Redirect;
> > > @@ -314,5 +315,8 @@
> > >                   String relativeDbgFileName = relativeFileName + "." + debugExt;
> > >
> > > -                Files.write(resourceFileBinary, resource.contentBytes());
> > > +                try (InputStream in = resource.content()) {
> > > +                    Files.copy(in, resourceFileBinary);
> > > +                }
> > > +
> > >                   Path resourceFileDebugSymbols;
> > >                   if (includeDebug) {
> > >
> > This looks okay.
>
> Thanks Alan.
>
> Severin, you're good with this?

Looks good.

Thanks,
Severin

Reply | Threaded
Open this post in threaded view
|

Re: RFR (XS) 8241462: StripNativeDebugSymbols jlink plugin allocates huge arrays

Aleksey Shipilev-3
On 3/24/20 6:40 PM, Severin Gehwolf wrote:

> On Tue, 2020-03-24 at 12:03 +0100, Aleksey Shipilev wrote:
>> On 3/23/20 9:35 PM, Alan Bateman wrote:
>>> On 23/03/2020 19:22, Aleksey Shipilev wrote:
>>>> +import java.io.InputStream;
>>>>   import java.io.IOException;
>>>>   import java.lang.ProcessBuilder.Redirect;
>>>> @@ -314,5 +315,8 @@
>>>>                   String relativeDbgFileName = relativeFileName + "." + debugExt;
>>>>
>>>> -                Files.write(resourceFileBinary, resource.contentBytes());
>>>> +                try (InputStream in = resource.content()) {
>>>> +                    Files.copy(in, resourceFileBinary);
>>>> +                }
>>>> +
>>>>                   Path resourceFileDebugSymbols;
>>>>                   if (includeDebug) {
>>>>
>>> This looks okay.
>>
>> Thanks Alan.
>>
>> Severin, you're good with this?
>
> Looks good.

Thanks!

--
-Aleksey