RFR(S): 8186293: [aix] Fix thread creation with huge stack sizes

Lindenmaier, Goetz goetz.lindenmaier at sap.com
Thu Aug 17 08:41:52 UTC 2017


Hi Thomas, 

the purpose of my fix is to make the behavior more similar.

For -XX:ThreadStackSize=40000000000 you get in both dbg and opt:

on aix:
[0.226s][warning][os,thread] The thread stack size specified is invalid: 40000000000k
[0.226s][warning][os,thread] Failed to start thread - pthread_create failed (22=EINVAL) for attributes: stacksize: 192k, guardsize: 4k, detached.
Error occurred during initialization of VM
java.lang.OutOfMemoryError...

on linux:
[0.225s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 400000000k, guardsize: 0k, detached.
Error occurred during initialization of VM
java.lang.OutOfMemoryError...

Note the stack sizes reported.

I think the assertion on linux is only theoretical, as the function 
succeeds setting even impossible values. What else should
go wrong? attr != NULL is obvious.

You must remove the upper range limit from ThreadStackSize to reproduce this easily.
In jdk9, this upper range limit is missing.

Best regards,
  Goetz.


> -----Original Message-----
> From: David Holmes [mailto:david.holmes at oracle.com]
> Sent: Thursday, August 17, 2017 9:23 AM
> To: Thomas Stüfe <thomas.stuefe at gmail.com>; Lindenmaier, Goetz
> <goetz.lindenmaier at sap.com>
> Cc: hotspot-runtime-dev at openjdk.java.net
> Subject: Re: RFR(S): 8186293: [aix] Fix thread creation with huge stack sizes
> 
> Hi Thomas,
> 
> On 17/08/2017 5:07 PM, Thomas Stüfe wrote:
> >
> > On Thu, Aug 17, 2017 at 8:52 AM, Lindenmaier, Goetz
> > <goetz.lindenmaier at sap.com <mailto:goetz.lindenmaier at sap.com>>
> wrote:
> >
> >     Hi David,
> >
> >     > I wonder whether a fatal error "Error occurred during initialization of
> >     > VM" would not be better than just logging a warning?
> >     I skip thread creation if the error code is != 0 and return false as it
> >     happens on linux. So you see the exact same behavior. Only I
> >     print the additional message about the stack size because that
> >     is missing from the pthread attr which is reported (as setting it
> >     failed).
> >
> >
> > Platforms seem to have different behaviour now:
> >
> > AIX debug (with your patch): if either one of
> > pthread_attr_setstacksize(), pthread_attr_setguardsize or pthread_create
> > fails, we log a warning and return an error.
> > AIX release: ditto.
> >
> > Linux debug: if pthread_attr_setstacksize fails, we assert. We ignore
> > errors from pthread_attr_setguardsize. If pthread_create fails, we log a
> > warning and return an error.
> > Linux release: We ignore errors from both pthread_attr_setstacksize and
> > pthread_attr_setguardsize. If pthread_create fails, we log a warning and
> > return an error.
> 
> To me the asserts are there to catch basic usage errors that indicate a
> general programming bug (eg something uninitialized). They will also
> catch an "illegal argument" if the API detects that, but that is secondary.
> 
> If pthread_create fails we do as you say, but if this is a system
> problem (like bad -Xss) then it will fail the first JavaThread  creation
> and we will get the "Error occurred during initialization".
> 
> > I think it would be nice to have consistent behavior for all platforms.
> 
> Yes consistency would be nice but if one platform has more error
> checking then another then we'd have to drop assertions, even if we
> don't ever expect a failure on that platform.
> 
> > Not sure if this needs to be done with this patch here. As for an "Error
> > occurred during initialization" (debug only or release too?) - can we be
> > sure this only happens at initialization? Could it not be possible for
> > java threads with different stack sizes to be started later, and
> > triggering the same error?
> 
> I would expect a large stacksize passed to j.l.Thread constructor to
> also be able to trigger this. But bad -Xss/-XX:ThreadStackSize will
> cause initialization to fail.
> 
> > I think I prefer to always have a runtime error (both in debug and
> > release builds), as Goetz did in his current AIX patch. And maybe have a
> > sensible Exception text.
> 
> If pthread_create fails we have no detail as to exactly why. If
> pthread_attr_setstacksize does then we have a reasonable idea. So not
> sure what you would suggest.
> 
> But in any case, as you suggest, this would all be a separate
> enhancement request.
> 
> Cheers,
> David
> 
> > Kind Regards, Thomas
> >
> >
> >     I removed the reference to linux, although I find it useful to
> >     point out such unexpected differences.
> >     http://cr.openjdk.java.net/~goetz/wr17/8186293-
> aixHugeStack/webrev.02/
> >     <http://cr.openjdk.java.net/~goetz/wr17/8186293-
> aixHugeStack/webrev.02/>
> >
> >     Best regards,
> >        Goetz.
> >
> >
> >
> >
> >      > -----Original Message-----
> >      > From: David Holmes [mailto:david.holmes at oracle.com
> >     <mailto:david.holmes at oracle.com>]
> >      > Sent: Wednesday, August 16, 2017 10:54 PM
> >      > To: Lindenmaier, Goetz <goetz.lindenmaier at sap.com
> >     <mailto:goetz.lindenmaier at sap.com>>; hotspot-runtime-
> >      > dev at openjdk.java.net <mailto:dev at openjdk.java.net>
> >      > Subject: Re: RFR(S): 8186293: [aix] Fix thread creation with huge
> >     stack sizes
> >      >
> >      > On 17/08/2017 12:24 AM, Lindenmaier, Goetz wrote:
> >      > > Hi,
> >      > >
> >      > > TestOptionWithRanges causes the vm on aix to crash on some
> >     machines.
> >      > > This is because huge stack sizes are not treated properly.
> >      > >
> >      > > On linux, pthread_attr_setstacksize succeeds if called with
> >     huge values, but
> >      > > pthread_create() then fails. On Aix, pthread_attr_setstacksize
> >     fails if
> >      > > passed a value exceeding the limits and leaves the minimal system
> >      >
> >      > The AIX behaviour is more in spirit with POSIX.
> >      >
> >      > > thread stack size in attr. Thus thread creation succeeds and
> >     leads to
> >      > > crashes after thread creation when the guard pages shall be
> >     protected
> >      > > but don't fit on the tiny stack created.
> >      > >
> >      > > Please review this small, aix-only change.
> >      > > http://cr.openjdk.java.net/~goetz/wr17/8186293-
> >     <http://cr.openjdk.java.net/~goetz/wr17/8186293->
> >      > aixHugeStack/webrev.01/
> >      >
> >      > I wonder whether a fatal error "Error occurred during
> >     initialization of
> >      > VM" would not be better than just logging a warning?
> >      >
> >      > As Thomas notes, no need to discuss/describe what may or may not
> >     happen
> >      > on other platforms.
> >      >
> >      > Cheers,
> >      > David
> >      >
> >      > > Best regards,
> >      > >    Goetz.
> >      > >
> >
> >


More information about the hotspot-runtime-dev mailing list