openadk.patch 248 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036
  1. diff -Nur icedtea-2.4.7.orig/Makefile.in icedtea-2.4.7/Makefile.in
  2. --- icedtea-2.4.7.orig/Makefile.in 2014-04-16 06:20:44.689988653 +0200
  3. +++ icedtea-2.4.7/Makefile.in 2014-05-01 13:34:58.421434811 +0200
  4. @@ -712,7 +712,7 @@
  5. $(am__append_14) $(am__append_15) $(DISTRIBUTION_PATCHES)
  6. # Bootstrapping patches
  7. -ICEDTEA_BOOT_PATCHES = patches/boot/javafiles.patch \
  8. +ICEDTEA_BOOT_PATCHES = patches/openadk.patch patches/boot/javafiles.patch \
  9. patches/boot/ant-javac.patch patches/boot/corba-idlj.patch \
  10. patches/boot/corba-no-gen.patch patches/boot/corba-orb.patch \
  11. patches/boot/demos.patch patches/boot/fphexconstants.patch \
  12. diff -Nur icedtea-2.4.7.orig/patches/openadk.patch icedtea-2.4.7/patches/openadk.patch
  13. --- icedtea-2.4.7.orig/patches/openadk.patch 1970-01-01 01:00:00.000000000 +0100
  14. +++ icedtea-2.4.7/patches/openadk.patch 2014-05-15 15:52:54.503242117 +0200
  15. @@ -0,0 +1,7020 @@
  16. +diff -Nur openjdk.orig/hotspot/make/linux/makefiles/zeroshark.make openjdk/hotspot/make/linux/makefiles/zeroshark.make
  17. +--- openjdk.orig/hotspot/make/linux/makefiles/zeroshark.make 2014-02-20 19:51:45.000000000 +0100
  18. ++++ openjdk/hotspot/make/linux/makefiles/zeroshark.make 2014-05-13 16:56:38.917714592 +0200
  19. +@@ -39,20 +39,20 @@
  20. +
  21. + offsets_arm.s: mkoffsets
  22. + @echo Generating assembler offsets
  23. +- ./mkoffsets > $@
  24. ++ $(QEMU) ./mkoffsets > $@
  25. +
  26. + bytecodes_arm.s: bytecodes_arm.def mkbc
  27. + @echo Generating ARM assembler bytecode sequences
  28. +- $(CXX_COMPILE) -E -x c++ - < $< | ./mkbc - $@ $(COMPILE_DONE)
  29. ++ $(CXX_COMPILE) -E -x c++ - < $< | $(QEMU) ./mkbc - $@ $(COMPILE_DONE)
  30. +
  31. + mkbc: $(GAMMADIR)/tools/mkbc.c
  32. + @echo Compiling mkbc tool
  33. +- $(CC_COMPILE) -o $@ $< $(COMPILE_DONE)
  34. ++ $(CC_COMPILE) -static -o $@ $< $(COMPILE_DONE)
  35. +
  36. + mkoffsets: asm_helper.cpp
  37. + @echo Compiling offset generator
  38. + $(QUIETLY) $(REMOVE_TARGET)
  39. +- $(CXX_COMPILE) -DSTATIC_OFFSETS -o $@ $< $(COMPILE_DONE)
  40. ++ $(CXX_COMPILE) -static -DSTATIC_OFFSETS -o $@ $< $(COMPILE_DONE)
  41. +
  42. + endif
  43. + endif
  44. +diff -Nur openjdk.orig/hotspot/src/os/linux/vm/os_linux.cpp openjdk/hotspot/src/os/linux/vm/os_linux.cpp
  45. +--- openjdk.orig/hotspot/src/os/linux/vm/os_linux.cpp 2014-02-20 19:51:45.000000000 +0100
  46. ++++ openjdk/hotspot/src/os/linux/vm/os_linux.cpp 2014-05-13 16:14:56.637091447 +0200
  47. +@@ -112,7 +112,6 @@
  48. + # include <string.h>
  49. + # include <syscall.h>
  50. + # include <sys/sysinfo.h>
  51. +-# include <gnu/libc-version.h>
  52. + # include <sys/ipc.h>
  53. + # include <sys/shm.h>
  54. + # include <link.h>
  55. +@@ -650,9 +649,7 @@
  56. + os::Linux::set_glibc_version(str);
  57. + } else {
  58. + // _CS_GNU_LIBC_VERSION is not supported, try gnu_get_libc_version()
  59. +- static char _gnu_libc_version[32];
  60. +- jio_snprintf(_gnu_libc_version, sizeof(_gnu_libc_version),
  61. +- "glibc %s %s", gnu_get_libc_version(), gnu_get_libc_release());
  62. ++ static char _gnu_libc_version[32] = "2.9";
  63. + os::Linux::set_glibc_version(_gnu_libc_version);
  64. + }
  65. +
  66. +@@ -2951,10 +2948,7 @@
  67. + // If we are running with earlier version, which did not have symbol versions,
  68. + // we should use the base version.
  69. + void* os::Linux::libnuma_dlsym(void* handle, const char *name) {
  70. +- void *f = dlvsym(handle, name, "libnuma_1.1");
  71. +- if (f == NULL) {
  72. +- f = dlsym(handle, name);
  73. +- }
  74. ++ void *f = dlsym(handle, name);
  75. + return f;
  76. + }
  77. +
  78. +@@ -5329,7 +5323,21 @@
  79. + // Linux doesn't yet have a (official) notion of processor sets,
  80. + // so just return the system wide load average.
  81. + int os::loadavg(double loadavg[], int nelem) {
  82. +- return ::getloadavg(loadavg, nelem);
  83. ++ FILE *LOADAVG;
  84. ++ double avg[3] = { 0.0, 0.0, 0.0 };
  85. ++ int i, res = -1;;
  86. ++
  87. ++ if ((LOADAVG = fopen("/proc/loadavg", "r"))) {
  88. ++ fscanf(LOADAVG, "%lf %lf %lf", &avg[0], &avg[1], &avg[2]);
  89. ++ res = 0;
  90. ++ fclose(LOADAVG);
  91. ++ }
  92. ++
  93. ++ for (i = 0; (i < nelem) && (i < 3); i++) {
  94. ++ loadavg[i] = avg[i];
  95. ++ }
  96. ++
  97. ++ return res;
  98. + }
  99. +
  100. + void os::pause() {
  101. +diff -Nur openjdk.orig/hotspot/src/os/linux/vm/os_linux.cpp.orig openjdk/hotspot/src/os/linux/vm/os_linux.cpp.orig
  102. +--- openjdk.orig/hotspot/src/os/linux/vm/os_linux.cpp.orig 1970-01-01 01:00:00.000000000 +0100
  103. ++++ openjdk/hotspot/src/os/linux/vm/os_linux.cpp.orig 2014-02-20 19:51:45.000000000 +0100
  104. +@@ -0,0 +1,5989 @@
  105. ++/*
  106. ++ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
  107. ++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  108. ++ *
  109. ++ * This code is free software; you can redistribute it and/or modify it
  110. ++ * under the terms of the GNU General Public License version 2 only, as
  111. ++ * published by the Free Software Foundation.
  112. ++ *
  113. ++ * This code is distributed in the hope that it will be useful, but WITHOUT
  114. ++ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  115. ++ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  116. ++ * version 2 for more details (a copy is included in the LICENSE file that
  117. ++ * accompanied this code).
  118. ++ *
  119. ++ * You should have received a copy of the GNU General Public License version
  120. ++ * 2 along with this work; if not, write to the Free Software Foundation,
  121. ++ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  122. ++ *
  123. ++ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  124. ++ * or visit www.oracle.com if you need additional information or have any
  125. ++ * questions.
  126. ++ *
  127. ++ */
  128. ++
  129. ++// no precompiled headers
  130. ++#include "classfile/classLoader.hpp"
  131. ++#include "classfile/systemDictionary.hpp"
  132. ++#include "classfile/vmSymbols.hpp"
  133. ++#include "code/icBuffer.hpp"
  134. ++#include "code/vtableStubs.hpp"
  135. ++#include "compiler/compileBroker.hpp"
  136. ++#include "interpreter/interpreter.hpp"
  137. ++#include "jvm_linux.h"
  138. ++#include "memory/allocation.inline.hpp"
  139. ++#include "memory/filemap.hpp"
  140. ++#include "mutex_linux.inline.hpp"
  141. ++#include "oops/oop.inline.hpp"
  142. ++#include "os_share_linux.hpp"
  143. ++#include "prims/jniFastGetField.hpp"
  144. ++#include "prims/jvm.h"
  145. ++#include "prims/jvm_misc.hpp"
  146. ++#include "runtime/arguments.hpp"
  147. ++#include "runtime/extendedPC.hpp"
  148. ++#include "runtime/globals.hpp"
  149. ++#include "runtime/interfaceSupport.hpp"
  150. ++#include "runtime/init.hpp"
  151. ++#include "runtime/java.hpp"
  152. ++#include "runtime/javaCalls.hpp"
  153. ++#include "runtime/mutexLocker.hpp"
  154. ++#include "runtime/objectMonitor.hpp"
  155. ++#include "runtime/osThread.hpp"
  156. ++#include "runtime/perfMemory.hpp"
  157. ++#include "runtime/sharedRuntime.hpp"
  158. ++#include "runtime/statSampler.hpp"
  159. ++#include "runtime/stubRoutines.hpp"
  160. ++#include "runtime/threadCritical.hpp"
  161. ++#include "runtime/timer.hpp"
  162. ++#include "services/attachListener.hpp"
  163. ++#include "services/memTracker.hpp"
  164. ++#include "services/runtimeService.hpp"
  165. ++#include "thread_linux.inline.hpp"
  166. ++#include "utilities/decoder.hpp"
  167. ++#include "utilities/defaultStream.hpp"
  168. ++#include "utilities/events.hpp"
  169. ++#include "utilities/elfFile.hpp"
  170. ++#include "utilities/growableArray.hpp"
  171. ++#include "utilities/vmError.hpp"
  172. ++#ifdef TARGET_ARCH_x86
  173. ++# include "assembler_x86.inline.hpp"
  174. ++# include "nativeInst_x86.hpp"
  175. ++#endif
  176. ++#ifdef TARGET_ARCH_sparc
  177. ++# include "assembler_sparc.inline.hpp"
  178. ++# include "nativeInst_sparc.hpp"
  179. ++#endif
  180. ++#ifdef TARGET_ARCH_zero
  181. ++# include "assembler_zero.inline.hpp"
  182. ++# include "nativeInst_zero.hpp"
  183. ++#endif
  184. ++#ifdef TARGET_ARCH_arm
  185. ++# include "assembler_arm.inline.hpp"
  186. ++# include "nativeInst_arm.hpp"
  187. ++#endif
  188. ++#ifdef TARGET_ARCH_ppc
  189. ++# include "assembler_ppc.inline.hpp"
  190. ++# include "nativeInst_ppc.hpp"
  191. ++#endif
  192. ++
  193. ++// put OS-includes here
  194. ++# include <sys/types.h>
  195. ++# include <sys/mman.h>
  196. ++# include <sys/stat.h>
  197. ++# include <sys/select.h>
  198. ++# include <pthread.h>
  199. ++# include <signal.h>
  200. ++# include <errno.h>
  201. ++# include <dlfcn.h>
  202. ++# include <stdio.h>
  203. ++# include <unistd.h>
  204. ++# include <sys/resource.h>
  205. ++# include <pthread.h>
  206. ++# include <sys/stat.h>
  207. ++# include <sys/time.h>
  208. ++# include <sys/times.h>
  209. ++# include <sys/utsname.h>
  210. ++# include <sys/socket.h>
  211. ++# include <sys/wait.h>
  212. ++# include <pwd.h>
  213. ++# include <poll.h>
  214. ++# include <semaphore.h>
  215. ++# include <fcntl.h>
  216. ++# include <string.h>
  217. ++# include <syscall.h>
  218. ++# include <sys/sysinfo.h>
  219. ++# include <gnu/libc-version.h>
  220. ++# include <sys/ipc.h>
  221. ++# include <sys/shm.h>
  222. ++# include <link.h>
  223. ++# include <stdint.h>
  224. ++# include <inttypes.h>
  225. ++# include <sys/ioctl.h>
  226. ++
  227. ++#define MAX_PATH (2 * K)
  228. ++
  229. ++// for timer info max values which include all bits
  230. ++#define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
  231. ++
  232. ++#define LARGEPAGES_BIT (1 << 6)
  233. ++
  234. ++#ifndef EM_AARCH64
  235. ++#define EM_AARCH64 183 /* ARM AARCH64 */
  236. ++#endif
  237. ++
  238. ++////////////////////////////////////////////////////////////////////////////////
  239. ++// global variables
  240. ++julong os::Linux::_physical_memory = 0;
  241. ++
  242. ++address os::Linux::_initial_thread_stack_bottom = NULL;
  243. ++uintptr_t os::Linux::_initial_thread_stack_size = 0;
  244. ++
  245. ++int (*os::Linux::_clock_gettime)(clockid_t, struct timespec *) = NULL;
  246. ++int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
  247. ++Mutex* os::Linux::_createThread_lock = NULL;
  248. ++pthread_t os::Linux::_main_thread;
  249. ++int os::Linux::_page_size = -1;
  250. ++const int os::Linux::_vm_default_page_size = (8 * K);
  251. ++bool os::Linux::_is_floating_stack = false;
  252. ++bool os::Linux::_is_NPTL = false;
  253. ++bool os::Linux::_supports_fast_thread_cpu_time = false;
  254. ++const char * os::Linux::_glibc_version = NULL;
  255. ++const char * os::Linux::_libpthread_version = NULL;
  256. ++
  257. ++static jlong initial_time_count=0;
  258. ++
  259. ++static int clock_tics_per_sec = 100;
  260. ++
  261. ++// For diagnostics to print a message once. see run_periodic_checks
  262. ++static sigset_t check_signal_done;
  263. ++static bool check_signals = true;;
  264. ++
  265. ++static pid_t _initial_pid = 0;
  266. ++
  267. ++/* Signal number used to suspend/resume a thread */
  268. ++
  269. ++/* do not use any signal number less than SIGSEGV, see 4355769 */
  270. ++static int SR_signum = SIGUSR2;
  271. ++sigset_t SR_sigset;
  272. ++
  273. ++/* Used to protect dlsym() calls */
  274. ++static pthread_mutex_t dl_mutex;
  275. ++
  276. ++// Declarations
  277. ++static void unpackTime(timespec* absTime, bool isAbsolute, jlong time);
  278. ++
  279. ++#ifdef JAVASE_EMBEDDED
  280. ++class MemNotifyThread: public Thread {
  281. ++ friend class VMStructs;
  282. ++ public:
  283. ++ virtual void run();
  284. ++
  285. ++ private:
  286. ++ static MemNotifyThread* _memnotify_thread;
  287. ++ int _fd;
  288. ++
  289. ++ public:
  290. ++
  291. ++ // Constructor
  292. ++ MemNotifyThread(int fd);
  293. ++
  294. ++ // Tester
  295. ++ bool is_memnotify_thread() const { return true; }
  296. ++
  297. ++ // Printing
  298. ++ char* name() const { return (char*)"Linux MemNotify Thread"; }
  299. ++
  300. ++ // Returns the single instance of the MemNotifyThread
  301. ++ static MemNotifyThread* memnotify_thread() { return _memnotify_thread; }
  302. ++
  303. ++ // Create and start the single instance of MemNotifyThread
  304. ++ static void start();
  305. ++};
  306. ++#endif // JAVASE_EMBEDDED
  307. ++
  308. ++// utility functions
  309. ++
  310. ++static int SR_initialize();
  311. ++static int SR_finalize();
  312. ++
  313. ++julong os::available_memory() {
  314. ++ return Linux::available_memory();
  315. ++}
  316. ++
  317. ++julong os::Linux::available_memory() {
  318. ++ // values in struct sysinfo are "unsigned long"
  319. ++ struct sysinfo si;
  320. ++ sysinfo(&si);
  321. ++
  322. ++ return (julong)si.freeram * si.mem_unit;
  323. ++}
  324. ++
  325. ++julong os::physical_memory() {
  326. ++ return Linux::physical_memory();
  327. ++}
  328. ++
  329. ++julong os::allocatable_physical_memory(julong size) {
  330. ++#ifdef _LP64
  331. ++ return size;
  332. ++#else
  333. ++ julong result = MIN2(size, (julong)3800*M);
  334. ++ if (!is_allocatable(result)) {
  335. ++ // See comments under solaris for alignment considerations
  336. ++ julong reasonable_size = (julong)2*G - 2 * os::vm_page_size();
  337. ++ result = MIN2(size, reasonable_size);
  338. ++ }
  339. ++ return result;
  340. ++#endif // _LP64
  341. ++}
  342. ++
  343. ++////////////////////////////////////////////////////////////////////////////////
  344. ++// environment support
  345. ++
  346. ++bool os::getenv(const char* name, char* buf, int len) {
  347. ++ const char* val = ::getenv(name);
  348. ++ if (val != NULL && strlen(val) < (size_t)len) {
  349. ++ strcpy(buf, val);
  350. ++ return true;
  351. ++ }
  352. ++ if (len > 0) buf[0] = 0; // return a null string
  353. ++ return false;
  354. ++}
  355. ++
  356. ++
  357. ++// Return true if user is running as root.
  358. ++
  359. ++bool os::have_special_privileges() {
  360. ++ static bool init = false;
  361. ++ static bool privileges = false;
  362. ++ if (!init) {
  363. ++ privileges = (getuid() != geteuid()) || (getgid() != getegid());
  364. ++ init = true;
  365. ++ }
  366. ++ return privileges;
  367. ++}
  368. ++
  369. ++
  370. ++#ifndef SYS_gettid
  371. ++// i386: 224, ia64: 1105, amd64: 186, sparc 143
  372. ++#ifdef __ia64__
  373. ++#define SYS_gettid 1105
  374. ++#elif __i386__
  375. ++#define SYS_gettid 224
  376. ++#elif __amd64__
  377. ++#define SYS_gettid 186
  378. ++#elif __sparc__
  379. ++#define SYS_gettid 143
  380. ++#else
  381. ++#error define gettid for the arch
  382. ++#endif
  383. ++#endif
  384. ++
  385. ++// Cpu architecture string
  386. ++#if defined(ZERO)
  387. ++static char cpu_arch[] = ZERO_LIBARCH;
  388. ++#elif defined(IA64)
  389. ++static char cpu_arch[] = "ia64";
  390. ++#elif defined(IA32)
  391. ++static char cpu_arch[] = "i386";
  392. ++#elif defined(AMD64)
  393. ++static char cpu_arch[] = "amd64";
  394. ++#elif defined(ARM)
  395. ++static char cpu_arch[] = "arm";
  396. ++#elif defined(PPC)
  397. ++static char cpu_arch[] = "ppc";
  398. ++#elif defined(SPARC)
  399. ++# ifdef _LP64
  400. ++static char cpu_arch[] = "sparcv9";
  401. ++# else
  402. ++static char cpu_arch[] = "sparc";
  403. ++# endif
  404. ++#else
  405. ++#error Add appropriate cpu_arch setting
  406. ++#endif
  407. ++
  408. ++
  409. ++// pid_t gettid()
  410. ++//
  411. ++// Returns the kernel thread id of the currently running thread. Kernel
  412. ++// thread id is used to access /proc.
  413. ++//
  414. ++// (Note that getpid() on LinuxThreads returns kernel thread id too; but
  415. ++// on NPTL, it returns the same pid for all threads, as required by POSIX.)
  416. ++//
  417. ++pid_t os::Linux::gettid() {
  418. ++ int rslt = syscall(SYS_gettid);
  419. ++ if (rslt == -1) {
  420. ++ // old kernel, no NPTL support
  421. ++ return getpid();
  422. ++ } else {
  423. ++ return (pid_t)rslt;
  424. ++ }
  425. ++}
  426. ++
  427. ++// Most versions of linux have a bug where the number of processors are
  428. ++// determined by looking at the /proc file system. In a chroot environment,
  429. ++// the system call returns 1. This causes the VM to act as if it is
  430. ++// a single processor and elide locking (see is_MP() call).
  431. ++static bool unsafe_chroot_detected = false;
  432. ++static const char *unstable_chroot_error = "/proc file system not found.\n"
  433. ++ "Java may be unstable running multithreaded in a chroot "
  434. ++ "environment on Linux when /proc filesystem is not mounted.";
  435. ++
  436. ++void os::Linux::initialize_system_info() {
  437. ++ set_processor_count(sysconf(_SC_NPROCESSORS_CONF));
  438. ++ if (processor_count() == 1) {
  439. ++ pid_t pid = os::Linux::gettid();
  440. ++ char fname[32];
  441. ++ jio_snprintf(fname, sizeof(fname), "/proc/%d", pid);
  442. ++ FILE *fp = fopen(fname, "r");
  443. ++ if (fp == NULL) {
  444. ++ unsafe_chroot_detected = true;
  445. ++ } else {
  446. ++ fclose(fp);
  447. ++ }
  448. ++ }
  449. ++ _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE);
  450. ++ assert(processor_count() > 0, "linux error");
  451. ++}
  452. ++
  453. ++void os::init_system_properties_values() {
  454. ++// char arch[12];
  455. ++// sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
  456. ++
  457. ++ // The next steps are taken in the product version:
  458. ++ //
  459. ++ // Obtain the JAVA_HOME value from the location of libjvm[_g].so.
  460. ++ // This library should be located at:
  461. ++ // <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm[_g].so.
  462. ++ //
  463. ++ // If "/jre/lib/" appears at the right place in the path, then we
  464. ++ // assume libjvm[_g].so is installed in a JDK and we use this path.
  465. ++ //
  466. ++ // Otherwise exit with message: "Could not create the Java virtual machine."
  467. ++ //
  468. ++ // The following extra steps are taken in the debugging version:
  469. ++ //
  470. ++ // If "/jre/lib/" does NOT appear at the right place in the path
  471. ++ // instead of exit check for $JAVA_HOME environment variable.
  472. ++ //
  473. ++ // If it is defined and we are able to locate $JAVA_HOME/jre/lib/<arch>,
  474. ++ // then we append a fake suffix "hotspot/libjvm[_g].so" to this path so
  475. ++ // it looks like libjvm[_g].so is installed there
  476. ++ // <JAVA_HOME>/jre/lib/<arch>/hotspot/libjvm[_g].so.
  477. ++ //
  478. ++ // Otherwise exit.
  479. ++ //
  480. ++ // Important note: if the location of libjvm.so changes this
  481. ++ // code needs to be changed accordingly.
  482. ++
  483. ++ // The next few definitions allow the code to be verbatim:
  484. ++#define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal)
  485. ++#define getenv(n) ::getenv(n)
  486. ++
  487. ++/*
  488. ++ * See ld(1):
  489. ++ * The linker uses the following search paths to locate required
  490. ++ * shared libraries:
  491. ++ * 1: ...
  492. ++ * ...
  493. ++ * 7: The default directories, normally /lib and /usr/lib.
  494. ++ */
  495. ++#if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390) || defined(AARCH64))
  496. ++#define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
  497. ++#else
  498. ++#define DEFAULT_LIBPATH "/lib:/usr/lib"
  499. ++#endif
  500. ++
  501. ++#define EXTENSIONS_DIR "/lib/ext"
  502. ++#define ENDORSED_DIR "/lib/endorsed"
  503. ++#define REG_DIR "/usr/java/packages"
  504. ++
  505. ++ {
  506. ++ /* sysclasspath, java_home, dll_dir */
  507. ++ {
  508. ++ char *home_path;
  509. ++ char *dll_path;
  510. ++ char *pslash;
  511. ++ char buf[MAXPATHLEN];
  512. ++ os::jvm_path(buf, sizeof(buf));
  513. ++
  514. ++ // Found the full path to libjvm.so.
  515. ++ // Now cut the path to <java_home>/jre if we can.
  516. ++ *(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */
  517. ++ pslash = strrchr(buf, '/');
  518. ++ if (pslash != NULL)
  519. ++ *pslash = '\0'; /* get rid of /{client|server|hotspot} */
  520. ++ dll_path = malloc(strlen(buf) + 1);
  521. ++ if (dll_path == NULL)
  522. ++ return;
  523. ++ strcpy(dll_path, buf);
  524. ++ Arguments::set_dll_dir(dll_path);
  525. ++
  526. ++ if (pslash != NULL) {
  527. ++ pslash = strrchr(buf, '/');
  528. ++ if (pslash != NULL) {
  529. ++ *pslash = '\0'; /* get rid of /<arch> */
  530. ++ pslash = strrchr(buf, '/');
  531. ++ if (pslash != NULL)
  532. ++ *pslash = '\0'; /* get rid of /lib */
  533. ++ }
  534. ++ }
  535. ++
  536. ++ home_path = malloc(strlen(buf) + 1);
  537. ++ if (home_path == NULL)
  538. ++ return;
  539. ++ strcpy(home_path, buf);
  540. ++ Arguments::set_java_home(home_path);
  541. ++
  542. ++ if (!set_boot_path('/', ':'))
  543. ++ return;
  544. ++ }
  545. ++
  546. ++ /*
  547. ++ * Where to look for native libraries
  548. ++ *
  549. ++ * Note: Due to a legacy implementation, most of the library path
  550. ++ * is set in the launcher. This was to accomodate linking restrictions
  551. ++ * on legacy Linux implementations (which are no longer supported).
  552. ++ * Eventually, all the library path setting will be done here.
  553. ++ *
  554. ++ * However, to prevent the proliferation of improperly built native
  555. ++ * libraries, the new path component /usr/java/packages is added here.
  556. ++ * Eventually, all the library path setting will be done here.
  557. ++ */
  558. ++ {
  559. ++ char *ld_library_path;
  560. ++
  561. ++ /*
  562. ++ * Construct the invariant part of ld_library_path. Note that the
  563. ++ * space for the colon and the trailing null are provided by the
  564. ++ * nulls included by the sizeof operator (so actually we allocate
  565. ++ * a byte more than necessary).
  566. ++ */
  567. ++ ld_library_path = (char *) malloc(sizeof(REG_DIR) + sizeof("/lib/") +
  568. ++ strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH));
  569. ++ sprintf(ld_library_path, REG_DIR "/lib/%s:" DEFAULT_LIBPATH, cpu_arch);
  570. ++
  571. ++ /*
  572. ++ * Get the user setting of LD_LIBRARY_PATH, and prepended it. It
  573. ++ * should always exist (until the legacy problem cited above is
  574. ++ * addressed).
  575. ++ */
  576. ++ char *v = getenv("LD_LIBRARY_PATH");
  577. ++ if (v != NULL) {
  578. ++ char *t = ld_library_path;
  579. ++ /* That's +1 for the colon and +1 for the trailing '\0' */
  580. ++ ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1);
  581. ++ sprintf(ld_library_path, "%s:%s", v, t);
  582. ++ }
  583. ++ Arguments::set_library_path(ld_library_path);
  584. ++ }
  585. ++
  586. ++ /*
  587. ++ * Extensions directories.
  588. ++ *
  589. ++ * Note that the space for the colon and the trailing null are provided
  590. ++ * by the nulls included by the sizeof operator (so actually one byte more
  591. ++ * than necessary is allocated).
  592. ++ */
  593. ++ {
  594. ++ char *buf = malloc(strlen(Arguments::get_java_home()) +
  595. ++ sizeof(EXTENSIONS_DIR) + sizeof(REG_DIR) + sizeof(EXTENSIONS_DIR));
  596. ++ sprintf(buf, "%s" EXTENSIONS_DIR ":" REG_DIR EXTENSIONS_DIR,
  597. ++ Arguments::get_java_home());
  598. ++ Arguments::set_ext_dirs(buf);
  599. ++ }
  600. ++
  601. ++ /* Endorsed standards default directory. */
  602. ++ {
  603. ++ char * buf;
  604. ++ buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR));
  605. ++ sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
  606. ++ Arguments::set_endorsed_dirs(buf);
  607. ++ }
  608. ++ }
  609. ++
  610. ++#undef malloc
  611. ++#undef getenv
  612. ++#undef EXTENSIONS_DIR
  613. ++#undef ENDORSED_DIR
  614. ++
  615. ++ // Done
  616. ++ return;
  617. ++}
  618. ++
  619. ++////////////////////////////////////////////////////////////////////////////////
  620. ++// breakpoint support
  621. ++
  622. ++void os::breakpoint() {
  623. ++ BREAKPOINT;
  624. ++}
  625. ++
  626. ++extern "C" void breakpoint() {
  627. ++ // use debugger to set breakpoint here
  628. ++}
  629. ++
  630. ++////////////////////////////////////////////////////////////////////////////////
  631. ++// signal support
  632. ++
  633. ++debug_only(static bool signal_sets_initialized = false);
  634. ++static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
  635. ++
  636. ++bool os::Linux::is_sig_ignored(int sig) {
  637. ++ struct sigaction oact;
  638. ++ sigaction(sig, (struct sigaction*)NULL, &oact);
  639. ++ void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction)
  640. ++ : CAST_FROM_FN_PTR(void*, oact.sa_handler);
  641. ++ if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN))
  642. ++ return true;
  643. ++ else
  644. ++ return false;
  645. ++}
  646. ++
  647. ++void os::Linux::signal_sets_init() {
  648. ++ // Should also have an assertion stating we are still single-threaded.
  649. ++ assert(!signal_sets_initialized, "Already initialized");
  650. ++ // Fill in signals that are necessarily unblocked for all threads in
  651. ++ // the VM. Currently, we unblock the following signals:
  652. ++ // SHUTDOWN{1,2,3}_SIGNAL: for shutdown hooks support (unless over-ridden
  653. ++ // by -Xrs (=ReduceSignalUsage));
  654. ++ // BREAK_SIGNAL which is unblocked only by the VM thread and blocked by all
  655. ++ // other threads. The "ReduceSignalUsage" boolean tells us not to alter
  656. ++ // the dispositions or masks wrt these signals.
  657. ++ // Programs embedding the VM that want to use the above signals for their
  658. ++ // own purposes must, at this time, use the "-Xrs" option to prevent
  659. ++ // interference with shutdown hooks and BREAK_SIGNAL thread dumping.
  660. ++ // (See bug 4345157, and other related bugs).
  661. ++ // In reality, though, unblocking these signals is really a nop, since
  662. ++ // these signals are not blocked by default.
  663. ++ sigemptyset(&unblocked_sigs);
  664. ++ sigemptyset(&allowdebug_blocked_sigs);
  665. ++ sigaddset(&unblocked_sigs, SIGILL);
  666. ++ sigaddset(&unblocked_sigs, SIGSEGV);
  667. ++ sigaddset(&unblocked_sigs, SIGBUS);
  668. ++ sigaddset(&unblocked_sigs, SIGFPE);
  669. ++ sigaddset(&unblocked_sigs, SR_signum);
  670. ++
  671. ++ if (!ReduceSignalUsage) {
  672. ++ if (!os::Linux::is_sig_ignored(SHUTDOWN1_SIGNAL)) {
  673. ++ sigaddset(&unblocked_sigs, SHUTDOWN1_SIGNAL);
  674. ++ sigaddset(&allowdebug_blocked_sigs, SHUTDOWN1_SIGNAL);
  675. ++ }
  676. ++ if (!os::Linux::is_sig_ignored(SHUTDOWN2_SIGNAL)) {
  677. ++ sigaddset(&unblocked_sigs, SHUTDOWN2_SIGNAL);
  678. ++ sigaddset(&allowdebug_blocked_sigs, SHUTDOWN2_SIGNAL);
  679. ++ }
  680. ++ if (!os::Linux::is_sig_ignored(SHUTDOWN3_SIGNAL)) {
  681. ++ sigaddset(&unblocked_sigs, SHUTDOWN3_SIGNAL);
  682. ++ sigaddset(&allowdebug_blocked_sigs, SHUTDOWN3_SIGNAL);
  683. ++ }
  684. ++ }
  685. ++ // Fill in signals that are blocked by all but the VM thread.
  686. ++ sigemptyset(&vm_sigs);
  687. ++ if (!ReduceSignalUsage)
  688. ++ sigaddset(&vm_sigs, BREAK_SIGNAL);
  689. ++ debug_only(signal_sets_initialized = true);
  690. ++
  691. ++}
  692. ++
  693. ++// These are signals that are unblocked while a thread is running Java.
  694. ++// (For some reason, they get blocked by default.)
  695. ++sigset_t* os::Linux::unblocked_signals() {
  696. ++ assert(signal_sets_initialized, "Not initialized");
  697. ++ return &unblocked_sigs;
  698. ++}
  699. ++
  700. ++// These are the signals that are blocked while a (non-VM) thread is
  701. ++// running Java. Only the VM thread handles these signals.
  702. ++sigset_t* os::Linux::vm_signals() {
  703. ++ assert(signal_sets_initialized, "Not initialized");
  704. ++ return &vm_sigs;
  705. ++}
  706. ++
  707. ++// These are signals that are blocked during cond_wait to allow debugger in
  708. ++sigset_t* os::Linux::allowdebug_blocked_signals() {
  709. ++ assert(signal_sets_initialized, "Not initialized");
  710. ++ return &allowdebug_blocked_sigs;
  711. ++}
  712. ++
  713. ++void os::Linux::hotspot_sigmask(Thread* thread) {
  714. ++
  715. ++ //Save caller's signal mask before setting VM signal mask
  716. ++ sigset_t caller_sigmask;
  717. ++ pthread_sigmask(SIG_BLOCK, NULL, &caller_sigmask);
  718. ++
  719. ++ OSThread* osthread = thread->osthread();
  720. ++ osthread->set_caller_sigmask(caller_sigmask);
  721. ++
  722. ++ pthread_sigmask(SIG_UNBLOCK, os::Linux::unblocked_signals(), NULL);
  723. ++
  724. ++ if (!ReduceSignalUsage) {
  725. ++ if (thread->is_VM_thread()) {
  726. ++ // Only the VM thread handles BREAK_SIGNAL ...
  727. ++ pthread_sigmask(SIG_UNBLOCK, vm_signals(), NULL);
  728. ++ } else {
  729. ++ // ... all other threads block BREAK_SIGNAL
  730. ++ pthread_sigmask(SIG_BLOCK, vm_signals(), NULL);
  731. ++ }
  732. ++ }
  733. ++}
  734. ++
  735. ++//////////////////////////////////////////////////////////////////////////////
  736. ++// detecting pthread library
  737. ++
  738. ++void os::Linux::libpthread_init() {
  739. ++ // Save glibc and pthread version strings. Note that _CS_GNU_LIBC_VERSION
  740. ++ // and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a
  741. ++ // generic name for earlier versions.
  742. ++ // Define macros here so we can build HotSpot on old systems.
  743. ++# ifndef _CS_GNU_LIBC_VERSION
  744. ++# define _CS_GNU_LIBC_VERSION 2
  745. ++# endif
  746. ++# ifndef _CS_GNU_LIBPTHREAD_VERSION
  747. ++# define _CS_GNU_LIBPTHREAD_VERSION 3
  748. ++# endif
  749. ++
  750. ++ size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0);
  751. ++ if (n > 0) {
  752. ++ char *str = (char *)malloc(n, mtInternal);
  753. ++ confstr(_CS_GNU_LIBC_VERSION, str, n);
  754. ++ os::Linux::set_glibc_version(str);
  755. ++ } else {
  756. ++ // _CS_GNU_LIBC_VERSION is not supported, try gnu_get_libc_version()
  757. ++ static char _gnu_libc_version[32];
  758. ++ jio_snprintf(_gnu_libc_version, sizeof(_gnu_libc_version),
  759. ++ "glibc %s %s", gnu_get_libc_version(), gnu_get_libc_release());
  760. ++ os::Linux::set_glibc_version(_gnu_libc_version);
  761. ++ }
  762. ++
  763. ++ n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
  764. ++ if (n > 0) {
  765. ++ char *str = (char *)malloc(n, mtInternal);
  766. ++ confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n);
  767. ++ // Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells
  768. ++ // us "NPTL-0.29" even we are running with LinuxThreads. Check if this
  769. ++ // is the case. LinuxThreads has a hard limit on max number of threads.
  770. ++ // So sysconf(_SC_THREAD_THREADS_MAX) will return a positive value.
  771. ++ // On the other hand, NPTL does not have such a limit, sysconf()
  772. ++ // will return -1 and errno is not changed. Check if it is really NPTL.
  773. ++ if (strcmp(os::Linux::glibc_version(), "glibc 2.3.2") == 0 &&
  774. ++ strstr(str, "NPTL") &&
  775. ++ sysconf(_SC_THREAD_THREADS_MAX) > 0) {
  776. ++ free(str);
  777. ++ os::Linux::set_libpthread_version("linuxthreads");
  778. ++ } else {
  779. ++ os::Linux::set_libpthread_version(str);
  780. ++ }
  781. ++ } else {
  782. ++ // glibc before 2.3.2 only has LinuxThreads.
  783. ++ os::Linux::set_libpthread_version("linuxthreads");
  784. ++ }
  785. ++
  786. ++ if (strstr(libpthread_version(), "NPTL")) {
  787. ++ os::Linux::set_is_NPTL();
  788. ++ } else {
  789. ++ os::Linux::set_is_LinuxThreads();
  790. ++ }
  791. ++
  792. ++ // LinuxThreads have two flavors: floating-stack mode, which allows variable
  793. ++ // stack size; and fixed-stack mode. NPTL is always floating-stack.
  794. ++ if (os::Linux::is_NPTL() || os::Linux::supports_variable_stack_size()) {
  795. ++ os::Linux::set_is_floating_stack();
  796. ++ }
  797. ++}
  798. ++
  799. ++/////////////////////////////////////////////////////////////////////////////
  800. ++// thread stack
  801. ++
  802. ++// Force Linux kernel to expand current thread stack. If "bottom" is close
  803. ++// to the stack guard, caller should block all signals.
  804. ++//
  805. ++// MAP_GROWSDOWN:
  806. ++// A special mmap() flag that is used to implement thread stacks. It tells
  807. ++// kernel that the memory region should extend downwards when needed. This
  808. ++// allows early versions of LinuxThreads to only mmap the first few pages
  809. ++// when creating a new thread. Linux kernel will automatically expand thread
  810. ++// stack as needed (on page faults).
  811. ++//
  812. ++// However, because the memory region of a MAP_GROWSDOWN stack can grow on
  813. ++// demand, if a page fault happens outside an already mapped MAP_GROWSDOWN
  814. ++// region, it's hard to tell if the fault is due to a legitimate stack
  815. ++// access or because of reading/writing non-exist memory (e.g. buffer
  816. ++// overrun). As a rule, if the fault happens below current stack pointer,
  817. ++// Linux kernel does not expand stack, instead a SIGSEGV is sent to the
  818. ++// application (see Linux kernel fault.c).
  819. ++//
  820. ++// This Linux feature can cause SIGSEGV when VM bangs thread stack for
  821. ++// stack overflow detection.
  822. ++//
  823. ++// Newer version of LinuxThreads (since glibc-2.2, or, RH-7.x) and NPTL do
  824. ++// not use this flag. However, the stack of initial thread is not created
  825. ++// by pthread, it is still MAP_GROWSDOWN. Also it's possible (though
  826. ++// unlikely) that user code can create a thread with MAP_GROWSDOWN stack
  827. ++// and then attach the thread to JVM.
  828. ++//
  829. ++// To get around the problem and allow stack banging on Linux, we need to
  830. ++// manually expand thread stack after receiving the SIGSEGV.
  831. ++//
  832. ++// There are two ways to expand thread stack to address "bottom", we used
  833. ++// both of them in JVM before 1.5:
  834. ++// 1. adjust stack pointer first so that it is below "bottom", and then
  835. ++// touch "bottom"
  836. ++// 2. mmap() the page in question
  837. ++//
  838. ++// Now alternate signal stack is gone, it's harder to use 2. For instance,
  839. ++// if current sp is already near the lower end of page 101, and we need to
  840. ++// call mmap() to map page 100, it is possible that part of the mmap() frame
  841. ++// will be placed in page 100. When page 100 is mapped, it is zero-filled.
  842. ++// That will destroy the mmap() frame and cause VM to crash.
  843. ++//
  844. ++// The following code works by adjusting sp first, then accessing the "bottom"
  845. ++// page to force a page fault. Linux kernel will then automatically expand the
  846. ++// stack mapping.
  847. ++//
  848. ++// _expand_stack_to() assumes its frame size is less than page size, which
  849. ++// should always be true if the function is not inlined.
  850. ++
  851. ++#if __GNUC__ < 3 // gcc 2.x does not support noinline attribute
  852. ++#define NOINLINE
  853. ++#else
  854. ++#define NOINLINE __attribute__ ((noinline))
  855. ++#endif
  856. ++
  857. ++static void _expand_stack_to(address bottom) NOINLINE;
  858. ++
  859. ++static void _expand_stack_to(address bottom) {
  860. ++ address sp;
  861. ++ size_t size;
  862. ++ volatile char *p;
  863. ++
  864. ++ // Adjust bottom to point to the largest address within the same page, it
  865. ++ // gives us a one-page buffer if alloca() allocates slightly more memory.
  866. ++ bottom = (address)align_size_down((uintptr_t)bottom, os::Linux::page_size());
  867. ++ bottom += os::Linux::page_size() - 1;
  868. ++
  869. ++ // sp might be slightly above current stack pointer; if that's the case, we
  870. ++ // will alloca() a little more space than necessary, which is OK. Don't use
  871. ++ // os::current_stack_pointer(), as its result can be slightly below current
  872. ++ // stack pointer, causing us to not alloca enough to reach "bottom".
  873. ++ sp = (address)&sp;
  874. ++
  875. ++ if (sp > bottom) {
  876. ++ size = sp - bottom;
  877. ++ p = (volatile char *)alloca(size);
  878. ++ assert(p != NULL && p <= (volatile char *)bottom, "alloca problem?");
  879. ++ p[0] = '\0';
  880. ++ }
  881. ++}
  882. ++
  883. ++bool os::Linux::manually_expand_stack(JavaThread * t, address addr) {
  884. ++ assert(t!=NULL, "just checking");
  885. ++ assert(t->osthread()->expanding_stack(), "expand should be set");
  886. ++ assert(t->stack_base() != NULL, "stack_base was not initialized");
  887. ++
  888. ++ if (addr < t->stack_base() && addr >= t->stack_yellow_zone_base()) {
  889. ++ sigset_t mask_all, old_sigset;
  890. ++ sigfillset(&mask_all);
  891. ++ pthread_sigmask(SIG_SETMASK, &mask_all, &old_sigset);
  892. ++ _expand_stack_to(addr);
  893. ++ pthread_sigmask(SIG_SETMASK, &old_sigset, NULL);
  894. ++ return true;
  895. ++ }
  896. ++ return false;
  897. ++}
  898. ++
  899. ++//////////////////////////////////////////////////////////////////////////////
  900. ++// create new thread
  901. ++
  902. ++static address highest_vm_reserved_address();
  903. ++
  904. ++// check if it's safe to start a new thread
  905. ++static bool _thread_safety_check(Thread* thread) {
  906. ++ if (os::Linux::is_LinuxThreads() && !os::Linux::is_floating_stack()) {
  907. ++ // Fixed stack LinuxThreads (SuSE Linux/x86, and some versions of Redhat)
  908. ++ // Heap is mmap'ed at lower end of memory space. Thread stacks are
  909. ++ // allocated (MAP_FIXED) from high address space. Every thread stack
  910. ++ // occupies a fixed size slot (usually 2Mbytes, but user can change
  911. ++ // it to other values if they rebuild LinuxThreads).
  912. ++ //
  913. ++ // Problem with MAP_FIXED is that mmap() can still succeed even part of
  914. ++ // the memory region has already been mmap'ed. That means if we have too
  915. ++ // many threads and/or very large heap, eventually thread stack will
  916. ++ // collide with heap.
  917. ++ //
  918. ++ // Here we try to prevent heap/stack collision by comparing current
  919. ++ // stack bottom with the highest address that has been mmap'ed by JVM
  920. ++ // plus a safety margin for memory maps created by native code.
  921. ++ //
  922. ++ // This feature can be disabled by setting ThreadSafetyMargin to 0
  923. ++ //
  924. ++ if (ThreadSafetyMargin > 0) {
  925. ++ address stack_bottom = os::current_stack_base() - os::current_stack_size();
  926. ++
  927. ++ // not safe if our stack extends below the safety margin
  928. ++ return stack_bottom - ThreadSafetyMargin >= highest_vm_reserved_address();
  929. ++ } else {
  930. ++ return true;
  931. ++ }
  932. ++ } else {
  933. ++ // Floating stack LinuxThreads or NPTL:
  934. ++ // Unlike fixed stack LinuxThreads, thread stacks are not MAP_FIXED. When
  935. ++ // there's not enough space left, pthread_create() will fail. If we come
  936. ++ // here, that means enough space has been reserved for stack.
  937. ++ return true;
  938. ++ }
  939. ++}
  940. ++
  941. ++// Thread start routine for all newly created threads
  942. ++static void *java_start(Thread *thread) {
  943. ++ // Try to randomize the cache line index of hot stack frames.
  944. ++ // This helps when threads of the same stack traces evict each other's
  945. ++ // cache lines. The threads can be either from the same JVM instance, or
  946. ++ // from different JVM instances. The benefit is especially true for
  947. ++ // processors with hyperthreading technology.
  948. ++ static int counter = 0;
  949. ++ int pid = os::current_process_id();
  950. ++ alloca(((pid ^ counter++) & 7) * 128);
  951. ++
  952. ++ ThreadLocalStorage::set_thread(thread);
  953. ++
  954. ++ OSThread* osthread = thread->osthread();
  955. ++ Monitor* sync = osthread->startThread_lock();
  956. ++
  957. ++ // non floating stack LinuxThreads needs extra check, see above
  958. ++ if (!_thread_safety_check(thread)) {
  959. ++ // notify parent thread
  960. ++ MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag);
  961. ++ osthread->set_state(ZOMBIE);
  962. ++ sync->notify_all();
  963. ++ return NULL;
  964. ++ }
  965. ++
  966. ++ // thread_id is kernel thread id (similar to Solaris LWP id)
  967. ++ osthread->set_thread_id(os::Linux::gettid());
  968. ++
  969. ++ if (UseNUMA) {
  970. ++ int lgrp_id = os::numa_get_group_id();
  971. ++ if (lgrp_id != -1) {
  972. ++ thread->set_lgrp_id(lgrp_id);
  973. ++ }
  974. ++ }
  975. ++ // initialize signal mask for this thread
  976. ++ os::Linux::hotspot_sigmask(thread);
  977. ++
  978. ++ // initialize floating point control register
  979. ++ os::Linux::init_thread_fpu_state();
  980. ++
  981. ++ // handshaking with parent thread
  982. ++ {
  983. ++ MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag);
  984. ++
  985. ++ // notify parent thread
  986. ++ osthread->set_state(INITIALIZED);
  987. ++ sync->notify_all();
  988. ++
  989. ++ // wait until os::start_thread()
  990. ++ while (osthread->get_state() == INITIALIZED) {
  991. ++ sync->wait(Mutex::_no_safepoint_check_flag);
  992. ++ }
  993. ++ }
  994. ++
  995. ++ // call one more level start routine
  996. ++ thread->run();
  997. ++
  998. ++ return 0;
  999. ++}
  1000. ++
  1001. ++bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
  1002. ++ assert(thread->osthread() == NULL, "caller responsible");
  1003. ++
  1004. ++ // Allocate the OSThread object
  1005. ++ OSThread* osthread = new OSThread(NULL, NULL);
  1006. ++ if (osthread == NULL) {
  1007. ++ return false;
  1008. ++ }
  1009. ++
  1010. ++ // set the correct thread state
  1011. ++ osthread->set_thread_type(thr_type);
  1012. ++
  1013. ++ // Initial state is ALLOCATED but not INITIALIZED
  1014. ++ osthread->set_state(ALLOCATED);
  1015. ++
  1016. ++ thread->set_osthread(osthread);
  1017. ++
  1018. ++ // init thread attributes
  1019. ++ pthread_attr_t attr;
  1020. ++ pthread_attr_init(&attr);
  1021. ++ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  1022. ++
  1023. ++ // stack size
  1024. ++ if (os::Linux::supports_variable_stack_size()) {
  1025. ++ // calculate stack size if it's not specified by caller
  1026. ++ if (stack_size == 0) {
  1027. ++ stack_size = os::Linux::default_stack_size(thr_type);
  1028. ++
  1029. ++ switch (thr_type) {
  1030. ++ case os::java_thread:
  1031. ++ // Java threads use ThreadStackSize which default value can be
  1032. ++ // changed with the flag -Xss
  1033. ++ assert (JavaThread::stack_size_at_create() > 0, "this should be set");
  1034. ++ stack_size = JavaThread::stack_size_at_create();
  1035. ++ break;
  1036. ++ case os::compiler_thread:
  1037. ++ if (CompilerThreadStackSize > 0) {
  1038. ++ stack_size = (size_t)(CompilerThreadStackSize * K);
  1039. ++ break;
  1040. ++ } // else fall through:
  1041. ++ // use VMThreadStackSize if CompilerThreadStackSize is not defined
  1042. ++ case os::vm_thread:
  1043. ++ case os::pgc_thread:
  1044. ++ case os::cgc_thread:
  1045. ++ case os::watcher_thread:
  1046. ++ if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
  1047. ++ break;
  1048. ++ }
  1049. ++ }
  1050. ++
  1051. ++ stack_size = MAX2(stack_size, os::Linux::min_stack_allowed);
  1052. ++ pthread_attr_setstacksize(&attr, stack_size);
  1053. ++ } else {
  1054. ++ // let pthread_create() pick the default value.
  1055. ++ }
  1056. ++
  1057. ++ // glibc guard page
  1058. ++ pthread_attr_setguardsize(&attr, os::Linux::default_guard_size(thr_type));
  1059. ++
  1060. ++ ThreadState state;
  1061. ++
  1062. ++ {
  1063. ++ // Serialize thread creation if we are running with fixed stack LinuxThreads
  1064. ++ bool lock = os::Linux::is_LinuxThreads() && !os::Linux::is_floating_stack();
  1065. ++ if (lock) {
  1066. ++ os::Linux::createThread_lock()->lock_without_safepoint_check();
  1067. ++ }
  1068. ++
  1069. ++ pthread_t tid;
  1070. ++ int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
  1071. ++
  1072. ++ pthread_attr_destroy(&attr);
  1073. ++
  1074. ++ if (ret != 0) {
  1075. ++ if (PrintMiscellaneous && (Verbose || WizardMode)) {
  1076. ++ perror("pthread_create()");
  1077. ++ }
  1078. ++ // Need to clean up stuff we've allocated so far
  1079. ++ thread->set_osthread(NULL);
  1080. ++ delete osthread;
  1081. ++ if (lock) os::Linux::createThread_lock()->unlock();
  1082. ++ return false;
  1083. ++ }
  1084. ++
  1085. ++ // Store pthread info into the OSThread
  1086. ++ osthread->set_pthread_id(tid);
  1087. ++
  1088. ++ // Wait until child thread is either initialized or aborted
  1089. ++ {
  1090. ++ Monitor* sync_with_child = osthread->startThread_lock();
  1091. ++ MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag);
  1092. ++ while ((state = osthread->get_state()) == ALLOCATED) {
  1093. ++ sync_with_child->wait(Mutex::_no_safepoint_check_flag);
  1094. ++ }
  1095. ++ }
  1096. ++
  1097. ++ if (lock) {
  1098. ++ os::Linux::createThread_lock()->unlock();
  1099. ++ }
  1100. ++ }
  1101. ++
  1102. ++ // Aborted due to thread limit being reached
  1103. ++ if (state == ZOMBIE) {
  1104. ++ thread->set_osthread(NULL);
  1105. ++ delete osthread;
  1106. ++ return false;
  1107. ++ }
  1108. ++
  1109. ++ // The thread is returned suspended (in state INITIALIZED),
  1110. ++ // and is started higher up in the call chain
  1111. ++ assert(state == INITIALIZED, "race condition");
  1112. ++ return true;
  1113. ++}
  1114. ++
  1115. ++/////////////////////////////////////////////////////////////////////////////
  1116. ++// attach existing thread
  1117. ++
  1118. ++// bootstrap the main thread
  1119. ++bool os::create_main_thread(JavaThread* thread) {
  1120. ++ assert(os::Linux::_main_thread == pthread_self(), "should be called inside main thread");
  1121. ++ return create_attached_thread(thread);
  1122. ++}
  1123. ++
  1124. ++bool os::create_attached_thread(JavaThread* thread) {
  1125. ++#ifdef ASSERT
  1126. ++ thread->verify_not_published();
  1127. ++#endif
  1128. ++
  1129. ++ // Allocate the OSThread object
  1130. ++ OSThread* osthread = new OSThread(NULL, NULL);
  1131. ++
  1132. ++ if (osthread == NULL) {
  1133. ++ return false;
  1134. ++ }
  1135. ++
  1136. ++ // Store pthread info into the OSThread
  1137. ++ osthread->set_thread_id(os::Linux::gettid());
  1138. ++ osthread->set_pthread_id(::pthread_self());
  1139. ++
  1140. ++ // initialize floating point control register
  1141. ++ os::Linux::init_thread_fpu_state();
  1142. ++
  1143. ++ // Initial thread state is RUNNABLE
  1144. ++ osthread->set_state(RUNNABLE);
  1145. ++
  1146. ++ thread->set_osthread(osthread);
  1147. ++
  1148. ++ if (UseNUMA) {
  1149. ++ int lgrp_id = os::numa_get_group_id();
  1150. ++ if (lgrp_id != -1) {
  1151. ++ thread->set_lgrp_id(lgrp_id);
  1152. ++ }
  1153. ++ }
  1154. ++
  1155. ++ if (os::Linux::is_initial_thread()) {
  1156. ++ // If current thread is initial thread, its stack is mapped on demand,
  1157. ++ // see notes about MAP_GROWSDOWN. Here we try to force kernel to map
  1158. ++ // the entire stack region to avoid SEGV in stack banging.
  1159. ++ // It is also useful to get around the heap-stack-gap problem on SuSE
  1160. ++ // kernel (see 4821821 for details). We first expand stack to the top
  1161. ++ // of yellow zone, then enable stack yellow zone (order is significant,
  1162. ++ // enabling yellow zone first will crash JVM on SuSE Linux), so there
  1163. ++ // is no gap between the last two virtual memory regions.
  1164. ++
  1165. ++ JavaThread *jt = (JavaThread *)thread;
  1166. ++ address addr = jt->stack_yellow_zone_base();
  1167. ++ assert(addr != NULL, "initialization problem?");
  1168. ++ assert(jt->stack_available(addr) > 0, "stack guard should not be enabled");
  1169. ++
  1170. ++ osthread->set_expanding_stack();
  1171. ++ os::Linux::manually_expand_stack(jt, addr);
  1172. ++ osthread->clear_expanding_stack();
  1173. ++ }
  1174. ++
  1175. ++ // initialize signal mask for this thread
  1176. ++ // and save the caller's signal mask
  1177. ++ os::Linux::hotspot_sigmask(thread);
  1178. ++
  1179. ++ return true;
  1180. ++}
  1181. ++
  1182. ++void os::pd_start_thread(Thread* thread) {
  1183. ++ OSThread * osthread = thread->osthread();
  1184. ++ assert(osthread->get_state() != INITIALIZED, "just checking");
  1185. ++ Monitor* sync_with_child = osthread->startThread_lock();
  1186. ++ MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag);
  1187. ++ sync_with_child->notify();
  1188. ++}
  1189. ++
  1190. ++// Free Linux resources related to the OSThread
  1191. ++void os::free_thread(OSThread* osthread) {
  1192. ++ assert(osthread != NULL, "osthread not set");
  1193. ++
  1194. ++ if (Thread::current()->osthread() == osthread) {
  1195. ++ // Restore caller's signal mask
  1196. ++ sigset_t sigmask = osthread->caller_sigmask();
  1197. ++ pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
  1198. ++ }
  1199. ++
  1200. ++ delete osthread;
  1201. ++}
  1202. ++
  1203. ++//////////////////////////////////////////////////////////////////////////////
  1204. ++// thread local storage
  1205. ++
  1206. ++int os::allocate_thread_local_storage() {
  1207. ++ pthread_key_t key;
  1208. ++ int rslt = pthread_key_create(&key, NULL);
  1209. ++ assert(rslt == 0, "cannot allocate thread local storage");
  1210. ++ return (int)key;
  1211. ++}
  1212. ++
  1213. ++// Note: This is currently not used by VM, as we don't destroy TLS key
  1214. ++// on VM exit.
  1215. ++void os::free_thread_local_storage(int index) {
  1216. ++ int rslt = pthread_key_delete((pthread_key_t)index);
  1217. ++ assert(rslt == 0, "invalid index");
  1218. ++}
  1219. ++
  1220. ++void os::thread_local_storage_at_put(int index, void* value) {
  1221. ++ int rslt = pthread_setspecific((pthread_key_t)index, value);
  1222. ++ assert(rslt == 0, "pthread_setspecific failed");
  1223. ++}
  1224. ++
  1225. ++extern "C" Thread* get_thread() {
  1226. ++ return ThreadLocalStorage::thread();
  1227. ++}
  1228. ++
  1229. ++//////////////////////////////////////////////////////////////////////////////
  1230. ++// initial thread
  1231. ++
  1232. ++// Check if current thread is the initial thread, similar to Solaris thr_main.
  1233. ++bool os::Linux::is_initial_thread(void) {
  1234. ++ char dummy;
  1235. ++ // If called before init complete, thread stack bottom will be null.
  1236. ++ // Can be called if fatal error occurs before initialization.
  1237. ++ if (initial_thread_stack_bottom() == NULL) return false;
  1238. ++ assert(initial_thread_stack_bottom() != NULL &&
  1239. ++ initial_thread_stack_size() != 0,
  1240. ++ "os::init did not locate initial thread's stack region");
  1241. ++ if ((address)&dummy >= initial_thread_stack_bottom() &&
  1242. ++ (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size())
  1243. ++ return true;
  1244. ++ else return false;
  1245. ++}
  1246. ++
  1247. ++// Find the virtual memory area that contains addr
  1248. ++static bool find_vma(address addr, address* vma_low, address* vma_high) {
  1249. ++ FILE *fp = fopen("/proc/self/maps", "r");
  1250. ++ if (fp) {
  1251. ++ address low, high;
  1252. ++ while (!feof(fp)) {
  1253. ++ if (fscanf(fp, "%p-%p", &low, &high) == 2) {
  1254. ++ if (low <= addr && addr < high) {
  1255. ++ if (vma_low) *vma_low = low;
  1256. ++ if (vma_high) *vma_high = high;
  1257. ++ fclose (fp);
  1258. ++ return true;
  1259. ++ }
  1260. ++ }
  1261. ++ for (;;) {
  1262. ++ int ch = fgetc(fp);
  1263. ++ if (ch == EOF || ch == (int)'\n') break;
  1264. ++ }
  1265. ++ }
  1266. ++ fclose(fp);
  1267. ++ }
  1268. ++ return false;
  1269. ++}
  1270. ++
  1271. ++// Locate initial thread stack. This special handling of initial thread stack
  1272. ++// is needed because pthread_getattr_np() on most (all?) Linux distros returns
  1273. ++// bogus value for initial thread.
  1274. ++void os::Linux::capture_initial_stack(size_t max_size) {
  1275. ++ // stack size is the easy part, get it from RLIMIT_STACK
  1276. ++ size_t stack_size;
  1277. ++ struct rlimit rlim;
  1278. ++ getrlimit(RLIMIT_STACK, &rlim);
  1279. ++ stack_size = rlim.rlim_cur;
  1280. ++
  1281. ++ // 6308388: a bug in ld.so will relocate its own .data section to the
  1282. ++ // lower end of primordial stack; reduce ulimit -s value a little bit
  1283. ++ // so we won't install guard page on ld.so's data section.
  1284. ++ stack_size -= 2 * page_size();
  1285. ++
  1286. ++ // 4441425: avoid crash with "unlimited" stack size on SuSE 7.1 or Redhat
  1287. ++ // 7.1, in both cases we will get 2G in return value.
  1288. ++ // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0,
  1289. ++ // SuSE 7.2, Debian) can not handle alternate signal stack correctly
  1290. ++ // for initial thread if its stack size exceeds 6M. Cap it at 2M,
  1291. ++ // in case other parts in glibc still assumes 2M max stack size.
  1292. ++ // FIXME: alt signal stack is gone, maybe we can relax this constraint?
  1293. ++#ifndef IA64
  1294. ++ if (stack_size > 2 * K * K) stack_size = 2 * K * K;
  1295. ++#else
  1296. ++ // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small
  1297. ++ if (stack_size > 4 * K * K) stack_size = 4 * K * K;
  1298. ++#endif
  1299. ++
  1300. ++ // Try to figure out where the stack base (top) is. This is harder.
  1301. ++ //
  1302. ++ // When an application is started, glibc saves the initial stack pointer in
  1303. ++ // a global variable "__libc_stack_end", which is then used by system
  1304. ++ // libraries. __libc_stack_end should be pretty close to stack top. The
  1305. ++ // variable is available since the very early days. However, because it is
  1306. ++ // a private interface, it could disappear in the future.
  1307. ++ //
  1308. ++ // Linux kernel saves start_stack information in /proc/<pid>/stat. Similar
  1309. ++ // to __libc_stack_end, it is very close to stack top, but isn't the real
  1310. ++ // stack top. Note that /proc may not exist if VM is running as a chroot
  1311. ++ // program, so reading /proc/<pid>/stat could fail. Also the contents of
  1312. ++ // /proc/<pid>/stat could change in the future (though unlikely).
  1313. ++ //
  1314. ++ // We try __libc_stack_end first. If that doesn't work, look for
  1315. ++ // /proc/<pid>/stat. If neither of them works, we use current stack pointer
  1316. ++ // as a hint, which should work well in most cases.
  1317. ++
  1318. ++ uintptr_t stack_start;
  1319. ++
  1320. ++ // try __libc_stack_end first
  1321. ++ uintptr_t *p = (uintptr_t *)dlsym(RTLD_DEFAULT, "__libc_stack_end");
  1322. ++ if (p && *p) {
  1323. ++ stack_start = *p;
  1324. ++ } else {
  1325. ++ // see if we can get the start_stack field from /proc/self/stat
  1326. ++ FILE *fp;
  1327. ++ int pid;
  1328. ++ char state;
  1329. ++ int ppid;
  1330. ++ int pgrp;
  1331. ++ int session;
  1332. ++ int nr;
  1333. ++ int tpgrp;
  1334. ++ unsigned long flags;
  1335. ++ unsigned long minflt;
  1336. ++ unsigned long cminflt;
  1337. ++ unsigned long majflt;
  1338. ++ unsigned long cmajflt;
  1339. ++ unsigned long utime;
  1340. ++ unsigned long stime;
  1341. ++ long cutime;
  1342. ++ long cstime;
  1343. ++ long prio;
  1344. ++ long nice;
  1345. ++ long junk;
  1346. ++ long it_real;
  1347. ++ uintptr_t start;
  1348. ++ uintptr_t vsize;
  1349. ++ intptr_t rss;
  1350. ++ uintptr_t rsslim;
  1351. ++ uintptr_t scodes;
  1352. ++ uintptr_t ecode;
  1353. ++ int i;
  1354. ++
  1355. ++ // Figure what the primordial thread stack base is. Code is inspired
  1356. ++ // by email from Hans Boehm. /proc/self/stat begins with current pid,
  1357. ++ // followed by command name surrounded by parentheses, state, etc.
  1358. ++ char stat[2048];
  1359. ++ int statlen;
  1360. ++
  1361. ++ fp = fopen("/proc/self/stat", "r");
  1362. ++ if (fp) {
  1363. ++ statlen = fread(stat, 1, 2047, fp);
  1364. ++ stat[statlen] = '\0';
  1365. ++ fclose(fp);
  1366. ++
  1367. ++ // Skip pid and the command string. Note that we could be dealing with
  1368. ++ // weird command names, e.g. user could decide to rename java launcher
  1369. ++ // to "java 1.4.2 :)", then the stat file would look like
  1370. ++ // 1234 (java 1.4.2 :)) R ... ...
  1371. ++ // We don't really need to know the command string, just find the last
  1372. ++ // occurrence of ")" and then start parsing from there. See bug 4726580.
  1373. ++ char * s = strrchr(stat, ')');
  1374. ++
  1375. ++ i = 0;
  1376. ++ if (s) {
  1377. ++ // Skip blank chars
  1378. ++ do s++; while (isspace(*s));
  1379. ++
  1380. ++#define _UFM UINTX_FORMAT
  1381. ++#define _DFM INTX_FORMAT
  1382. ++
  1383. ++ /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 */
  1384. ++ /* 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 */
  1385. ++ i = sscanf(s, "%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld " _UFM _UFM _DFM _UFM _UFM _UFM _UFM,
  1386. ++ &state, /* 3 %c */
  1387. ++ &ppid, /* 4 %d */
  1388. ++ &pgrp, /* 5 %d */
  1389. ++ &session, /* 6 %d */
  1390. ++ &nr, /* 7 %d */
  1391. ++ &tpgrp, /* 8 %d */
  1392. ++ &flags, /* 9 %lu */
  1393. ++ &minflt, /* 10 %lu */
  1394. ++ &cminflt, /* 11 %lu */
  1395. ++ &majflt, /* 12 %lu */
  1396. ++ &cmajflt, /* 13 %lu */
  1397. ++ &utime, /* 14 %lu */
  1398. ++ &stime, /* 15 %lu */
  1399. ++ &cutime, /* 16 %ld */
  1400. ++ &cstime, /* 17 %ld */
  1401. ++ &prio, /* 18 %ld */
  1402. ++ &nice, /* 19 %ld */
  1403. ++ &junk, /* 20 %ld */
  1404. ++ &it_real, /* 21 %ld */
  1405. ++ &start, /* 22 UINTX_FORMAT */
  1406. ++ &vsize, /* 23 UINTX_FORMAT */
  1407. ++ &rss, /* 24 INTX_FORMAT */
  1408. ++ &rsslim, /* 25 UINTX_FORMAT */
  1409. ++ &scodes, /* 26 UINTX_FORMAT */
  1410. ++ &ecode, /* 27 UINTX_FORMAT */
  1411. ++ &stack_start); /* 28 UINTX_FORMAT */
  1412. ++ }
  1413. ++
  1414. ++#undef _UFM
  1415. ++#undef _DFM
  1416. ++
  1417. ++ if (i != 28 - 2) {
  1418. ++ assert(false, "Bad conversion from /proc/self/stat");
  1419. ++ // product mode - assume we are the initial thread, good luck in the
  1420. ++ // embedded case.
  1421. ++ warning("Can't detect initial thread stack location - bad conversion");
  1422. ++ stack_start = (uintptr_t) &rlim;
  1423. ++ }
  1424. ++ } else {
  1425. ++ // For some reason we can't open /proc/self/stat (for example, running on
  1426. ++ // FreeBSD with a Linux emulator, or inside chroot), this should work for
  1427. ++ // most cases, so don't abort:
  1428. ++ warning("Can't detect initial thread stack location - no /proc/self/stat");
  1429. ++ stack_start = (uintptr_t) &rlim;
  1430. ++ }
  1431. ++ }
  1432. ++
  1433. ++ // Now we have a pointer (stack_start) very close to the stack top, the
  1434. ++ // next thing to do is to figure out the exact location of stack top. We
  1435. ++ // can find out the virtual memory area that contains stack_start by
  1436. ++ // reading /proc/self/maps, it should be the last vma in /proc/self/maps,
  1437. ++ // and its upper limit is the real stack top. (again, this would fail if
  1438. ++ // running inside chroot, because /proc may not exist.)
  1439. ++
  1440. ++ uintptr_t stack_top;
  1441. ++ address low, high;
  1442. ++ if (find_vma((address)stack_start, &low, &high)) {
  1443. ++ // success, "high" is the true stack top. (ignore "low", because initial
  1444. ++ // thread stack grows on demand, its real bottom is high - RLIMIT_STACK.)
  1445. ++ stack_top = (uintptr_t)high;
  1446. ++ } else {
  1447. ++ // failed, likely because /proc/self/maps does not exist
  1448. ++ warning("Can't detect initial thread stack location - find_vma failed");
  1449. ++ // best effort: stack_start is normally within a few pages below the real
  1450. ++ // stack top, use it as stack top, and reduce stack size so we won't put
  1451. ++ // guard page outside stack.
  1452. ++ stack_top = stack_start;
  1453. ++ stack_size -= 16 * page_size();
  1454. ++ }
  1455. ++
  1456. ++ // stack_top could be partially down the page so align it
  1457. ++ stack_top = align_size_up(stack_top, page_size());
  1458. ++
  1459. ++ if (max_size && stack_size > max_size) {
  1460. ++ _initial_thread_stack_size = max_size;
  1461. ++ } else {
  1462. ++ _initial_thread_stack_size = stack_size;
  1463. ++ }
  1464. ++
  1465. ++ _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size());
  1466. ++ _initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size;
  1467. ++}
  1468. ++
  1469. ++////////////////////////////////////////////////////////////////////////////////
  1470. ++// time support
  1471. ++
  1472. ++// Time since start-up in seconds to a fine granularity.
  1473. ++// Used by VMSelfDestructTimer and the MemProfiler.
  1474. ++double os::elapsedTime() {
  1475. ++
  1476. ++ return (double)(os::elapsed_counter()) * 0.000001;
  1477. ++}
  1478. ++
  1479. ++jlong os::elapsed_counter() {
  1480. ++ timeval time;
  1481. ++ int status = gettimeofday(&time, NULL);
  1482. ++ return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count;
  1483. ++}
  1484. ++
  1485. ++jlong os::elapsed_frequency() {
  1486. ++ return (1000 * 1000);
  1487. ++}
  1488. ++
  1489. ++// For now, we say that linux does not support vtime. I have no idea
  1490. ++// whether it can actually be made to (DLD, 9/13/05).
  1491. ++
  1492. ++bool os::supports_vtime() { return false; }
  1493. ++bool os::enable_vtime() { return false; }
  1494. ++bool os::vtime_enabled() { return false; }
  1495. ++double os::elapsedVTime() {
  1496. ++ // better than nothing, but not much
  1497. ++ return elapsedTime();
  1498. ++}
  1499. ++
  1500. ++jlong os::javaTimeMillis() {
  1501. ++ timeval time;
  1502. ++ int status = gettimeofday(&time, NULL);
  1503. ++ assert(status != -1, "linux error");
  1504. ++ return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000);
  1505. ++}
  1506. ++
  1507. ++#ifndef CLOCK_MONOTONIC
  1508. ++#define CLOCK_MONOTONIC (1)
  1509. ++#endif
  1510. ++
  1511. ++void os::Linux::clock_init() {
  1512. ++ // we do dlopen's in this particular order due to bug in linux
  1513. ++ // dynamical loader (see 6348968) leading to crash on exit
  1514. ++ void* handle = dlopen("librt.so.1", RTLD_LAZY);
  1515. ++ if (handle == NULL) {
  1516. ++ handle = dlopen("librt.so", RTLD_LAZY);
  1517. ++ }
  1518. ++
  1519. ++ if (handle) {
  1520. ++ int (*clock_getres_func)(clockid_t, struct timespec*) =
  1521. ++ (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_getres");
  1522. ++ int (*clock_gettime_func)(clockid_t, struct timespec*) =
  1523. ++ (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_gettime");
  1524. ++ if (clock_getres_func && clock_gettime_func) {
  1525. ++ // See if monotonic clock is supported by the kernel. Note that some
  1526. ++ // early implementations simply return kernel jiffies (updated every
  1527. ++ // 1/100 or 1/1000 second). It would be bad to use such a low res clock
  1528. ++ // for nano time (though the monotonic property is still nice to have).
  1529. ++ // It's fixed in newer kernels, however clock_getres() still returns
  1530. ++ // 1/HZ. We check if clock_getres() works, but will ignore its reported
  1531. ++ // resolution for now. Hopefully as people move to new kernels, this
  1532. ++ // won't be a problem.
  1533. ++ struct timespec res;
  1534. ++ struct timespec tp;
  1535. ++ if (clock_getres_func (CLOCK_MONOTONIC, &res) == 0 &&
  1536. ++ clock_gettime_func(CLOCK_MONOTONIC, &tp) == 0) {
  1537. ++ // yes, monotonic clock is supported
  1538. ++ _clock_gettime = clock_gettime_func;
  1539. ++ } else {
  1540. ++ // close librt if there is no monotonic clock
  1541. ++ dlclose(handle);
  1542. ++ }
  1543. ++ }
  1544. ++ }
  1545. ++}
  1546. ++
  1547. ++#ifndef SYS_clock_getres
  1548. ++
  1549. ++#if defined(IA32) || defined(AMD64)
  1550. ++#define SYS_clock_getres IA32_ONLY(266) AMD64_ONLY(229)
  1551. ++#define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y)
  1552. ++#else
  1553. ++#warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
  1554. ++#define sys_clock_getres(x,y) -1
  1555. ++#endif
  1556. ++
  1557. ++#else
  1558. ++#define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y)
  1559. ++#endif
  1560. ++
  1561. ++void os::Linux::fast_thread_clock_init() {
  1562. ++ if (!UseLinuxPosixThreadCPUClocks) {
  1563. ++ return;
  1564. ++ }
  1565. ++ clockid_t clockid;
  1566. ++ struct timespec tp;
  1567. ++ int (*pthread_getcpuclockid_func)(pthread_t, clockid_t *) =
  1568. ++ (int(*)(pthread_t, clockid_t *)) dlsym(RTLD_DEFAULT, "pthread_getcpuclockid");
  1569. ++
  1570. ++ // Switch to using fast clocks for thread cpu time if
  1571. ++ // the sys_clock_getres() returns 0 error code.
  1572. ++ // Note, that some kernels may support the current thread
  1573. ++ // clock (CLOCK_THREAD_CPUTIME_ID) but not the clocks
  1574. ++ // returned by the pthread_getcpuclockid().
  1575. ++ // If the fast Posix clocks are supported then the sys_clock_getres()
  1576. ++ // must return at least tp.tv_sec == 0 which means a resolution
  1577. ++ // better than 1 sec. This is extra check for reliability.
  1578. ++
  1579. ++ if(pthread_getcpuclockid_func &&
  1580. ++ pthread_getcpuclockid_func(_main_thread, &clockid) == 0 &&
  1581. ++ sys_clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) {
  1582. ++
  1583. ++ _supports_fast_thread_cpu_time = true;
  1584. ++ _pthread_getcpuclockid = pthread_getcpuclockid_func;
  1585. ++ }
  1586. ++}
  1587. ++
  1588. ++jlong os::javaTimeNanos() {
  1589. ++ if (Linux::supports_monotonic_clock()) {
  1590. ++ struct timespec tp;
  1591. ++ int status = Linux::clock_gettime(CLOCK_MONOTONIC, &tp);
  1592. ++ assert(status == 0, "gettime error");
  1593. ++ jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec);
  1594. ++ return result;
  1595. ++ } else {
  1596. ++ timeval time;
  1597. ++ int status = gettimeofday(&time, NULL);
  1598. ++ assert(status != -1, "linux error");
  1599. ++ jlong usecs = jlong(time.tv_sec) * (1000 * 1000) + jlong(time.tv_usec);
  1600. ++ return 1000 * usecs;
  1601. ++ }
  1602. ++}
  1603. ++
  1604. ++void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
  1605. ++ if (Linux::supports_monotonic_clock()) {
  1606. ++ info_ptr->max_value = ALL_64_BITS;
  1607. ++
  1608. ++ // CLOCK_MONOTONIC - amount of time since some arbitrary point in the past
  1609. ++ info_ptr->may_skip_backward = false; // not subject to resetting or drifting
  1610. ++ info_ptr->may_skip_forward = false; // not subject to resetting or drifting
  1611. ++ } else {
  1612. ++ // gettimeofday - based on time in seconds since the Epoch thus does not wrap
  1613. ++ info_ptr->max_value = ALL_64_BITS;
  1614. ++
  1615. ++ // gettimeofday is a real time clock so it skips
  1616. ++ info_ptr->may_skip_backward = true;
  1617. ++ info_ptr->may_skip_forward = true;
  1618. ++ }
  1619. ++
  1620. ++ info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
  1621. ++}
  1622. ++
  1623. ++// Return the real, user, and system times in seconds from an
  1624. ++// arbitrary fixed point in the past.
  1625. ++bool os::getTimesSecs(double* process_real_time,
  1626. ++ double* process_user_time,
  1627. ++ double* process_system_time) {
  1628. ++ struct tms ticks;
  1629. ++ clock_t real_ticks = times(&ticks);
  1630. ++
  1631. ++ if (real_ticks == (clock_t) (-1)) {
  1632. ++ return false;
  1633. ++ } else {
  1634. ++ double ticks_per_second = (double) clock_tics_per_sec;
  1635. ++ *process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
  1636. ++ *process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
  1637. ++ *process_real_time = ((double) real_ticks) / ticks_per_second;
  1638. ++
  1639. ++ return true;
  1640. ++ }
  1641. ++}
  1642. ++
  1643. ++
  1644. ++char * os::local_time_string(char *buf, size_t buflen) {
  1645. ++ struct tm t;
  1646. ++ time_t long_time;
  1647. ++ time(&long_time);
  1648. ++ localtime_r(&long_time, &t);
  1649. ++ jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
  1650. ++ t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
  1651. ++ t.tm_hour, t.tm_min, t.tm_sec);
  1652. ++ return buf;
  1653. ++}
  1654. ++
  1655. ++struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
  1656. ++ return localtime_r(clock, res);
  1657. ++}
  1658. ++
  1659. ++////////////////////////////////////////////////////////////////////////////////
  1660. ++// runtime exit support
  1661. ++
  1662. ++// Note: os::shutdown() might be called very early during initialization, or
  1663. ++// called from signal handler. Before adding something to os::shutdown(), make
  1664. ++// sure it is async-safe and can handle partially initialized VM.
  1665. ++void os::shutdown() {
  1666. ++
  1667. ++ // allow PerfMemory to attempt cleanup of any persistent resources
  1668. ++ perfMemory_exit();
  1669. ++
  1670. ++ // needs to remove object in file system
  1671. ++ AttachListener::abort();
  1672. ++
  1673. ++ // flush buffered output, finish log files
  1674. ++ ostream_abort();
  1675. ++
  1676. ++ // Check for abort hook
  1677. ++ abort_hook_t abort_hook = Arguments::abort_hook();
  1678. ++ if (abort_hook != NULL) {
  1679. ++ abort_hook();
  1680. ++ }
  1681. ++
  1682. ++}
  1683. ++
  1684. ++// Note: os::abort() might be called very early during initialization, or
  1685. ++// called from signal handler. Before adding something to os::abort(), make
  1686. ++// sure it is async-safe and can handle partially initialized VM.
  1687. ++void os::abort(bool dump_core) {
  1688. ++ os::shutdown();
  1689. ++ if (dump_core) {
  1690. ++#ifndef PRODUCT
  1691. ++ fdStream out(defaultStream::output_fd());
  1692. ++ out.print_raw("Current thread is ");
  1693. ++ char buf[16];
  1694. ++ jio_snprintf(buf, sizeof(buf), UINTX_FORMAT, os::current_thread_id());
  1695. ++ out.print_raw_cr(buf);
  1696. ++ out.print_raw_cr("Dumping core ...");
  1697. ++#endif
  1698. ++ ::abort(); // dump core
  1699. ++ }
  1700. ++
  1701. ++ ::exit(1);
  1702. ++}
  1703. ++
  1704. ++// Die immediately, no exit hook, no abort hook, no cleanup.
  1705. ++void os::die() {
  1706. ++ // _exit() on LinuxThreads only kills current thread
  1707. ++ ::abort();
  1708. ++}
  1709. ++
  1710. ++// unused on linux for now.
  1711. ++void os::set_error_file(const char *logfile) {}
  1712. ++
  1713. ++
  1714. ++// This method is a copy of JDK's sysGetLastErrorString
  1715. ++// from src/solaris/hpi/src/system_md.c
  1716. ++
  1717. ++size_t os::lasterror(char *buf, size_t len) {
  1718. ++
  1719. ++ if (errno == 0) return 0;
  1720. ++
  1721. ++ const char *s = ::strerror(errno);
  1722. ++ size_t n = ::strlen(s);
  1723. ++ if (n >= len) {
  1724. ++ n = len - 1;
  1725. ++ }
  1726. ++ ::strncpy(buf, s, n);
  1727. ++ buf[n] = '\0';
  1728. ++ return n;
  1729. ++}
  1730. ++
  1731. ++intx os::current_thread_id() { return (intx)pthread_self(); }
  1732. ++int os::current_process_id() {
  1733. ++
  1734. ++ // Under the old linux thread library, linux gives each thread
  1735. ++ // its own process id. Because of this each thread will return
  1736. ++ // a different pid if this method were to return the result
  1737. ++ // of getpid(2). Linux provides no api that returns the pid
  1738. ++ // of the launcher thread for the vm. This implementation
  1739. ++ // returns a unique pid, the pid of the launcher thread
  1740. ++ // that starts the vm 'process'.
  1741. ++
  1742. ++ // Under the NPTL, getpid() returns the same pid as the
  1743. ++ // launcher thread rather than a unique pid per thread.
  1744. ++ // Use gettid() if you want the old pre NPTL behaviour.
  1745. ++
  1746. ++ // if you are looking for the result of a call to getpid() that
  1747. ++ // returns a unique pid for the calling thread, then look at the
  1748. ++ // OSThread::thread_id() method in osThread_linux.hpp file
  1749. ++
  1750. ++ return (int)(_initial_pid ? _initial_pid : getpid());
  1751. ++}
  1752. ++
  1753. ++// DLL functions
  1754. ++
  1755. ++const char* os::dll_file_extension() { return ".so"; }
  1756. ++
  1757. ++// This must be hard coded because it's the system's temporary
  1758. ++// directory not the java application's temp directory, ala java.io.tmpdir.
  1759. ++const char* os::get_temp_directory() { return "/tmp"; }
  1760. ++
  1761. ++static bool file_exists(const char* filename) {
  1762. ++ struct stat statbuf;
  1763. ++ if (filename == NULL || strlen(filename) == 0) {
  1764. ++ return false;
  1765. ++ }
  1766. ++ return os::stat(filename, &statbuf) == 0;
  1767. ++}
  1768. ++
  1769. ++void os::dll_build_name(char* buffer, size_t buflen,
  1770. ++ const char* pname, const char* fname) {
  1771. ++ // Copied from libhpi
  1772. ++ const size_t pnamelen = pname ? strlen(pname) : 0;
  1773. ++
  1774. ++ // Quietly truncate on buffer overflow. Should be an error.
  1775. ++ if (pnamelen + strlen(fname) + 10 > (size_t) buflen) {
  1776. ++ *buffer = '\0';
  1777. ++ return;
  1778. ++ }
  1779. ++
  1780. ++ if (pnamelen == 0) {
  1781. ++ snprintf(buffer, buflen, "lib%s.so", fname);
  1782. ++ } else if (strchr(pname, *os::path_separator()) != NULL) {
  1783. ++ int n;
  1784. ++ char** pelements = split_path(pname, &n);
  1785. ++ for (int i = 0 ; i < n ; i++) {
  1786. ++ // Really shouldn't be NULL, but check can't hurt
  1787. ++ if (pelements[i] == NULL || strlen(pelements[i]) == 0) {
  1788. ++ continue; // skip the empty path values
  1789. ++ }
  1790. ++ snprintf(buffer, buflen, "%s/lib%s.so", pelements[i], fname);
  1791. ++ if (file_exists(buffer)) {
  1792. ++ break;
  1793. ++ }
  1794. ++ }
  1795. ++ // release the storage
  1796. ++ for (int i = 0 ; i < n ; i++) {
  1797. ++ if (pelements[i] != NULL) {
  1798. ++ FREE_C_HEAP_ARRAY(char, pelements[i], mtInternal);
  1799. ++ }
  1800. ++ }
  1801. ++ if (pelements != NULL) {
  1802. ++ FREE_C_HEAP_ARRAY(char*, pelements, mtInternal);
  1803. ++ }
  1804. ++ } else {
  1805. ++ snprintf(buffer, buflen, "%s/lib%s.so", pname, fname);
  1806. ++ }
  1807. ++}
  1808. ++
  1809. ++const char* os::get_current_directory(char *buf, int buflen) {
  1810. ++ return getcwd(buf, buflen);
  1811. ++}
  1812. ++
  1813. ++// check if addr is inside libjvm[_g].so
  1814. ++bool os::address_is_in_vm(address addr) {
  1815. ++ static address libjvm_base_addr;
  1816. ++ Dl_info dlinfo;
  1817. ++
  1818. ++ if (libjvm_base_addr == NULL) {
  1819. ++ if (dladdr(CAST_FROM_FN_PTR(void *, os::address_is_in_vm), &dlinfo) != 0) {
  1820. ++ libjvm_base_addr = (address)dlinfo.dli_fbase;
  1821. ++ }
  1822. ++ assert(libjvm_base_addr !=NULL, "Cannot obtain base address for libjvm");
  1823. ++ }
  1824. ++
  1825. ++ if (dladdr((void *)addr, &dlinfo) != 0) {
  1826. ++ if (libjvm_base_addr == (address)dlinfo.dli_fbase) return true;
  1827. ++ }
  1828. ++
  1829. ++ return false;
  1830. ++}
  1831. ++
  1832. ++bool os::dll_address_to_function_name(address addr, char *buf,
  1833. ++ int buflen, int *offset) {
  1834. ++ // buf is not optional, but offset is optional
  1835. ++ assert(buf != NULL, "sanity check");
  1836. ++
  1837. ++ Dl_info dlinfo;
  1838. ++
  1839. ++ if (dladdr((void*)addr, &dlinfo) != 0) {
  1840. ++ // see if we have a matching symbol
  1841. ++ if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL) {
  1842. ++ if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) {
  1843. ++ jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname);
  1844. ++ }
  1845. ++ if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
  1846. ++ return true;
  1847. ++ }
  1848. ++ // no matching symbol so try for just file info
  1849. ++ if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) {
  1850. ++ if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
  1851. ++ buf, buflen, offset, dlinfo.dli_fname)) {
  1852. ++ return true;
  1853. ++ }
  1854. ++ }
  1855. ++ }
  1856. ++
  1857. ++ buf[0] = '\0';
  1858. ++ if (offset != NULL) *offset = -1;
  1859. ++ return false;
  1860. ++}
  1861. ++
  1862. ++struct _address_to_library_name {
  1863. ++ address addr; // input : memory address
  1864. ++ size_t buflen; // size of fname
  1865. ++ char* fname; // output: library name
  1866. ++ address base; // library base addr
  1867. ++};
  1868. ++
  1869. ++static int address_to_library_name_callback(struct dl_phdr_info *info,
  1870. ++ size_t size, void *data) {
  1871. ++ int i;
  1872. ++ bool found = false;
  1873. ++ address libbase = NULL;
  1874. ++ struct _address_to_library_name * d = (struct _address_to_library_name *)data;
  1875. ++
  1876. ++ // iterate through all loadable segments
  1877. ++ for (i = 0; i < info->dlpi_phnum; i++) {
  1878. ++ address segbase = (address)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
  1879. ++ if (info->dlpi_phdr[i].p_type == PT_LOAD) {
  1880. ++ // base address of a library is the lowest address of its loaded
  1881. ++ // segments.
  1882. ++ if (libbase == NULL || libbase > segbase) {
  1883. ++ libbase = segbase;
  1884. ++ }
  1885. ++ // see if 'addr' is within current segment
  1886. ++ if (segbase <= d->addr &&
  1887. ++ d->addr < segbase + info->dlpi_phdr[i].p_memsz) {
  1888. ++ found = true;
  1889. ++ }
  1890. ++ }
  1891. ++ }
  1892. ++
  1893. ++ // dlpi_name is NULL or empty if the ELF file is executable, return 0
  1894. ++ // so dll_address_to_library_name() can fall through to use dladdr() which
  1895. ++ // can figure out executable name from argv[0].
  1896. ++ if (found && info->dlpi_name && info->dlpi_name[0]) {
  1897. ++ d->base = libbase;
  1898. ++ if (d->fname) {
  1899. ++ jio_snprintf(d->fname, d->buflen, "%s", info->dlpi_name);
  1900. ++ }
  1901. ++ return 1;
  1902. ++ }
  1903. ++ return 0;
  1904. ++}
  1905. ++
  1906. ++bool os::dll_address_to_library_name(address addr, char* buf,
  1907. ++ int buflen, int* offset) {
  1908. ++ // buf is not optional, but offset is optional
  1909. ++ assert(buf != NULL, "sanity check");
  1910. ++
  1911. ++ Dl_info dlinfo;
  1912. ++ struct _address_to_library_name data;
  1913. ++
  1914. ++ // There is a bug in old glibc dladdr() implementation that it could resolve
  1915. ++ // to wrong library name if the .so file has a base address != NULL. Here
  1916. ++ // we iterate through the program headers of all loaded libraries to find
  1917. ++ // out which library 'addr' really belongs to. This workaround can be
  1918. ++ // removed once the minimum requirement for glibc is moved to 2.3.x.
  1919. ++ data.addr = addr;
  1920. ++ data.fname = buf;
  1921. ++ data.buflen = buflen;
  1922. ++ data.base = NULL;
  1923. ++ int rslt = dl_iterate_phdr(address_to_library_name_callback, (void *)&data);
  1924. ++
  1925. ++ if (rslt) {
  1926. ++ // buf already contains library name
  1927. ++ if (offset) *offset = addr - data.base;
  1928. ++ return true;
  1929. ++ }
  1930. ++ if (dladdr((void*)addr, &dlinfo) != 0) {
  1931. ++ if (dlinfo.dli_fname != NULL) {
  1932. ++ jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
  1933. ++ }
  1934. ++ if (dlinfo.dli_fbase != NULL && offset != NULL) {
  1935. ++ *offset = addr - (address)dlinfo.dli_fbase;
  1936. ++ }
  1937. ++ return true;
  1938. ++ }
  1939. ++
  1940. ++ buf[0] = '\0';
  1941. ++ if (offset) *offset = -1;
  1942. ++ return false;
  1943. ++}
  1944. ++
  1945. ++ // Loads .dll/.so and
  1946. ++ // in case of error it checks if .dll/.so was built for the
  1947. ++ // same architecture as Hotspot is running on
  1948. ++
  1949. ++
  1950. ++// Remember the stack's state. The Linux dynamic linker will change
  1951. ++// the stack to 'executable' at most once, so we must safepoint only once.
  1952. ++bool os::Linux::_stack_is_executable = false;
  1953. ++
  1954. ++// VM operation that loads a library. This is necessary if stack protection
  1955. ++// of the Java stacks can be lost during loading the library. If we
  1956. ++// do not stop the Java threads, they can stack overflow before the stacks
  1957. ++// are protected again.
  1958. ++class VM_LinuxDllLoad: public VM_Operation {
  1959. ++ private:
  1960. ++ const char *_filename;
  1961. ++ char *_ebuf;
  1962. ++ int _ebuflen;
  1963. ++ void *_lib;
  1964. ++ public:
  1965. ++ VM_LinuxDllLoad(const char *fn, char *ebuf, int ebuflen) :
  1966. ++ _filename(fn), _ebuf(ebuf), _ebuflen(ebuflen), _lib(NULL) {}
  1967. ++ VMOp_Type type() const { return VMOp_LinuxDllLoad; }
  1968. ++ void doit() {
  1969. ++ _lib = os::Linux::dll_load_in_vmthread(_filename, _ebuf, _ebuflen);
  1970. ++ os::Linux::_stack_is_executable = true;
  1971. ++ }
  1972. ++ void* loaded_library() { return _lib; }
  1973. ++};
  1974. ++
  1975. ++void * os::dll_load(const char *filename, char *ebuf, int ebuflen)
  1976. ++{
  1977. ++ void * result = NULL;
  1978. ++ bool load_attempted = false;
  1979. ++
  1980. ++ // Check whether the library to load might change execution rights
  1981. ++ // of the stack. If they are changed, the protection of the stack
  1982. ++ // guard pages will be lost. We need a safepoint to fix this.
  1983. ++ //
  1984. ++ // See Linux man page execstack(8) for more info.
  1985. ++ if (os::uses_stack_guard_pages() && !os::Linux::_stack_is_executable) {
  1986. ++ ElfFile ef(filename);
  1987. ++ if (!ef.specifies_noexecstack()) {
  1988. ++ if (!is_init_completed()) {
  1989. ++ os::Linux::_stack_is_executable = true;
  1990. ++ // This is OK - No Java threads have been created yet, and hence no
  1991. ++ // stack guard pages to fix.
  1992. ++ //
  1993. ++ // This should happen only when you are building JDK7 using a very
  1994. ++ // old version of JDK6 (e.g., with JPRT) and running test_gamma.
  1995. ++ //
  1996. ++ // Dynamic loader will make all stacks executable after
  1997. ++ // this function returns, and will not do that again.
  1998. ++ assert(Threads::first() == NULL, "no Java threads should exist yet.");
  1999. ++ } else {
  2000. ++ warning("You have loaded library %s which might have disabled stack guard. "
  2001. ++ "The VM will try to fix the stack guard now.\n"
  2002. ++ "It's highly recommended that you fix the library with "
  2003. ++ "'execstack -c <libfile>', or link it with '-z noexecstack'.",
  2004. ++ filename);
  2005. ++
  2006. ++ assert(Thread::current()->is_Java_thread(), "must be Java thread");
  2007. ++ JavaThread *jt = JavaThread::current();
  2008. ++ if (jt->thread_state() != _thread_in_native) {
  2009. ++ // This happens when a compiler thread tries to load a hsdis-<arch>.so file
  2010. ++ // that requires ExecStack. Cannot enter safe point. Let's give up.
  2011. ++ warning("Unable to fix stack guard. Giving up.");
  2012. ++ } else {
  2013. ++ if (!LoadExecStackDllInVMThread) {
  2014. ++ // This is for the case where the DLL has an static
  2015. ++ // constructor function that executes JNI code. We cannot
  2016. ++ // load such DLLs in the VMThread.
  2017. ++ result = os::Linux::dlopen_helper(filename, ebuf, ebuflen);
  2018. ++ }
  2019. ++
  2020. ++ ThreadInVMfromNative tiv(jt);
  2021. ++ debug_only(VMNativeEntryWrapper vew;)
  2022. ++
  2023. ++ VM_LinuxDllLoad op(filename, ebuf, ebuflen);
  2024. ++ VMThread::execute(&op);
  2025. ++ if (LoadExecStackDllInVMThread) {
  2026. ++ result = op.loaded_library();
  2027. ++ }
  2028. ++ load_attempted = true;
  2029. ++ }
  2030. ++ }
  2031. ++ }
  2032. ++ }
  2033. ++
  2034. ++ if (!load_attempted) {
  2035. ++ result = os::Linux::dlopen_helper(filename, ebuf, ebuflen);
  2036. ++ }
  2037. ++
  2038. ++ if (result != NULL) {
  2039. ++ // Successful loading
  2040. ++ return result;
  2041. ++ }
  2042. ++
  2043. ++ Elf32_Ehdr elf_head;
  2044. ++ int diag_msg_max_length=ebuflen-strlen(ebuf);
  2045. ++ char* diag_msg_buf=ebuf+strlen(ebuf);
  2046. ++
  2047. ++ if (diag_msg_max_length==0) {
  2048. ++ // No more space in ebuf for additional diagnostics message
  2049. ++ return NULL;
  2050. ++ }
  2051. ++
  2052. ++
  2053. ++ int file_descriptor= ::open(filename, O_RDONLY | O_NONBLOCK);
  2054. ++
  2055. ++ if (file_descriptor < 0) {
  2056. ++ // Can't open library, report dlerror() message
  2057. ++ return NULL;
  2058. ++ }
  2059. ++
  2060. ++ bool failed_to_read_elf_head=
  2061. ++ (sizeof(elf_head)!=
  2062. ++ (::read(file_descriptor, &elf_head,sizeof(elf_head)))) ;
  2063. ++
  2064. ++ ::close(file_descriptor);
  2065. ++ if (failed_to_read_elf_head) {
  2066. ++ // file i/o error - report dlerror() msg
  2067. ++ return NULL;
  2068. ++ }
  2069. ++
  2070. ++ typedef struct {
  2071. ++ Elf32_Half code; // Actual value as defined in elf.h
  2072. ++ Elf32_Half compat_class; // Compatibility of archs at VM's sense
  2073. ++ char elf_class; // 32 or 64 bit
  2074. ++ char endianess; // MSB or LSB
  2075. ++ char* name; // String representation
  2076. ++ } arch_t;
  2077. ++
  2078. ++ #ifndef EM_486
  2079. ++ #define EM_486 6 /* Intel 80486 */
  2080. ++ #endif
  2081. ++
  2082. ++ static const arch_t arch_array[]={
  2083. ++ {EM_386, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
  2084. ++ {EM_486, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
  2085. ++ {EM_IA_64, EM_IA_64, ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"},
  2086. ++ {EM_X86_64, EM_X86_64, ELFCLASS64, ELFDATA2LSB, (char*)"AMD 64"},
  2087. ++ {EM_SPARC, EM_SPARC, ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
  2088. ++ {EM_SPARC32PLUS, EM_SPARC, ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
  2089. ++ {EM_SPARCV9, EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"},
  2090. ++ {EM_PPC, EM_PPC, ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
  2091. ++ {EM_PPC64, EM_PPC64, ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
  2092. ++ {EM_ARM, EM_ARM, ELFCLASS32, ELFDATA2LSB, (char*)"ARM"},
  2093. ++ {EM_S390, EM_S390, ELFCLASSNONE, ELFDATA2MSB, (char*)"IBM System/390"},
  2094. ++ {EM_ALPHA, EM_ALPHA, ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"},
  2095. ++ {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"},
  2096. ++ {EM_MIPS, EM_MIPS, ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
  2097. ++ {EM_PARISC, EM_PARISC, ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
  2098. ++ {EM_68K, EM_68K, ELFCLASS32, ELFDATA2MSB, (char*)"M68k"},
  2099. ++ {EM_SH, EM_SH, ELFCLASS32, ELFDATA2LSB, (char*)"SH"}, /* Support little endian only*/
  2100. ++ {EM_AARCH64, EM_AARCH64, ELFCLASS64, ELFDATA2LSB, (char*)"AARCH64"} /* Support little endian only*/
  2101. ++ };
  2102. ++
  2103. ++ #if (defined IA32)
  2104. ++ static Elf32_Half running_arch_code=EM_386;
  2105. ++ #elif (defined AMD64)
  2106. ++ static Elf32_Half running_arch_code=EM_X86_64;
  2107. ++ #elif (defined IA64)
  2108. ++ static Elf32_Half running_arch_code=EM_IA_64;
  2109. ++ #elif (defined __sparc) && (defined _LP64)
  2110. ++ static Elf32_Half running_arch_code=EM_SPARCV9;
  2111. ++ #elif (defined __sparc) && (!defined _LP64)
  2112. ++ static Elf32_Half running_arch_code=EM_SPARC;
  2113. ++ #elif (defined __powerpc64__)
  2114. ++ static Elf32_Half running_arch_code=EM_PPC64;
  2115. ++ #elif (defined __powerpc__)
  2116. ++ static Elf32_Half running_arch_code=EM_PPC;
  2117. ++ #elif (defined ARM)
  2118. ++ static Elf32_Half running_arch_code=EM_ARM;
  2119. ++ #elif (defined S390)
  2120. ++ static Elf32_Half running_arch_code=EM_S390;
  2121. ++ #elif (defined ALPHA)
  2122. ++ static Elf32_Half running_arch_code=EM_ALPHA;
  2123. ++ #elif (defined MIPSEL)
  2124. ++ static Elf32_Half running_arch_code=EM_MIPS_RS3_LE;
  2125. ++ #elif (defined PARISC)
  2126. ++ static Elf32_Half running_arch_code=EM_PARISC;
  2127. ++ #elif (defined MIPS)
  2128. ++ static Elf32_Half running_arch_code=EM_MIPS;
  2129. ++ #elif (defined M68K)
  2130. ++ static Elf32_Half running_arch_code=EM_68K;
  2131. ++ #elif (defined SH)
  2132. ++ static Elf32_Half running_arch_code=EM_SH;
  2133. ++ #elif (defined AARCH64)
  2134. ++ static Elf32_Half running_arch_code=EM_AARCH64;
  2135. ++ #else
  2136. ++ #error Method os::dll_load requires that one of following is defined:\
  2137. ++ IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K, SH
  2138. ++ #endif
  2139. ++
  2140. ++ // Identify compatability class for VM's architecture and library's architecture
  2141. ++ // Obtain string descriptions for architectures
  2142. ++
  2143. ++ arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
  2144. ++ int running_arch_index=-1;
  2145. ++
  2146. ++ for (unsigned int i=0 ; i < ARRAY_SIZE(arch_array) ; i++ ) {
  2147. ++ if (running_arch_code == arch_array[i].code) {
  2148. ++ running_arch_index = i;
  2149. ++ }
  2150. ++ if (lib_arch.code == arch_array[i].code) {
  2151. ++ lib_arch.compat_class = arch_array[i].compat_class;
  2152. ++ lib_arch.name = arch_array[i].name;
  2153. ++ }
  2154. ++ }
  2155. ++
  2156. ++ assert(running_arch_index != -1,
  2157. ++ "Didn't find running architecture code (running_arch_code) in arch_array");
  2158. ++ if (running_arch_index == -1) {
  2159. ++ // Even though running architecture detection failed
  2160. ++ // we may still continue with reporting dlerror() message
  2161. ++ return NULL;
  2162. ++ }
  2163. ++
  2164. ++ if (lib_arch.endianess != arch_array[running_arch_index].endianess) {
  2165. ++ ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: endianness mismatch)");
  2166. ++ return NULL;
  2167. ++ }
  2168. ++
  2169. ++#ifndef S390
  2170. ++ if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) {
  2171. ++ ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: architecture word width mismatch)");
  2172. ++ return NULL;
  2173. ++ }
  2174. ++#endif // !S390
  2175. ++
  2176. ++ if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
  2177. ++ if ( lib_arch.name!=NULL ) {
  2178. ++ ::snprintf(diag_msg_buf, diag_msg_max_length-1,
  2179. ++ " (Possible cause: can't load %s-bit .so on a %s-bit platform)",
  2180. ++ lib_arch.name, arch_array[running_arch_index].name);
  2181. ++ } else {
  2182. ++ ::snprintf(diag_msg_buf, diag_msg_max_length-1,
  2183. ++ " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)",
  2184. ++ lib_arch.code,
  2185. ++ arch_array[running_arch_index].name);
  2186. ++ }
  2187. ++ }
  2188. ++
  2189. ++ return NULL;
  2190. ++}
  2191. ++
  2192. ++void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) {
  2193. ++ void * result = ::dlopen(filename, RTLD_LAZY);
  2194. ++ if (result == NULL) {
  2195. ++ ::strncpy(ebuf, ::dlerror(), ebuflen - 1);
  2196. ++ ebuf[ebuflen-1] = '\0';
  2197. ++ }
  2198. ++ return result;
  2199. ++}
  2200. ++
  2201. ++void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, int ebuflen) {
  2202. ++ void * result = NULL;
  2203. ++ if (LoadExecStackDllInVMThread) {
  2204. ++ result = dlopen_helper(filename, ebuf, ebuflen);
  2205. ++ }
  2206. ++
  2207. ++ // Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a
  2208. ++ // library that requires an executable stack, or which does not have this
  2209. ++ // stack attribute set, dlopen changes the stack attribute to executable. The
  2210. ++ // read protection of the guard pages gets lost.
  2211. ++ //
  2212. ++ // Need to check _stack_is_executable again as multiple VM_LinuxDllLoad
  2213. ++ // may have been queued at the same time.
  2214. ++
  2215. ++ if (!_stack_is_executable) {
  2216. ++ JavaThread *jt = Threads::first();
  2217. ++
  2218. ++ while (jt) {
  2219. ++ if (!jt->stack_guard_zone_unused() && // Stack not yet fully initialized
  2220. ++ jt->stack_yellow_zone_enabled()) { // No pending stack overflow exceptions
  2221. ++ if (!os::guard_memory((char *) jt->stack_red_zone_base() - jt->stack_red_zone_size(),
  2222. ++ jt->stack_yellow_zone_size() + jt->stack_red_zone_size())) {
  2223. ++ warning("Attempt to reguard stack yellow zone failed.");
  2224. ++ }
  2225. ++ }
  2226. ++ jt = jt->next();
  2227. ++ }
  2228. ++ }
  2229. ++
  2230. ++ return result;
  2231. ++}
  2232. ++
  2233. ++/*
  2234. ++ * glibc-2.0 libdl is not MT safe. If you are building with any glibc,
  2235. ++ * chances are you might want to run the generated bits against glibc-2.0
  2236. ++ * libdl.so, so always use locking for any version of glibc.
  2237. ++ */
  2238. ++void* os::dll_lookup(void* handle, const char* name) {
  2239. ++ pthread_mutex_lock(&dl_mutex);
  2240. ++ void* res = dlsym(handle, name);
  2241. ++ pthread_mutex_unlock(&dl_mutex);
  2242. ++ return res;
  2243. ++}
  2244. ++
  2245. ++
  2246. ++static bool _print_ascii_file(const char* filename, outputStream* st) {
  2247. ++ int fd = ::open(filename, O_RDONLY);
  2248. ++ if (fd == -1) {
  2249. ++ return false;
  2250. ++ }
  2251. ++
  2252. ++ char buf[32];
  2253. ++ int bytes;
  2254. ++ while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) {
  2255. ++ st->print_raw(buf, bytes);
  2256. ++ }
  2257. ++
  2258. ++ ::close(fd);
  2259. ++
  2260. ++ return true;
  2261. ++}
  2262. ++
  2263. ++bool _print_lsb_file(const char* filename, outputStream* st) {
  2264. ++ int fd = open(filename, O_RDONLY);
  2265. ++ if (fd == -1) {
  2266. ++ return false;
  2267. ++ }
  2268. ++
  2269. ++ char buf[512], *d_i, *d_r, *d_c;
  2270. ++ int bytes;
  2271. ++
  2272. ++ if ((bytes = read(fd, buf, sizeof(buf)-1)) == sizeof(buf)-1) {
  2273. ++ close(fd);
  2274. ++ return false;
  2275. ++ }
  2276. ++ close(fd);
  2277. ++
  2278. ++ buf[bytes] = '\n';
  2279. ++ buf[bytes+1] = '\0';
  2280. ++ d_i = strstr(buf, "DISTRIB_ID=");
  2281. ++ d_r = strstr(buf, "DISTRIB_RELEASE=");
  2282. ++ d_c = strstr(buf, "DISTRIB_CODENAME=");
  2283. ++ if (!d_i || !d_r || !d_c) {
  2284. ++ return false;
  2285. ++ }
  2286. ++ d_i = strchr(d_i, '=') + 1; *strchrnul(d_i, '\n') = '\0';
  2287. ++ d_r = strchr(d_r, '=') + 1; *strchrnul(d_r, '\n') = '\0';
  2288. ++ d_c = strchr(d_c, '=') + 1; *strchrnul(d_c, '\n') = '\0';
  2289. ++ st->print("%s %s (%s)", d_i, d_r, d_c);
  2290. ++
  2291. ++ return true;
  2292. ++}
  2293. ++
  2294. ++void os::print_dll_info(outputStream *st) {
  2295. ++ st->print_cr("Dynamic libraries:");
  2296. ++
  2297. ++ char fname[32];
  2298. ++ pid_t pid = os::Linux::gettid();
  2299. ++
  2300. ++ jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
  2301. ++
  2302. ++ if (!_print_ascii_file(fname, st)) {
  2303. ++ st->print("Can not get library information for pid = %d\n", pid);
  2304. ++ }
  2305. ++}
  2306. ++
  2307. ++void os::print_os_info_brief(outputStream* st) {
  2308. ++ os::Linux::print_distro_info(st);
  2309. ++
  2310. ++ os::Posix::print_uname_info(st);
  2311. ++
  2312. ++ os::Linux::print_libversion_info(st);
  2313. ++
  2314. ++}
  2315. ++
  2316. ++void os::print_os_info(outputStream* st) {
  2317. ++ st->print("OS:");
  2318. ++
  2319. ++ os::Linux::print_distro_info(st);
  2320. ++
  2321. ++ os::Posix::print_uname_info(st);
  2322. ++
  2323. ++ // Print warning if unsafe chroot environment detected
  2324. ++ if (unsafe_chroot_detected) {
  2325. ++ st->print("WARNING!! ");
  2326. ++ st->print_cr(unstable_chroot_error);
  2327. ++ }
  2328. ++
  2329. ++ os::Linux::print_libversion_info(st);
  2330. ++
  2331. ++ os::Posix::print_rlimit_info(st);
  2332. ++
  2333. ++ os::Posix::print_load_average(st);
  2334. ++
  2335. ++ os::Linux::print_full_memory_info(st);
  2336. ++}
  2337. ++
  2338. ++// Try to identify popular distros.
  2339. ++// Most Linux distributions have /etc/XXX-release file, which contains
  2340. ++// the OS version string. Some have more than one /etc/XXX-release file
  2341. ++// (e.g. Mandrake has both /etc/mandrake-release and /etc/redhat-release.),
  2342. ++// so the order is important.
  2343. ++void os::Linux::print_distro_info(outputStream* st) {
  2344. ++ if (!_print_ascii_file("/etc/mandrake-release", st) &&
  2345. ++ !_print_ascii_file("/etc/sun-release", st) &&
  2346. ++ !_print_ascii_file("/etc/redhat-release", st) &&
  2347. ++ !_print_ascii_file("/etc/SuSE-release", st) &&
  2348. ++ !_print_ascii_file("/etc/turbolinux-release", st) &&
  2349. ++ !_print_ascii_file("/etc/gentoo-release", st) &&
  2350. ++ !_print_lsb_file("/etc/lsb-release", st) &&
  2351. ++ !_print_ascii_file("/etc/debian_version", st) &&
  2352. ++ !_print_ascii_file("/etc/ltib-release", st) &&
  2353. ++ !_print_ascii_file("/etc/angstrom-version", st)) {
  2354. ++ st->print("Linux");
  2355. ++ }
  2356. ++ st->cr();
  2357. ++}
  2358. ++
  2359. ++void os::Linux::print_libversion_info(outputStream* st) {
  2360. ++ // libc, pthread
  2361. ++ st->print("libc:");
  2362. ++ st->print(os::Linux::glibc_version()); st->print(" ");
  2363. ++ st->print(os::Linux::libpthread_version()); st->print(" ");
  2364. ++ if (os::Linux::is_LinuxThreads()) {
  2365. ++ st->print("(%s stack)", os::Linux::is_floating_stack() ? "floating" : "fixed");
  2366. ++ }
  2367. ++ st->cr();
  2368. ++}
  2369. ++
  2370. ++void os::Linux::print_full_memory_info(outputStream* st) {
  2371. ++ st->print("\n/proc/meminfo:\n");
  2372. ++ _print_ascii_file("/proc/meminfo", st);
  2373. ++ st->cr();
  2374. ++}
  2375. ++
  2376. ++void os::print_memory_info(outputStream* st) {
  2377. ++
  2378. ++ st->print("Memory:");
  2379. ++ st->print(" %dk page", os::vm_page_size()>>10);
  2380. ++
  2381. ++ // values in struct sysinfo are "unsigned long"
  2382. ++ struct sysinfo si;
  2383. ++ sysinfo(&si);
  2384. ++
  2385. ++ st->print(", physical " UINT64_FORMAT "k",
  2386. ++ os::physical_memory() >> 10);
  2387. ++ st->print("(" UINT64_FORMAT "k free)",
  2388. ++ os::available_memory() >> 10);
  2389. ++ st->print(", swap " UINT64_FORMAT "k",
  2390. ++ ((jlong)si.totalswap * si.mem_unit) >> 10);
  2391. ++ st->print("(" UINT64_FORMAT "k free)",
  2392. ++ ((jlong)si.freeswap * si.mem_unit) >> 10);
  2393. ++ st->cr();
  2394. ++}
  2395. ++
  2396. ++void os::pd_print_cpu_info(outputStream* st) {
  2397. ++ st->print("\n/proc/cpuinfo:\n");
  2398. ++ if (!_print_ascii_file("/proc/cpuinfo", st)) {
  2399. ++ st->print(" <Not Available>");
  2400. ++ }
  2401. ++ st->cr();
  2402. ++}
  2403. ++
  2404. ++// Taken from /usr/include/bits/siginfo.h Supposed to be architecture specific
  2405. ++// but they're the same for all the linux arch that we support
  2406. ++// and they're the same for solaris but there's no common place to put this.
  2407. ++const char *ill_names[] = { "ILL0", "ILL_ILLOPC", "ILL_ILLOPN", "ILL_ILLADR",
  2408. ++ "ILL_ILLTRP", "ILL_PRVOPC", "ILL_PRVREG",
  2409. ++ "ILL_COPROC", "ILL_BADSTK" };
  2410. ++
  2411. ++const char *fpe_names[] = { "FPE0", "FPE_INTDIV", "FPE_INTOVF", "FPE_FLTDIV",
  2412. ++ "FPE_FLTOVF", "FPE_FLTUND", "FPE_FLTRES",
  2413. ++ "FPE_FLTINV", "FPE_FLTSUB", "FPE_FLTDEN" };
  2414. ++
  2415. ++const char *segv_names[] = { "SEGV0", "SEGV_MAPERR", "SEGV_ACCERR" };
  2416. ++
  2417. ++const char *bus_names[] = { "BUS0", "BUS_ADRALN", "BUS_ADRERR", "BUS_OBJERR" };
  2418. ++
  2419. ++void os::print_siginfo(outputStream* st, void* siginfo) {
  2420. ++ st->print("siginfo:");
  2421. ++
  2422. ++ const int buflen = 100;
  2423. ++ char buf[buflen];
  2424. ++ siginfo_t *si = (siginfo_t*)siginfo;
  2425. ++ st->print("si_signo=%s: ", os::exception_name(si->si_signo, buf, buflen));
  2426. ++ if (si->si_errno != 0 && strerror_r(si->si_errno, buf, buflen) == 0) {
  2427. ++ st->print("si_errno=%s", buf);
  2428. ++ } else {
  2429. ++ st->print("si_errno=%d", si->si_errno);
  2430. ++ }
  2431. ++ const int c = si->si_code;
  2432. ++ assert(c > 0, "unexpected si_code");
  2433. ++ switch (si->si_signo) {
  2434. ++ case SIGILL:
  2435. ++ st->print(", si_code=%d (%s)", c, c > 8 ? "" : ill_names[c]);
  2436. ++ st->print(", si_addr=" PTR_FORMAT, si->si_addr);
  2437. ++ break;
  2438. ++ case SIGFPE:
  2439. ++ st->print(", si_code=%d (%s)", c, c > 9 ? "" : fpe_names[c]);
  2440. ++ st->print(", si_addr=" PTR_FORMAT, si->si_addr);
  2441. ++ break;
  2442. ++ case SIGSEGV:
  2443. ++ st->print(", si_code=%d (%s)", c, c > 2 ? "" : segv_names[c]);
  2444. ++ st->print(", si_addr=" PTR_FORMAT, si->si_addr);
  2445. ++ break;
  2446. ++ case SIGBUS:
  2447. ++ st->print(", si_code=%d (%s)", c, c > 3 ? "" : bus_names[c]);
  2448. ++ st->print(", si_addr=" PTR_FORMAT, si->si_addr);
  2449. ++ break;
  2450. ++ default:
  2451. ++ st->print(", si_code=%d", si->si_code);
  2452. ++ // no si_addr
  2453. ++ }
  2454. ++
  2455. ++ if ((si->si_signo == SIGBUS || si->si_signo == SIGSEGV) &&
  2456. ++ UseSharedSpaces) {
  2457. ++ FileMapInfo* mapinfo = FileMapInfo::current_info();
  2458. ++ if (mapinfo->is_in_shared_space(si->si_addr)) {
  2459. ++ st->print("\n\nError accessing class data sharing archive." \
  2460. ++ " Mapped file inaccessible during execution, " \
  2461. ++ " possible disk/network problem.");
  2462. ++ }
  2463. ++ }
  2464. ++ st->cr();
  2465. ++}
  2466. ++
  2467. ++
  2468. ++static void print_signal_handler(outputStream* st, int sig,
  2469. ++ char* buf, size_t buflen);
  2470. ++
  2471. ++void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) {
  2472. ++ st->print_cr("Signal Handlers:");
  2473. ++ print_signal_handler(st, SIGSEGV, buf, buflen);
  2474. ++ print_signal_handler(st, SIGBUS , buf, buflen);
  2475. ++ print_signal_handler(st, SIGFPE , buf, buflen);
  2476. ++ print_signal_handler(st, SIGPIPE, buf, buflen);
  2477. ++ print_signal_handler(st, SIGXFSZ, buf, buflen);
  2478. ++ print_signal_handler(st, SIGILL , buf, buflen);
  2479. ++ print_signal_handler(st, INTERRUPT_SIGNAL, buf, buflen);
  2480. ++ print_signal_handler(st, SR_signum, buf, buflen);
  2481. ++ print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);
  2482. ++ print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen);
  2483. ++ print_signal_handler(st, SHUTDOWN3_SIGNAL , buf, buflen);
  2484. ++ print_signal_handler(st, BREAK_SIGNAL, buf, buflen);
  2485. ++}
  2486. ++
  2487. ++static char saved_jvm_path[MAXPATHLEN] = {0};
  2488. ++
  2489. ++// Find the full path to the current module, libjvm.so or libjvm_g.so
  2490. ++void os::jvm_path(char *buf, jint buflen) {
  2491. ++ // Error checking.
  2492. ++ if (buflen < MAXPATHLEN) {
  2493. ++ assert(false, "must use a large-enough buffer");
  2494. ++ buf[0] = '\0';
  2495. ++ return;
  2496. ++ }
  2497. ++ // Lazy resolve the path to current module.
  2498. ++ if (saved_jvm_path[0] != 0) {
  2499. ++ strcpy(buf, saved_jvm_path);
  2500. ++ return;
  2501. ++ }
  2502. ++
  2503. ++ char dli_fname[MAXPATHLEN];
  2504. ++ bool ret = dll_address_to_library_name(
  2505. ++ CAST_FROM_FN_PTR(address, os::jvm_path),
  2506. ++ dli_fname, sizeof(dli_fname), NULL);
  2507. ++ assert(ret, "cannot locate libjvm");
  2508. ++ char *rp = NULL;
  2509. ++ if (ret && dli_fname[0] != '\0') {
  2510. ++ rp = realpath(dli_fname, buf);
  2511. ++ }
  2512. ++ if (rp == NULL)
  2513. ++ return;
  2514. ++
  2515. ++ if (Arguments::created_by_gamma_launcher()) {
  2516. ++ // Support for the gamma launcher. Typical value for buf is
  2517. ++ // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so". If "/jre/lib/" appears at
  2518. ++ // the right place in the string, then assume we are installed in a JDK and
  2519. ++ // we're done. Otherwise, check for a JAVA_HOME environment variable and fix
  2520. ++ // up the path so it looks like libjvm.so is installed there (append a
  2521. ++ // fake suffix hotspot/libjvm.so).
  2522. ++ const char *p = buf + strlen(buf) - 1;
  2523. ++ for (int count = 0; p > buf && count < 5; ++count) {
  2524. ++ for (--p; p > buf && *p != '/'; --p)
  2525. ++ /* empty */ ;
  2526. ++ }
  2527. ++
  2528. ++ if (strncmp(p, "/jre/lib/", 9) != 0) {
  2529. ++ // Look for JAVA_HOME in the environment.
  2530. ++ char* java_home_var = ::getenv("JAVA_HOME");
  2531. ++ if (java_home_var != NULL && java_home_var[0] != 0) {
  2532. ++ char* jrelib_p;
  2533. ++ int len;
  2534. ++
  2535. ++ // Check the current module name "libjvm.so" or "libjvm_g.so".
  2536. ++ p = strrchr(buf, '/');
  2537. ++ assert(strstr(p, "/libjvm") == p, "invalid library name");
  2538. ++ p = strstr(p, "_g") ? "_g" : "";
  2539. ++
  2540. ++ rp = realpath(java_home_var, buf);
  2541. ++ if (rp == NULL)
  2542. ++ return;
  2543. ++
  2544. ++ // determine if this is a legacy image or modules image
  2545. ++ // modules image doesn't have "jre" subdirectory
  2546. ++ len = strlen(buf);
  2547. ++ jrelib_p = buf + len;
  2548. ++ snprintf(jrelib_p, buflen-len, "/jre/lib/%s", cpu_arch);
  2549. ++ if (0 != access(buf, F_OK)) {
  2550. ++ snprintf(jrelib_p, buflen-len, "/lib/%s", cpu_arch);
  2551. ++ }
  2552. ++
  2553. ++ if (0 == access(buf, F_OK)) {
  2554. ++ // Use current module name "libjvm[_g].so" instead of
  2555. ++ // "libjvm"debug_only("_g")".so" since for fastdebug version
  2556. ++ // we should have "libjvm.so" but debug_only("_g") adds "_g"!
  2557. ++ len = strlen(buf);
  2558. ++ snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p);
  2559. ++ } else {
  2560. ++ // Go back to path of .so
  2561. ++ rp = realpath(dli_fname, buf);
  2562. ++ if (rp == NULL)
  2563. ++ return;
  2564. ++ }
  2565. ++ }
  2566. ++ }
  2567. ++ }
  2568. ++
  2569. ++ strcpy(saved_jvm_path, buf);
  2570. ++}
  2571. ++
  2572. ++void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
  2573. ++ // no prefix required, not even "_"
  2574. ++}
  2575. ++
  2576. ++void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
  2577. ++ // no suffix required
  2578. ++}
  2579. ++
  2580. ++////////////////////////////////////////////////////////////////////////////////
  2581. ++// sun.misc.Signal support
  2582. ++
  2583. ++static volatile jint sigint_count = 0;
  2584. ++
  2585. ++static void
  2586. ++UserHandler(int sig, void *siginfo, void *context) {
  2587. ++ // 4511530 - sem_post is serialized and handled by the manager thread. When
  2588. ++ // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We
  2589. ++ // don't want to flood the manager thread with sem_post requests.
  2590. ++ if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1)
  2591. ++ return;
  2592. ++
  2593. ++ // Ctrl-C is pressed during error reporting, likely because the error
  2594. ++ // handler fails to abort. Let VM die immediately.
  2595. ++ if (sig == SIGINT && is_error_reported()) {
  2596. ++ os::die();
  2597. ++ }
  2598. ++
  2599. ++ os::signal_notify(sig);
  2600. ++}
  2601. ++
  2602. ++void* os::user_handler() {
  2603. ++ return CAST_FROM_FN_PTR(void*, UserHandler);
  2604. ++}
  2605. ++
  2606. ++class Semaphore : public StackObj {
  2607. ++ public:
  2608. ++ Semaphore();
  2609. ++ ~Semaphore();
  2610. ++ void signal();
  2611. ++ void wait();
  2612. ++ bool trywait();
  2613. ++ bool timedwait(unsigned int sec, int nsec);
  2614. ++ private:
  2615. ++ sem_t _semaphore;
  2616. ++};
  2617. ++
  2618. ++
  2619. ++Semaphore::Semaphore() {
  2620. ++ sem_init(&_semaphore, 0, 0);
  2621. ++}
  2622. ++
  2623. ++Semaphore::~Semaphore() {
  2624. ++ sem_destroy(&_semaphore);
  2625. ++}
  2626. ++
  2627. ++void Semaphore::signal() {
  2628. ++ sem_post(&_semaphore);
  2629. ++}
  2630. ++
  2631. ++void Semaphore::wait() {
  2632. ++ sem_wait(&_semaphore);
  2633. ++}
  2634. ++
  2635. ++bool Semaphore::trywait() {
  2636. ++ return sem_trywait(&_semaphore) == 0;
  2637. ++}
  2638. ++
  2639. ++bool Semaphore::timedwait(unsigned int sec, int nsec) {
  2640. ++ struct timespec ts;
  2641. ++ unpackTime(&ts, false, (sec * NANOSECS_PER_SEC) + nsec);
  2642. ++
  2643. ++ while (1) {
  2644. ++ int result = sem_timedwait(&_semaphore, &ts);
  2645. ++ if (result == 0) {
  2646. ++ return true;
  2647. ++ } else if (errno == EINTR) {
  2648. ++ continue;
  2649. ++ } else if (errno == ETIMEDOUT) {
  2650. ++ return false;
  2651. ++ } else {
  2652. ++ return false;
  2653. ++ }
  2654. ++ }
  2655. ++}
  2656. ++
  2657. ++extern "C" {
  2658. ++ typedef void (*sa_handler_t)(int);
  2659. ++ typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
  2660. ++}
  2661. ++
  2662. ++void* os::signal(int signal_number, void* handler) {
  2663. ++ struct sigaction sigAct, oldSigAct;
  2664. ++
  2665. ++ sigfillset(&(sigAct.sa_mask));
  2666. ++ sigAct.sa_flags = SA_RESTART|SA_SIGINFO;
  2667. ++ sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler);
  2668. ++
  2669. ++ if (sigaction(signal_number, &sigAct, &oldSigAct)) {
  2670. ++ // -1 means registration failed
  2671. ++ return (void *)-1;
  2672. ++ }
  2673. ++
  2674. ++ return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler);
  2675. ++}
  2676. ++
  2677. ++void os::signal_raise(int signal_number) {
  2678. ++ ::raise(signal_number);
  2679. ++}
  2680. ++
  2681. ++/*
  2682. ++ * The following code is moved from os.cpp for making this
  2683. ++ * code platform specific, which it is by its very nature.
  2684. ++ */
  2685. ++
  2686. ++// Will be modified when max signal is changed to be dynamic
  2687. ++int os::sigexitnum_pd() {
  2688. ++ return NSIG;
  2689. ++}
  2690. ++
  2691. ++// a counter for each possible signal value
  2692. ++static volatile jint pending_signals[NSIG+1] = { 0 };
  2693. ++
  2694. ++// Linux(POSIX) specific hand shaking semaphore.
  2695. ++static sem_t sig_sem;
  2696. ++static Semaphore sr_semaphore;
  2697. ++
  2698. ++void os::signal_init_pd() {
  2699. ++ // Initialize signal structures
  2700. ++ ::memset((void*)pending_signals, 0, sizeof(pending_signals));
  2701. ++
  2702. ++ // Initialize signal semaphore
  2703. ++ ::sem_init(&sig_sem, 0, 0);
  2704. ++}
  2705. ++
  2706. ++void os::signal_notify(int sig) {
  2707. ++ Atomic::inc(&pending_signals[sig]);
  2708. ++ ::sem_post(&sig_sem);
  2709. ++}
  2710. ++
  2711. ++static int check_pending_signals(bool wait) {
  2712. ++ Atomic::store(0, &sigint_count);
  2713. ++ for (;;) {
  2714. ++ for (int i = 0; i < NSIG + 1; i++) {
  2715. ++ jint n = pending_signals[i];
  2716. ++ if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
  2717. ++ return i;
  2718. ++ }
  2719. ++ }
  2720. ++ if (!wait) {
  2721. ++ return -1;
  2722. ++ }
  2723. ++ JavaThread *thread = JavaThread::current();
  2724. ++ ThreadBlockInVM tbivm(thread);
  2725. ++
  2726. ++ bool threadIsSuspended;
  2727. ++ do {
  2728. ++ thread->set_suspend_equivalent();
  2729. ++ // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
  2730. ++ ::sem_wait(&sig_sem);
  2731. ++
  2732. ++ // were we externally suspended while we were waiting?
  2733. ++ threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
  2734. ++ if (threadIsSuspended) {
  2735. ++ //
  2736. ++ // The semaphore has been incremented, but while we were waiting
  2737. ++ // another thread suspended us. We don't want to continue running
  2738. ++ // while suspended because that would surprise the thread that
  2739. ++ // suspended us.
  2740. ++ //
  2741. ++ ::sem_post(&sig_sem);
  2742. ++
  2743. ++ thread->java_suspend_self();
  2744. ++ }
  2745. ++ } while (threadIsSuspended);
  2746. ++ }
  2747. ++}
  2748. ++
  2749. ++int os::signal_lookup() {
  2750. ++ return check_pending_signals(false);
  2751. ++}
  2752. ++
  2753. ++int os::signal_wait() {
  2754. ++ return check_pending_signals(true);
  2755. ++}
  2756. ++
  2757. ++////////////////////////////////////////////////////////////////////////////////
  2758. ++// Virtual Memory
  2759. ++
  2760. ++int os::vm_page_size() {
  2761. ++ // Seems redundant as all get out
  2762. ++ assert(os::Linux::page_size() != -1, "must call os::init");
  2763. ++ return os::Linux::page_size();
  2764. ++}
  2765. ++
  2766. ++// Solaris allocates memory by pages.
  2767. ++int os::vm_allocation_granularity() {
  2768. ++ assert(os::Linux::page_size() != -1, "must call os::init");
  2769. ++ return os::Linux::page_size();
  2770. ++}
  2771. ++
  2772. ++// Rationale behind this function:
  2773. ++// current (Mon Apr 25 20:12:18 MSD 2005) oprofile drops samples without executable
  2774. ++// mapping for address (see lookup_dcookie() in the kernel module), thus we cannot get
  2775. ++// samples for JITted code. Here we create private executable mapping over the code cache
  2776. ++// and then we can use standard (well, almost, as mapping can change) way to provide
  2777. ++// info for the reporting script by storing timestamp and location of symbol
  2778. ++void linux_wrap_code(char* base, size_t size) {
  2779. ++ static volatile jint cnt = 0;
  2780. ++
  2781. ++ if (!UseOprofile) {
  2782. ++ return;
  2783. ++ }
  2784. ++
  2785. ++ char buf[PATH_MAX+1];
  2786. ++ int num = Atomic::add(1, &cnt);
  2787. ++
  2788. ++ snprintf(buf, sizeof(buf), "%s/hs-vm-%d-%d",
  2789. ++ os::get_temp_directory(), os::current_process_id(), num);
  2790. ++ unlink(buf);
  2791. ++
  2792. ++ int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);
  2793. ++
  2794. ++ if (fd != -1) {
  2795. ++ off_t rv = ::lseek(fd, size-2, SEEK_SET);
  2796. ++ if (rv != (off_t)-1) {
  2797. ++ if (::write(fd, "", 1) == 1) {
  2798. ++ mmap(base, size,
  2799. ++ PROT_READ|PROT_WRITE|PROT_EXEC,
  2800. ++ MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
  2801. ++ }
  2802. ++ }
  2803. ++ ::close(fd);
  2804. ++ unlink(buf);
  2805. ++ }
  2806. ++}
  2807. ++
  2808. ++static bool recoverable_mmap_error(int err) {
  2809. ++ // See if the error is one we can let the caller handle. This
  2810. ++ // list of errno values comes from JBS-6843484. I can't find a
  2811. ++ // Linux man page that documents this specific set of errno
  2812. ++ // values so while this list currently matches Solaris, it may
  2813. ++ // change as we gain experience with this failure mode.
  2814. ++ switch (err) {
  2815. ++ case EBADF:
  2816. ++ case EINVAL:
  2817. ++ case ENOTSUP:
  2818. ++ // let the caller deal with these errors
  2819. ++ return true;
  2820. ++
  2821. ++ default:
  2822. ++ // Any remaining errors on this OS can cause our reserved mapping
  2823. ++ // to be lost. That can cause confusion where different data
  2824. ++ // structures think they have the same memory mapped. The worst
  2825. ++ // scenario is if both the VM and a library think they have the
  2826. ++ // same memory mapped.
  2827. ++ return false;
  2828. ++ }
  2829. ++}
  2830. ++
  2831. ++static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
  2832. ++ int err) {
  2833. ++ warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2834. ++ ", %d) failed; error='%s' (errno=%d)", addr, size, exec,
  2835. ++ strerror(err), err);
  2836. ++}
  2837. ++
  2838. ++static void warn_fail_commit_memory(char* addr, size_t size,
  2839. ++ size_t alignment_hint, bool exec,
  2840. ++ int err) {
  2841. ++ warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2842. ++ ", " SIZE_FORMAT ", %d) failed; error='%s' (errno=%d)", addr, size,
  2843. ++ alignment_hint, exec, strerror(err), err);
  2844. ++}
  2845. ++
  2846. ++static void warn_fail_commit_memory(char* addr, size_t size,
  2847. ++ size_t alignment_hint, bool exec,
  2848. ++ int err, const char* msg) {
  2849. ++ warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
  2850. ++ ", " SIZE_FORMAT ", %d) failed; error='%s' (errno=%d); %s", addr, size,
  2851. ++ alignment_hint, exec, strerror(err), err, msg);
  2852. ++}
  2853. ++
  2854. ++// NOTE: Linux kernel does not really reserve the pages for us.
  2855. ++// All it does is to check if there are enough free pages
  2856. ++// left at the time of mmap(). This could be a potential
  2857. ++// problem.
  2858. ++int os::Linux::commit_memory_impl(char* addr, size_t size, bool exec) {
  2859. ++ int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
  2860. ++ uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
  2861. ++ MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
  2862. ++ if (res != (uintptr_t) MAP_FAILED) {
  2863. ++ if (UseNUMAInterleaving) {
  2864. ++ numa_make_global(addr, size);
  2865. ++ }
  2866. ++ return 0;
  2867. ++ }
  2868. ++
  2869. ++ int err = errno; // save errno from mmap() call above
  2870. ++
  2871. ++ if (!recoverable_mmap_error(err)) {
  2872. ++ warn_fail_commit_memory(addr, size, exec, err);
  2873. ++ vm_exit_out_of_memory(size, "committing reserved memory.");
  2874. ++ }
  2875. ++
  2876. ++ return err;
  2877. ++}
  2878. ++
  2879. ++bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
  2880. ++ return os::Linux::commit_memory_impl(addr, size, exec) == 0;
  2881. ++}
  2882. ++
  2883. ++void os::pd_commit_memory_or_exit(char* addr, size_t size, bool exec,
  2884. ++ const char* mesg) {
  2885. ++ assert(mesg != NULL, "mesg must be specified");
  2886. ++ int err = os::Linux::commit_memory_impl(addr, size, exec);
  2887. ++ if (err != 0) {
  2888. ++ // the caller wants all commit errors to exit with the specified mesg:
  2889. ++ warn_fail_commit_memory(addr, size, exec, err);
  2890. ++ vm_exit_out_of_memory(size, mesg);
  2891. ++ }
  2892. ++}
  2893. ++
  2894. ++// Define MAP_HUGETLB here so we can build HotSpot on old systems.
  2895. ++#ifndef MAP_HUGETLB
  2896. ++#define MAP_HUGETLB 0x40000
  2897. ++#endif
  2898. ++
  2899. ++// Define MADV_HUGEPAGE here so we can build HotSpot on old systems.
  2900. ++#ifndef MADV_HUGEPAGE
  2901. ++#define MADV_HUGEPAGE 14
  2902. ++#endif
  2903. ++
  2904. ++volatile jint os::Linux::num_largepage_commit_fails = 0;
  2905. ++
  2906. ++int os::Linux::commit_memory_impl(char* addr, size_t size,
  2907. ++ size_t alignment_hint, bool exec) {
  2908. ++ int err;
  2909. ++ if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) {
  2910. ++ int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
  2911. ++ uintptr_t res =
  2912. ++ (uintptr_t) ::mmap(addr, size, prot,
  2913. ++ MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_HUGETLB,
  2914. ++ -1, 0);
  2915. ++ if (res != (uintptr_t) MAP_FAILED) {
  2916. ++ if (UseNUMAInterleaving) {
  2917. ++ numa_make_global(addr, size);
  2918. ++ }
  2919. ++ return 0;
  2920. ++ }
  2921. ++
  2922. ++ err = errno; // save errno from mmap() call above
  2923. ++
  2924. ++ if (!recoverable_mmap_error(err)) {
  2925. ++ // However, it is not clear that this loss of our reserved mapping
  2926. ++ // happens with large pages on Linux or that we cannot recover
  2927. ++ // from the loss. For now, we just issue a warning and we don't
  2928. ++ // call vm_exit_out_of_memory(). This issue is being tracked by
  2929. ++ // JBS-8007074.
  2930. ++ Atomic::inc(&os::Linux::num_largepage_commit_fails);
  2931. ++ warn_fail_commit_memory(addr, size, alignment_hint, exec, err,
  2932. ++ "Cannot allocate large pages, falling back to regular pages");
  2933. ++// vm_exit_out_of_memory(size, "committing reserved memory.");
  2934. ++ }
  2935. ++ // Fall through and try to use small pages
  2936. ++ }
  2937. ++
  2938. ++ err = os::Linux::commit_memory_impl(addr, size, exec);
  2939. ++ if (err == 0) {
  2940. ++ realign_memory(addr, size, alignment_hint);
  2941. ++ }
  2942. ++ return err;
  2943. ++}
  2944. ++
  2945. ++bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
  2946. ++ bool exec) {
  2947. ++ return os::Linux::commit_memory_impl(addr, size, alignment_hint, exec) == 0;
  2948. ++}
  2949. ++
  2950. ++void os::pd_commit_memory_or_exit(char* addr, size_t size,
  2951. ++ size_t alignment_hint, bool exec,
  2952. ++ const char* mesg) {
  2953. ++ assert(mesg != NULL, "mesg must be specified");
  2954. ++ int err = os::Linux::commit_memory_impl(addr, size, alignment_hint, exec);
  2955. ++ if (err != 0) {
  2956. ++ // the caller wants all commit errors to exit with the specified mesg:
  2957. ++ warn_fail_commit_memory(addr, size, alignment_hint, exec, err);
  2958. ++ vm_exit_out_of_memory(size, mesg);
  2959. ++ }
  2960. ++}
  2961. ++
  2962. ++void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
  2963. ++ if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) {
  2964. ++ // We don't check the return value: madvise(MADV_HUGEPAGE) may not
  2965. ++ // be supported or the memory may already be backed by huge pages.
  2966. ++ ::madvise(addr, bytes, MADV_HUGEPAGE);
  2967. ++ }
  2968. ++}
  2969. ++
  2970. ++void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
  2971. ++ // This method works by doing an mmap over an existing mmaping and effectively discarding
  2972. ++ // the existing pages. However it won't work for SHM-based large pages that cannot be
  2973. ++ // uncommitted at all. We don't do anything in this case to avoid creating a segment with
  2974. ++ // small pages on top of the SHM segment. This method always works for small pages, so we
  2975. ++ // allow that in any case.
  2976. ++ if (alignment_hint <= (size_t)os::vm_page_size() || !UseSHM) {
  2977. ++ commit_memory(addr, bytes, alignment_hint, !ExecMem);
  2978. ++ }
  2979. ++}
  2980. ++
  2981. ++void os::numa_make_global(char *addr, size_t bytes) {
  2982. ++ Linux::numa_interleave_memory(addr, bytes);
  2983. ++}
  2984. ++
  2985. ++void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) {
  2986. ++ Linux::numa_tonode_memory(addr, bytes, lgrp_hint);
  2987. ++}
  2988. ++
  2989. ++bool os::numa_topology_changed() { return false; }
  2990. ++
  2991. ++size_t os::numa_get_groups_num() {
  2992. ++ int max_node = Linux::numa_max_node();
  2993. ++ return max_node > 0 ? max_node + 1 : 1;
  2994. ++}
  2995. ++
  2996. ++int os::numa_get_group_id() {
  2997. ++ int cpu_id = Linux::sched_getcpu();
  2998. ++ if (cpu_id != -1) {
  2999. ++ int lgrp_id = Linux::get_node_by_cpu(cpu_id);
  3000. ++ if (lgrp_id != -1) {
  3001. ++ return lgrp_id;
  3002. ++ }
  3003. ++ }
  3004. ++ return 0;
  3005. ++}
  3006. ++
  3007. ++size_t os::numa_get_leaf_groups(int *ids, size_t size) {
  3008. ++ for (size_t i = 0; i < size; i++) {
  3009. ++ ids[i] = i;
  3010. ++ }
  3011. ++ return size;
  3012. ++}
  3013. ++
  3014. ++bool os::get_page_info(char *start, page_info* info) {
  3015. ++ return false;
  3016. ++}
  3017. ++
  3018. ++char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
  3019. ++ return end;
  3020. ++}
  3021. ++
  3022. ++
  3023. ++int os::Linux::sched_getcpu_syscall(void) {
  3024. ++ unsigned int cpu;
  3025. ++ int retval = -1;
  3026. ++
  3027. ++#if defined(IA32)
  3028. ++# ifndef SYS_getcpu
  3029. ++# define SYS_getcpu 318
  3030. ++# endif
  3031. ++ retval = syscall(SYS_getcpu, &cpu, NULL, NULL);
  3032. ++#elif defined(AMD64)
  3033. ++// Unfortunately we have to bring all these macros here from vsyscall.h
  3034. ++// to be able to compile on old linuxes.
  3035. ++# define __NR_vgetcpu 2
  3036. ++# define VSYSCALL_START (-10UL << 20)
  3037. ++# define VSYSCALL_SIZE 1024
  3038. ++# define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
  3039. ++ typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache);
  3040. ++ vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
  3041. ++ retval = vgetcpu(&cpu, NULL, NULL);
  3042. ++#endif
  3043. ++
  3044. ++ return (retval == -1) ? retval : cpu;
  3045. ++}
  3046. ++
  3047. ++// Something to do with the numa-aware allocator needs these symbols
  3048. ++extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { }
  3049. ++extern "C" JNIEXPORT void numa_error(char *where) { }
  3050. ++extern "C" JNIEXPORT int fork1() { return fork(); }
  3051. ++
  3052. ++
  3053. ++// If we are running with libnuma version > 2, then we should
  3054. ++// be trying to use symbols with versions 1.1
  3055. ++// If we are running with earlier version, which did not have symbol versions,
  3056. ++// we should use the base version.
  3057. ++void* os::Linux::libnuma_dlsym(void* handle, const char *name) {
  3058. ++ void *f = dlvsym(handle, name, "libnuma_1.1");
  3059. ++ if (f == NULL) {
  3060. ++ f = dlsym(handle, name);
  3061. ++ }
  3062. ++ return f;
  3063. ++}
  3064. ++
  3065. ++bool os::Linux::libnuma_init() {
  3066. ++ // sched_getcpu() should be in libc.
  3067. ++ set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t,
  3068. ++ dlsym(RTLD_DEFAULT, "sched_getcpu")));
  3069. ++
  3070. ++ // If it's not, try a direct syscall.
  3071. ++ if (sched_getcpu() == -1)
  3072. ++ set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, (void*)&sched_getcpu_syscall));
  3073. ++
  3074. ++ if (sched_getcpu() != -1) { // Does it work?
  3075. ++ void *handle = dlopen("libnuma.so.1", RTLD_LAZY);
  3076. ++ if (handle != NULL) {
  3077. ++ set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t,
  3078. ++ libnuma_dlsym(handle, "numa_node_to_cpus")));
  3079. ++ set_numa_max_node(CAST_TO_FN_PTR(numa_max_node_func_t,
  3080. ++ libnuma_dlsym(handle, "numa_max_node")));
  3081. ++ set_numa_available(CAST_TO_FN_PTR(numa_available_func_t,
  3082. ++ libnuma_dlsym(handle, "numa_available")));
  3083. ++ set_numa_tonode_memory(CAST_TO_FN_PTR(numa_tonode_memory_func_t,
  3084. ++ libnuma_dlsym(handle, "numa_tonode_memory")));
  3085. ++ set_numa_interleave_memory(CAST_TO_FN_PTR(numa_interleave_memory_func_t,
  3086. ++ libnuma_dlsym(handle, "numa_interleave_memory")));
  3087. ++
  3088. ++
  3089. ++ if (numa_available() != -1) {
  3090. ++ set_numa_all_nodes((unsigned long*)libnuma_dlsym(handle, "numa_all_nodes"));
  3091. ++ // Create a cpu -> node mapping
  3092. ++ _cpu_to_node = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int>(0, true);
  3093. ++ rebuild_cpu_to_node_map();
  3094. ++ return true;
  3095. ++ }
  3096. ++ }
  3097. ++ }
  3098. ++ return false;
  3099. ++}
  3100. ++
  3101. ++// rebuild_cpu_to_node_map() constructs a table mapping cpud id to node id.
  3102. ++// The table is later used in get_node_by_cpu().
  3103. ++void os::Linux::rebuild_cpu_to_node_map() {
  3104. ++ const size_t NCPUS = 32768; // Since the buffer size computation is very obscure
  3105. ++ // in libnuma (possible values are starting from 16,
  3106. ++ // and continuing up with every other power of 2, but less
  3107. ++ // than the maximum number of CPUs supported by kernel), and
  3108. ++ // is a subject to change (in libnuma version 2 the requirements
  3109. ++ // are more reasonable) we'll just hardcode the number they use
  3110. ++ // in the library.
  3111. ++ const size_t BitsPerCLong = sizeof(long) * CHAR_BIT;
  3112. ++
  3113. ++ size_t cpu_num = os::active_processor_count();
  3114. ++ size_t cpu_map_size = NCPUS / BitsPerCLong;
  3115. ++ size_t cpu_map_valid_size =
  3116. ++ MIN2((cpu_num + BitsPerCLong - 1) / BitsPerCLong, cpu_map_size);
  3117. ++
  3118. ++ cpu_to_node()->clear();
  3119. ++ cpu_to_node()->at_grow(cpu_num - 1);
  3120. ++ size_t node_num = numa_get_groups_num();
  3121. ++
  3122. ++ unsigned long *cpu_map = NEW_C_HEAP_ARRAY(unsigned long, cpu_map_size, mtInternal);
  3123. ++ for (size_t i = 0; i < node_num; i++) {
  3124. ++ if (numa_node_to_cpus(i, cpu_map, cpu_map_size * sizeof(unsigned long)) != -1) {
  3125. ++ for (size_t j = 0; j < cpu_map_valid_size; j++) {
  3126. ++ if (cpu_map[j] != 0) {
  3127. ++ for (size_t k = 0; k < BitsPerCLong; k++) {
  3128. ++ if (cpu_map[j] & (1UL << k)) {
  3129. ++ cpu_to_node()->at_put(j * BitsPerCLong + k, i);
  3130. ++ }
  3131. ++ }
  3132. ++ }
  3133. ++ }
  3134. ++ }
  3135. ++ }
  3136. ++ FREE_C_HEAP_ARRAY(unsigned long, cpu_map, mtInternal);
  3137. ++}
  3138. ++
  3139. ++int os::Linux::get_node_by_cpu(int cpu_id) {
  3140. ++ if (cpu_to_node() != NULL && cpu_id >= 0 && cpu_id < cpu_to_node()->length()) {
  3141. ++ return cpu_to_node()->at(cpu_id);
  3142. ++ }
  3143. ++ return -1;
  3144. ++}
  3145. ++
  3146. ++GrowableArray<int>* os::Linux::_cpu_to_node;
  3147. ++os::Linux::sched_getcpu_func_t os::Linux::_sched_getcpu;
  3148. ++os::Linux::numa_node_to_cpus_func_t os::Linux::_numa_node_to_cpus;
  3149. ++os::Linux::numa_max_node_func_t os::Linux::_numa_max_node;
  3150. ++os::Linux::numa_available_func_t os::Linux::_numa_available;
  3151. ++os::Linux::numa_tonode_memory_func_t os::Linux::_numa_tonode_memory;
  3152. ++os::Linux::numa_interleave_memory_func_t os::Linux::_numa_interleave_memory;
  3153. ++unsigned long* os::Linux::_numa_all_nodes;
  3154. ++
  3155. ++bool os::pd_uncommit_memory(char* addr, size_t size) {
  3156. ++ uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
  3157. ++ MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
  3158. ++ return res != (uintptr_t) MAP_FAILED;
  3159. ++}
  3160. ++
  3161. ++static
  3162. ++address get_stack_commited_bottom(address bottom, size_t size) {
  3163. ++ address nbot = bottom;
  3164. ++ address ntop = bottom + size;
  3165. ++
  3166. ++ size_t page_sz = os::vm_page_size();
  3167. ++ unsigned pages = size / page_sz;
  3168. ++
  3169. ++ unsigned char vec[1];
  3170. ++ unsigned imin = 1, imax = pages + 1, imid;
  3171. ++ int mincore_return_value;
  3172. ++
  3173. ++ while (imin < imax) {
  3174. ++ imid = (imax + imin) / 2;
  3175. ++ nbot = ntop - (imid * page_sz);
  3176. ++
  3177. ++ // Use a trick with mincore to check whether the page is mapped or not.
  3178. ++ // mincore sets vec to 1 if page resides in memory and to 0 if page
  3179. ++ // is swapped output but if page we are asking for is unmapped
  3180. ++ // it returns -1,ENOMEM
  3181. ++ mincore_return_value = mincore(nbot, page_sz, vec);
  3182. ++
  3183. ++ if (mincore_return_value == -1) {
  3184. ++ // Page is not mapped go up
  3185. ++ // to find first mapped page
  3186. ++ if (errno != EAGAIN) {
  3187. ++ assert(errno == ENOMEM, "Unexpected mincore errno");
  3188. ++ imax = imid;
  3189. ++ }
  3190. ++ } else {
  3191. ++ // Page is mapped go down
  3192. ++ // to find first not mapped page
  3193. ++ imin = imid + 1;
  3194. ++ }
  3195. ++ }
  3196. ++
  3197. ++ nbot = nbot + page_sz;
  3198. ++
  3199. ++ // Adjust stack bottom one page up if last checked page is not mapped
  3200. ++ if (mincore_return_value == -1) {
  3201. ++ nbot = nbot + page_sz;
  3202. ++ }
  3203. ++
  3204. ++ return nbot;
  3205. ++}
  3206. ++
  3207. ++
  3208. ++// Linux uses a growable mapping for the stack, and if the mapping for
  3209. ++// the stack guard pages is not removed when we detach a thread the
  3210. ++// stack cannot grow beyond the pages where the stack guard was
  3211. ++// mapped. If at some point later in the process the stack expands to
  3212. ++// that point, the Linux kernel cannot expand the stack any further
  3213. ++// because the guard pages are in the way, and a segfault occurs.
  3214. ++//
  3215. ++// However, it's essential not to split the stack region by unmapping
  3216. ++// a region (leaving a hole) that's already part of the stack mapping,
  3217. ++// so if the stack mapping has already grown beyond the guard pages at
  3218. ++// the time we create them, we have to truncate the stack mapping.
  3219. ++// So, we need to know the extent of the stack mapping when
  3220. ++// create_stack_guard_pages() is called.
  3221. ++
  3222. ++// We only need this for stacks that are growable: at the time of
  3223. ++// writing thread stacks don't use growable mappings (i.e. those
  3224. ++// creeated with MAP_GROWSDOWN), and aren't marked "[stack]", so this
  3225. ++// only applies to the main thread.
  3226. ++
  3227. ++// If the (growable) stack mapping already extends beyond the point
  3228. ++// where we're going to put our guard pages, truncate the mapping at
  3229. ++// that point by munmap()ping it. This ensures that when we later
  3230. ++// munmap() the guard pages we don't leave a hole in the stack
  3231. ++// mapping. This only affects the main/initial thread
  3232. ++
  3233. ++bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
  3234. ++
  3235. ++ if (os::Linux::is_initial_thread()) {
  3236. ++ // As we manually grow stack up to bottom inside create_attached_thread(),
  3237. ++ // it's likely that os::Linux::initial_thread_stack_bottom is mapped and
  3238. ++ // we don't need to do anything special.
  3239. ++ // Check it first, before calling heavy function.
  3240. ++ uintptr_t stack_extent = (uintptr_t) os::Linux::initial_thread_stack_bottom();
  3241. ++ unsigned char vec[1];
  3242. ++
  3243. ++ if (mincore((address)stack_extent, os::vm_page_size(), vec) == -1) {
  3244. ++ // Fallback to slow path on all errors, including EAGAIN
  3245. ++ stack_extent = (uintptr_t) get_stack_commited_bottom(
  3246. ++ os::Linux::initial_thread_stack_bottom(),
  3247. ++ (size_t)addr - stack_extent);
  3248. ++ }
  3249. ++
  3250. ++ if (stack_extent < (uintptr_t)addr) {
  3251. ++ ::munmap((void*)stack_extent, (uintptr_t)(addr - stack_extent));
  3252. ++ }
  3253. ++ }
  3254. ++
  3255. ++ return os::commit_memory(addr, size, !ExecMem);
  3256. ++}
  3257. ++
  3258. ++// If this is a growable mapping, remove the guard pages entirely by
  3259. ++// munmap()ping them. If not, just call uncommit_memory(). This only
  3260. ++// affects the main/initial thread, but guard against future OS changes
  3261. ++// It's safe to always unmap guard pages for initial thread because we
  3262. ++// always place it right after end of the mapped region
  3263. ++
  3264. ++bool os::remove_stack_guard_pages(char* addr, size_t size) {
  3265. ++ uintptr_t stack_extent, stack_base;
  3266. ++
  3267. ++ if (os::Linux::is_initial_thread()) {
  3268. ++ return ::munmap(addr, size) == 0;
  3269. ++ }
  3270. ++
  3271. ++ return os::uncommit_memory(addr, size);
  3272. ++}
  3273. ++
  3274. ++static address _highest_vm_reserved_address = NULL;
  3275. ++
  3276. ++// If 'fixed' is true, anon_mmap() will attempt to reserve anonymous memory
  3277. ++// at 'requested_addr'. If there are existing memory mappings at the same
  3278. ++// location, however, they will be overwritten. If 'fixed' is false,
  3279. ++// 'requested_addr' is only treated as a hint, the return value may or
  3280. ++// may not start from the requested address. Unlike Linux mmap(), this
  3281. ++// function returns NULL to indicate failure.
  3282. ++static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) {
  3283. ++ char * addr;
  3284. ++ int flags;
  3285. ++
  3286. ++ flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS;
  3287. ++ if (fixed) {
  3288. ++ assert((uintptr_t)requested_addr % os::Linux::page_size() == 0, "unaligned address");
  3289. ++ flags |= MAP_FIXED;
  3290. ++ }
  3291. ++
  3292. ++ // Map uncommitted pages PROT_READ and PROT_WRITE, change access
  3293. ++ // to PROT_EXEC if executable when we commit the page.
  3294. ++ addr = (char*)::mmap(requested_addr, bytes, PROT_READ|PROT_WRITE,
  3295. ++ flags, -1, 0);
  3296. ++
  3297. ++ if (addr != MAP_FAILED) {
  3298. ++ // anon_mmap() should only get called during VM initialization,
  3299. ++ // don't need lock (actually we can skip locking even it can be called
  3300. ++ // from multiple threads, because _highest_vm_reserved_address is just a
  3301. ++ // hint about the upper limit of non-stack memory regions.)
  3302. ++ if ((address)addr + bytes > _highest_vm_reserved_address) {
  3303. ++ _highest_vm_reserved_address = (address)addr + bytes;
  3304. ++ }
  3305. ++ }
  3306. ++
  3307. ++ return addr == MAP_FAILED ? NULL : addr;
  3308. ++}
  3309. ++
  3310. ++// Don't update _highest_vm_reserved_address, because there might be memory
  3311. ++// regions above addr + size. If so, releasing a memory region only creates
  3312. ++// a hole in the address space, it doesn't help prevent heap-stack collision.
  3313. ++//
  3314. ++static int anon_munmap(char * addr, size_t size) {
  3315. ++ return ::munmap(addr, size) == 0;
  3316. ++}
  3317. ++
  3318. ++char* os::pd_reserve_memory(size_t bytes, char* requested_addr,
  3319. ++ size_t alignment_hint) {
  3320. ++ return anon_mmap(requested_addr, bytes, (requested_addr != NULL));
  3321. ++}
  3322. ++
  3323. ++bool os::pd_release_memory(char* addr, size_t size) {
  3324. ++ return anon_munmap(addr, size);
  3325. ++}
  3326. ++
  3327. ++static address highest_vm_reserved_address() {
  3328. ++ return _highest_vm_reserved_address;
  3329. ++}
  3330. ++
  3331. ++static bool linux_mprotect(char* addr, size_t size, int prot) {
  3332. ++ // Linux wants the mprotect address argument to be page aligned.
  3333. ++ char* bottom = (char*)align_size_down((intptr_t)addr, os::Linux::page_size());
  3334. ++
  3335. ++ // According to SUSv3, mprotect() should only be used with mappings
  3336. ++ // established by mmap(), and mmap() always maps whole pages. Unaligned
  3337. ++ // 'addr' likely indicates problem in the VM (e.g. trying to change
  3338. ++ // protection of malloc'ed or statically allocated memory). Check the
  3339. ++ // caller if you hit this assert.
  3340. ++ assert(addr == bottom, "sanity check");
  3341. ++
  3342. ++ size = align_size_up(pointer_delta(addr, bottom, 1) + size, os::Linux::page_size());
  3343. ++ return ::mprotect(bottom, size, prot) == 0;
  3344. ++}
  3345. ++
  3346. ++// Set protections specified
  3347. ++bool os::protect_memory(char* addr, size_t bytes, ProtType prot,
  3348. ++ bool is_committed) {
  3349. ++ unsigned int p = 0;
  3350. ++ switch (prot) {
  3351. ++ case MEM_PROT_NONE: p = PROT_NONE; break;
  3352. ++ case MEM_PROT_READ: p = PROT_READ; break;
  3353. ++ case MEM_PROT_RW: p = PROT_READ|PROT_WRITE; break;
  3354. ++ case MEM_PROT_RWX: p = PROT_READ|PROT_WRITE|PROT_EXEC; break;
  3355. ++ default:
  3356. ++ ShouldNotReachHere();
  3357. ++ }
  3358. ++ // is_committed is unused.
  3359. ++ return linux_mprotect(addr, bytes, p);
  3360. ++}
  3361. ++
  3362. ++bool os::guard_memory(char* addr, size_t size) {
  3363. ++ return linux_mprotect(addr, size, PROT_NONE);
  3364. ++}
  3365. ++
  3366. ++bool os::unguard_memory(char* addr, size_t size) {
  3367. ++ return linux_mprotect(addr, size, PROT_READ|PROT_WRITE);
  3368. ++}
  3369. ++
  3370. ++bool os::Linux::hugetlbfs_sanity_check(bool warn, size_t page_size) {
  3371. ++ bool result = false;
  3372. ++ void *p = mmap (NULL, page_size, PROT_READ|PROT_WRITE,
  3373. ++ MAP_ANONYMOUS|MAP_PRIVATE|MAP_HUGETLB,
  3374. ++ -1, 0);
  3375. ++
  3376. ++ if (p != MAP_FAILED) {
  3377. ++ // We don't know if this really is a huge page or not.
  3378. ++ FILE *fp = fopen("/proc/self/maps", "r");
  3379. ++ if (fp) {
  3380. ++ while (!feof(fp)) {
  3381. ++ char chars[257];
  3382. ++ long x = 0;
  3383. ++ if (fgets(chars, sizeof(chars), fp)) {
  3384. ++ if (sscanf(chars, "%lx-%*x", &x) == 1
  3385. ++ && x == (long)p) {
  3386. ++ if (strstr (chars, "hugepage")) {
  3387. ++ result = true;
  3388. ++ break;
  3389. ++ }
  3390. ++ }
  3391. ++ }
  3392. ++ }
  3393. ++ fclose(fp);
  3394. ++ }
  3395. ++ munmap (p, page_size);
  3396. ++ if (result)
  3397. ++ return true;
  3398. ++ }
  3399. ++
  3400. ++ if (warn) {
  3401. ++ warning("HugeTLBFS is not supported by the operating system.");
  3402. ++ }
  3403. ++
  3404. ++ return result;
  3405. ++}
  3406. ++
  3407. ++/*
  3408. ++* Set the coredump_filter bits to include largepages in core dump (bit 6)
  3409. ++*
  3410. ++* From the coredump_filter documentation:
  3411. ++*
  3412. ++* - (bit 0) anonymous private memory
  3413. ++* - (bit 1) anonymous shared memory
  3414. ++* - (bit 2) file-backed private memory
  3415. ++* - (bit 3) file-backed shared memory
  3416. ++* - (bit 4) ELF header pages in file-backed private memory areas (it is
  3417. ++* effective only if the bit 2 is cleared)
  3418. ++* - (bit 5) hugetlb private memory
  3419. ++* - (bit 6) hugetlb shared memory
  3420. ++*/
  3421. ++static void set_coredump_filter(void) {
  3422. ++ FILE *f;
  3423. ++ long cdm;
  3424. ++
  3425. ++ if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) {
  3426. ++ return;
  3427. ++ }
  3428. ++
  3429. ++ if (fscanf(f, "%lx", &cdm) != 1) {
  3430. ++ fclose(f);
  3431. ++ return;
  3432. ++ }
  3433. ++
  3434. ++ rewind(f);
  3435. ++
  3436. ++ if ((cdm & LARGEPAGES_BIT) == 0) {
  3437. ++ cdm |= LARGEPAGES_BIT;
  3438. ++ fprintf(f, "%#lx", cdm);
  3439. ++ }
  3440. ++
  3441. ++ fclose(f);
  3442. ++}
  3443. ++
  3444. ++// Large page support
  3445. ++
  3446. ++static size_t _large_page_size = 0;
  3447. ++
  3448. ++void os::large_page_init() {
  3449. ++ if (!UseLargePages) {
  3450. ++ UseHugeTLBFS = false;
  3451. ++ UseSHM = false;
  3452. ++ return;
  3453. ++ }
  3454. ++
  3455. ++ if (FLAG_IS_DEFAULT(UseHugeTLBFS) && FLAG_IS_DEFAULT(UseSHM)) {
  3456. ++ // If UseLargePages is specified on the command line try both methods,
  3457. ++ // if it's default, then try only HugeTLBFS.
  3458. ++ if (FLAG_IS_DEFAULT(UseLargePages)) {
  3459. ++ UseHugeTLBFS = true;
  3460. ++ } else {
  3461. ++ UseHugeTLBFS = UseSHM = true;
  3462. ++ }
  3463. ++ }
  3464. ++
  3465. ++ if (LargePageSizeInBytes) {
  3466. ++ _large_page_size = LargePageSizeInBytes;
  3467. ++ } else {
  3468. ++ // large_page_size on Linux is used to round up heap size. x86 uses either
  3469. ++ // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
  3470. ++ // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
  3471. ++ // page as large as 256M.
  3472. ++ //
  3473. ++ // Here we try to figure out page size by parsing /proc/meminfo and looking
  3474. ++ // for a line with the following format:
  3475. ++ // Hugepagesize: 2048 kB
  3476. ++ //
  3477. ++ // If we can't determine the value (e.g. /proc is not mounted, or the text
  3478. ++ // format has been changed), we'll use the largest page size supported by
  3479. ++ // the processor.
  3480. ++
  3481. ++#ifndef ZERO
  3482. ++ _large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M)
  3483. ++ ARM_ONLY(2 * M) PPC_ONLY(4 * M);
  3484. ++#endif // ZERO
  3485. ++
  3486. ++ FILE *fp = fopen("/proc/meminfo", "r");
  3487. ++ if (fp) {
  3488. ++ while (!feof(fp)) {
  3489. ++ int x = 0;
  3490. ++ char buf[16];
  3491. ++ if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
  3492. ++ if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
  3493. ++ _large_page_size = x * K;
  3494. ++ break;
  3495. ++ }
  3496. ++ } else {
  3497. ++ // skip to next line
  3498. ++ for (;;) {
  3499. ++ int ch = fgetc(fp);
  3500. ++ if (ch == EOF || ch == (int)'\n') break;
  3501. ++ }
  3502. ++ }
  3503. ++ }
  3504. ++ fclose(fp);
  3505. ++ }
  3506. ++ }
  3507. ++
  3508. ++ // print a warning if any large page related flag is specified on command line
  3509. ++ bool warn_on_failure = !FLAG_IS_DEFAULT(UseHugeTLBFS);
  3510. ++
  3511. ++ const size_t default_page_size = (size_t)Linux::page_size();
  3512. ++ if (_large_page_size > default_page_size) {
  3513. ++ _page_sizes[0] = _large_page_size;
  3514. ++ _page_sizes[1] = default_page_size;
  3515. ++ _page_sizes[2] = 0;
  3516. ++ }
  3517. ++ UseHugeTLBFS = UseHugeTLBFS &&
  3518. ++ Linux::hugetlbfs_sanity_check(warn_on_failure, _large_page_size);
  3519. ++
  3520. ++ if (UseHugeTLBFS)
  3521. ++ UseSHM = false;
  3522. ++
  3523. ++ UseLargePages = UseHugeTLBFS || UseSHM;
  3524. ++
  3525. ++ set_coredump_filter();
  3526. ++}
  3527. ++
  3528. ++#ifndef SHM_HUGETLB
  3529. ++#define SHM_HUGETLB 04000
  3530. ++#endif
  3531. ++
  3532. ++char* os::reserve_memory_special(size_t bytes, char* req_addr, bool exec) {
  3533. ++ // "exec" is passed in but not used. Creating the shared image for
  3534. ++ // the code cache doesn't have an SHM_X executable permission to check.
  3535. ++ assert(UseLargePages && UseSHM, "only for SHM large pages");
  3536. ++
  3537. ++ key_t key = IPC_PRIVATE;
  3538. ++ char *addr;
  3539. ++
  3540. ++ bool warn_on_failure = UseLargePages &&
  3541. ++ (!FLAG_IS_DEFAULT(UseLargePages) ||
  3542. ++ !FLAG_IS_DEFAULT(LargePageSizeInBytes)
  3543. ++ );
  3544. ++ char msg[128];
  3545. ++
  3546. ++ // Create a large shared memory region to attach to based on size.
  3547. ++ // Currently, size is the total size of the heap
  3548. ++ int shmid = shmget(key, bytes, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
  3549. ++ if (shmid == -1) {
  3550. ++ // Possible reasons for shmget failure:
  3551. ++ // 1. shmmax is too small for Java heap.
  3552. ++ // > check shmmax value: cat /proc/sys/kernel/shmmax
  3553. ++ // > increase shmmax value: echo "0xffffffff" > /proc/sys/kernel/shmmax
  3554. ++ // 2. not enough large page memory.
  3555. ++ // > check available large pages: cat /proc/meminfo
  3556. ++ // > increase amount of large pages:
  3557. ++ // echo new_value > /proc/sys/vm/nr_hugepages
  3558. ++ // Note 1: different Linux may use different name for this property,
  3559. ++ // e.g. on Redhat AS-3 it is "hugetlb_pool".
  3560. ++ // Note 2: it's possible there's enough physical memory available but
  3561. ++ // they are so fragmented after a long run that they can't
  3562. ++ // coalesce into large pages. Try to reserve large pages when
  3563. ++ // the system is still "fresh".
  3564. ++ if (warn_on_failure) {
  3565. ++ jio_snprintf(msg, sizeof(msg), "Failed to reserve shared memory (errno = %d).", errno);
  3566. ++ warning(msg);
  3567. ++ }
  3568. ++ return NULL;
  3569. ++ }
  3570. ++
  3571. ++ // attach to the region
  3572. ++ addr = (char*)shmat(shmid, req_addr, 0);
  3573. ++ int err = errno;
  3574. ++
  3575. ++ // Remove shmid. If shmat() is successful, the actual shared memory segment
  3576. ++ // will be deleted when it's detached by shmdt() or when the process
  3577. ++ // terminates. If shmat() is not successful this will remove the shared
  3578. ++ // segment immediately.
  3579. ++ shmctl(shmid, IPC_RMID, NULL);
  3580. ++
  3581. ++ if ((intptr_t)addr == -1) {
  3582. ++ if (warn_on_failure) {
  3583. ++ jio_snprintf(msg, sizeof(msg), "Failed to attach shared memory (errno = %d).", err);
  3584. ++ warning(msg);
  3585. ++ }
  3586. ++ return NULL;
  3587. ++ }
  3588. ++
  3589. ++ if ((addr != NULL) && UseNUMAInterleaving) {
  3590. ++ numa_make_global(addr, bytes);
  3591. ++ }
  3592. ++
  3593. ++ // The memory is committed
  3594. ++ MemTracker::record_virtual_memory_reserve_and_commit((address)addr, bytes, mtNone, CALLER_PC);
  3595. ++
  3596. ++ return addr;
  3597. ++}
  3598. ++
  3599. ++bool os::release_memory_special(char* base, size_t bytes) {
  3600. ++ MemTracker::Tracker tkr = MemTracker::get_virtual_memory_release_tracker();
  3601. ++ // detaching the SHM segment will also delete it, see reserve_memory_special()
  3602. ++ int rslt = shmdt(base);
  3603. ++ if (rslt == 0) {
  3604. ++ tkr.record((address)base, bytes);
  3605. ++ return true;
  3606. ++ } else {
  3607. ++ tkr.discard();
  3608. ++ return false;
  3609. ++ }
  3610. ++}
  3611. ++
  3612. ++size_t os::large_page_size() {
  3613. ++ return _large_page_size;
  3614. ++}
  3615. ++
  3616. ++// HugeTLBFS allows application to commit large page memory on demand;
  3617. ++// with SysV SHM the entire memory region must be allocated as shared
  3618. ++// memory.
  3619. ++bool os::can_commit_large_page_memory() {
  3620. ++ return UseHugeTLBFS;
  3621. ++}
  3622. ++
  3623. ++bool os::can_execute_large_page_memory() {
  3624. ++ return UseHugeTLBFS;
  3625. ++}
  3626. ++
  3627. ++// Reserve memory at an arbitrary address, only if that area is
  3628. ++// available (and not reserved for something else).
  3629. ++
  3630. ++char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
  3631. ++ const int max_tries = 10;
  3632. ++ char* base[max_tries];
  3633. ++ size_t size[max_tries];
  3634. ++ const size_t gap = 0x000000;
  3635. ++
  3636. ++ // Assert only that the size is a multiple of the page size, since
  3637. ++ // that's all that mmap requires, and since that's all we really know
  3638. ++ // about at this low abstraction level. If we need higher alignment,
  3639. ++ // we can either pass an alignment to this method or verify alignment
  3640. ++ // in one of the methods further up the call chain. See bug 5044738.
  3641. ++ assert(bytes % os::vm_page_size() == 0, "reserving unexpected size block");
  3642. ++
  3643. ++ // Repeatedly allocate blocks until the block is allocated at the
  3644. ++ // right spot. Give up after max_tries. Note that reserve_memory() will
  3645. ++ // automatically update _highest_vm_reserved_address if the call is
  3646. ++ // successful. The variable tracks the highest memory address every reserved
  3647. ++ // by JVM. It is used to detect heap-stack collision if running with
  3648. ++ // fixed-stack LinuxThreads. Because here we may attempt to reserve more
  3649. ++ // space than needed, it could confuse the collision detecting code. To
  3650. ++ // solve the problem, save current _highest_vm_reserved_address and
  3651. ++ // calculate the correct value before return.
  3652. ++ address old_highest = _highest_vm_reserved_address;
  3653. ++
  3654. ++ // Linux mmap allows caller to pass an address as hint; give it a try first,
  3655. ++ // if kernel honors the hint then we can return immediately.
  3656. ++ char * addr = anon_mmap(requested_addr, bytes, false);
  3657. ++ if (addr == requested_addr) {
  3658. ++ return requested_addr;
  3659. ++ }
  3660. ++
  3661. ++ if (addr != NULL) {
  3662. ++ // mmap() is successful but it fails to reserve at the requested address
  3663. ++ anon_munmap(addr, bytes);
  3664. ++ }
  3665. ++
  3666. ++ int i;
  3667. ++ for (i = 0; i < max_tries; ++i) {
  3668. ++ base[i] = reserve_memory(bytes);
  3669. ++
  3670. ++ if (base[i] != NULL) {
  3671. ++ // Is this the block we wanted?
  3672. ++ if (base[i] == requested_addr) {
  3673. ++ size[i] = bytes;
  3674. ++ break;
  3675. ++ }
  3676. ++
  3677. ++ // Does this overlap the block we wanted? Give back the overlapped
  3678. ++ // parts and try again.
  3679. ++
  3680. ++ size_t top_overlap = requested_addr + (bytes + gap) - base[i];
  3681. ++ if (top_overlap >= 0 && top_overlap < bytes) {
  3682. ++ unmap_memory(base[i], top_overlap);
  3683. ++ base[i] += top_overlap;
  3684. ++ size[i] = bytes - top_overlap;
  3685. ++ } else {
  3686. ++ size_t bottom_overlap = base[i] + bytes - requested_addr;
  3687. ++ if (bottom_overlap >= 0 && bottom_overlap < bytes) {
  3688. ++ unmap_memory(requested_addr, bottom_overlap);
  3689. ++ size[i] = bytes - bottom_overlap;
  3690. ++ } else {
  3691. ++ size[i] = bytes;
  3692. ++ }
  3693. ++ }
  3694. ++ }
  3695. ++ }
  3696. ++
  3697. ++ // Give back the unused reserved pieces.
  3698. ++
  3699. ++ for (int j = 0; j < i; ++j) {
  3700. ++ if (base[j] != NULL) {
  3701. ++ unmap_memory(base[j], size[j]);
  3702. ++ }
  3703. ++ }
  3704. ++
  3705. ++ if (i < max_tries) {
  3706. ++ _highest_vm_reserved_address = MAX2(old_highest, (address)requested_addr + bytes);
  3707. ++ return requested_addr;
  3708. ++ } else {
  3709. ++ _highest_vm_reserved_address = old_highest;
  3710. ++ return NULL;
  3711. ++ }
  3712. ++}
  3713. ++
  3714. ++size_t os::read(int fd, void *buf, unsigned int nBytes) {
  3715. ++ return ::read(fd, buf, nBytes);
  3716. ++}
  3717. ++
  3718. ++// TODO-FIXME: reconcile Solaris' os::sleep with the linux variation.
  3719. ++// Solaris uses poll(), linux uses park().
  3720. ++// Poll() is likely a better choice, assuming that Thread.interrupt()
  3721. ++// generates a SIGUSRx signal. Note that SIGUSR1 can interfere with
  3722. ++// SIGSEGV, see 4355769.
  3723. ++
  3724. ++int os::sleep(Thread* thread, jlong millis, bool interruptible) {
  3725. ++ assert(thread == Thread::current(), "thread consistency check");
  3726. ++
  3727. ++ ParkEvent * const slp = thread->_SleepEvent ;
  3728. ++ slp->reset() ;
  3729. ++ OrderAccess::fence() ;
  3730. ++
  3731. ++ if (interruptible) {
  3732. ++ jlong prevtime = javaTimeNanos();
  3733. ++
  3734. ++ for (;;) {
  3735. ++ if (os::is_interrupted(thread, true)) {
  3736. ++ return OS_INTRPT;
  3737. ++ }
  3738. ++
  3739. ++ jlong newtime = javaTimeNanos();
  3740. ++
  3741. ++ if (newtime - prevtime < 0) {
  3742. ++ // time moving backwards, should only happen if no monotonic clock
  3743. ++ // not a guarantee() because JVM should not abort on kernel/glibc bugs
  3744. ++ assert(!Linux::supports_monotonic_clock(), "time moving backwards");
  3745. ++ } else {
  3746. ++ millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
  3747. ++ }
  3748. ++
  3749. ++ if(millis <= 0) {
  3750. ++ return OS_OK;
  3751. ++ }
  3752. ++
  3753. ++ prevtime = newtime;
  3754. ++
  3755. ++ {
  3756. ++ assert(thread->is_Java_thread(), "sanity check");
  3757. ++ JavaThread *jt = (JavaThread *) thread;
  3758. ++ ThreadBlockInVM tbivm(jt);
  3759. ++ OSThreadWaitState osts(jt->osthread(), false /* not Object.wait() */);
  3760. ++
  3761. ++ jt->set_suspend_equivalent();
  3762. ++ // cleared by handle_special_suspend_equivalent_condition() or
  3763. ++ // java_suspend_self() via check_and_wait_while_suspended()
  3764. ++
  3765. ++ slp->park(millis);
  3766. ++
  3767. ++ // were we externally suspended while we were waiting?
  3768. ++ jt->check_and_wait_while_suspended();
  3769. ++ }
  3770. ++ }
  3771. ++ } else {
  3772. ++ OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
  3773. ++ jlong prevtime = javaTimeNanos();
  3774. ++
  3775. ++ for (;;) {
  3776. ++ // It'd be nice to avoid the back-to-back javaTimeNanos() calls on
  3777. ++ // the 1st iteration ...
  3778. ++ jlong newtime = javaTimeNanos();
  3779. ++
  3780. ++ if (newtime - prevtime < 0) {
  3781. ++ // time moving backwards, should only happen if no monotonic clock
  3782. ++ // not a guarantee() because JVM should not abort on kernel/glibc bugs
  3783. ++ assert(!Linux::supports_monotonic_clock(), "time moving backwards");
  3784. ++ } else {
  3785. ++ millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
  3786. ++ }
  3787. ++
  3788. ++ if(millis <= 0) break ;
  3789. ++
  3790. ++ prevtime = newtime;
  3791. ++ slp->park(millis);
  3792. ++ }
  3793. ++ return OS_OK ;
  3794. ++ }
  3795. ++}
  3796. ++
  3797. ++int os::naked_sleep() {
  3798. ++ // %% make the sleep time an integer flag. for now use 1 millisec.
  3799. ++ return os::sleep(Thread::current(), 1, false);
  3800. ++}
  3801. ++
  3802. ++// Sleep forever; naked call to OS-specific sleep; use with CAUTION
  3803. ++void os::infinite_sleep() {
  3804. ++ while (true) { // sleep forever ...
  3805. ++ ::sleep(100); // ... 100 seconds at a time
  3806. ++ }
  3807. ++}
  3808. ++
  3809. ++// Used to convert frequent JVM_Yield() to nops
  3810. ++bool os::dont_yield() {
  3811. ++ return DontYieldALot;
  3812. ++}
  3813. ++
  3814. ++void os::yield() {
  3815. ++ sched_yield();
  3816. ++}
  3817. ++
  3818. ++os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN ;}
  3819. ++
  3820. ++void os::yield_all(int attempts) {
  3821. ++ // Yields to all threads, including threads with lower priorities
  3822. ++ // Threads on Linux are all with same priority. The Solaris style
  3823. ++ // os::yield_all() with nanosleep(1ms) is not necessary.
  3824. ++ sched_yield();
  3825. ++}
  3826. ++
  3827. ++// Called from the tight loops to possibly influence time-sharing heuristics
  3828. ++void os::loop_breaker(int attempts) {
  3829. ++ os::yield_all(attempts);
  3830. ++}
  3831. ++
  3832. ++////////////////////////////////////////////////////////////////////////////////
  3833. ++// thread priority support
  3834. ++
  3835. ++// Note: Normal Linux applications are run with SCHED_OTHER policy. SCHED_OTHER
  3836. ++// only supports dynamic priority, static priority must be zero. For real-time
  3837. ++// applications, Linux supports SCHED_RR which allows static priority (1-99).
  3838. ++// However, for large multi-threaded applications, SCHED_RR is not only slower
  3839. ++// than SCHED_OTHER, but also very unstable (my volano tests hang hard 4 out
  3840. ++// of 5 runs - Sep 2005).
  3841. ++//
  3842. ++// The following code actually changes the niceness of kernel-thread/LWP. It
  3843. ++// has an assumption that setpriority() only modifies one kernel-thread/LWP,
  3844. ++// not the entire user process, and user level threads are 1:1 mapped to kernel
  3845. ++// threads. It has always been the case, but could change in the future. For
  3846. ++// this reason, the code should not be used as default (ThreadPriorityPolicy=0).
  3847. ++// It is only used when ThreadPriorityPolicy=1 and requires root privilege.
  3848. ++
  3849. ++int os::java_to_os_priority[CriticalPriority + 1] = {
  3850. ++ 19, // 0 Entry should never be used
  3851. ++
  3852. ++ 4, // 1 MinPriority
  3853. ++ 3, // 2
  3854. ++ 2, // 3
  3855. ++
  3856. ++ 1, // 4
  3857. ++ 0, // 5 NormPriority
  3858. ++ -1, // 6
  3859. ++
  3860. ++ -2, // 7
  3861. ++ -3, // 8
  3862. ++ -4, // 9 NearMaxPriority
  3863. ++
  3864. ++ -5, // 10 MaxPriority
  3865. ++
  3866. ++ -5 // 11 CriticalPriority
  3867. ++};
  3868. ++
  3869. ++static int prio_init() {
  3870. ++ if (ThreadPriorityPolicy == 1) {
  3871. ++ // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1
  3872. ++ // if effective uid is not root. Perhaps, a more elegant way of doing
  3873. ++ // this is to test CAP_SYS_NICE capability, but that will require libcap.so
  3874. ++ if (geteuid() != 0) {
  3875. ++ if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) {
  3876. ++ warning("-XX:ThreadPriorityPolicy requires root privilege on Linux");
  3877. ++ }
  3878. ++ ThreadPriorityPolicy = 0;
  3879. ++ }
  3880. ++ }
  3881. ++ if (UseCriticalJavaThreadPriority) {
  3882. ++ os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority];
  3883. ++ }
  3884. ++ return 0;
  3885. ++}
  3886. ++
  3887. ++OSReturn os::set_native_priority(Thread* thread, int newpri) {
  3888. ++ if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) return OS_OK;
  3889. ++
  3890. ++ int ret = setpriority(PRIO_PROCESS, thread->osthread()->thread_id(), newpri);
  3891. ++ return (ret == 0) ? OS_OK : OS_ERR;
  3892. ++}
  3893. ++
  3894. ++OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
  3895. ++ if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) {
  3896. ++ *priority_ptr = java_to_os_priority[NormPriority];
  3897. ++ return OS_OK;
  3898. ++ }
  3899. ++
  3900. ++ errno = 0;
  3901. ++ *priority_ptr = getpriority(PRIO_PROCESS, thread->osthread()->thread_id());
  3902. ++ return (*priority_ptr != -1 || errno == 0 ? OS_OK : OS_ERR);
  3903. ++}
  3904. ++
  3905. ++// Hint to the underlying OS that a task switch would not be good.
  3906. ++// Void return because it's a hint and can fail.
  3907. ++void os::hint_no_preempt() {}
  3908. ++
  3909. ++////////////////////////////////////////////////////////////////////////////////
  3910. ++// suspend/resume support
  3911. ++
  3912. ++// the low-level signal-based suspend/resume support is a remnant from the
  3913. ++// old VM-suspension that used to be for java-suspension, safepoints etc,
  3914. ++// within hotspot. Now there is a single use-case for this:
  3915. ++// - calling get_thread_pc() on the VMThread by the flat-profiler task
  3916. ++// that runs in the watcher thread.
  3917. ++// The remaining code is greatly simplified from the more general suspension
  3918. ++// code that used to be used.
  3919. ++//
  3920. ++// The protocol is quite simple:
  3921. ++// - suspend:
  3922. ++// - sends a signal to the target thread
  3923. ++// - polls the suspend state of the osthread using a yield loop
  3924. ++// - target thread signal handler (SR_handler) sets suspend state
  3925. ++// and blocks in sigsuspend until continued
  3926. ++// - resume:
  3927. ++// - sets target osthread state to continue
  3928. ++// - sends signal to end the sigsuspend loop in the SR_handler
  3929. ++//
  3930. ++// Note that the SR_lock plays no role in this suspend/resume protocol.
  3931. ++//
  3932. ++
  3933. ++static void resume_clear_context(OSThread *osthread) {
  3934. ++ osthread->set_ucontext(NULL);
  3935. ++ osthread->set_siginfo(NULL);
  3936. ++}
  3937. ++
  3938. ++static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, ucontext_t* context) {
  3939. ++ osthread->set_ucontext(context);
  3940. ++ osthread->set_siginfo(siginfo);
  3941. ++}
  3942. ++
  3943. ++//
  3944. ++// Handler function invoked when a thread's execution is suspended or
  3945. ++// resumed. We have to be careful that only async-safe functions are
  3946. ++// called here (Note: most pthread functions are not async safe and
  3947. ++// should be avoided.)
  3948. ++//
  3949. ++// Note: sigwait() is a more natural fit than sigsuspend() from an
  3950. ++// interface point of view, but sigwait() prevents the signal hander
  3951. ++// from being run. libpthread would get very confused by not having
  3952. ++// its signal handlers run and prevents sigwait()'s use with the
  3953. ++// mutex granting granting signal.
  3954. ++//
  3955. ++// Currently only ever called on the VMThread and JavaThreads (PC sampling)
  3956. ++//
  3957. ++static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context) {
  3958. ++ // Save and restore errno to avoid confusing native code with EINTR
  3959. ++ // after sigsuspend.
  3960. ++ int old_errno = errno;
  3961. ++
  3962. ++ Thread* thread = Thread::current();
  3963. ++ OSThread* osthread = thread->osthread();
  3964. ++ assert(thread->is_VM_thread() || thread->is_Java_thread(), "Must be VMThread or JavaThread");
  3965. ++
  3966. ++ os::SuspendResume::State current = osthread->sr.state();
  3967. ++ if (current == os::SuspendResume::SR_SUSPEND_REQUEST) {
  3968. ++ suspend_save_context(osthread, siginfo, context);
  3969. ++
  3970. ++ // attempt to switch the state, we assume we had a SUSPEND_REQUEST
  3971. ++ os::SuspendResume::State state = osthread->sr.suspended();
  3972. ++ if (state == os::SuspendResume::SR_SUSPENDED) {
  3973. ++ sigset_t suspend_set; // signals for sigsuspend()
  3974. ++
  3975. ++ // get current set of blocked signals and unblock resume signal
  3976. ++ pthread_sigmask(SIG_BLOCK, NULL, &suspend_set);
  3977. ++ sigdelset(&suspend_set, SR_signum);
  3978. ++
  3979. ++ sr_semaphore.signal();
  3980. ++ // wait here until we are resumed
  3981. ++ while (1) {
  3982. ++ sigsuspend(&suspend_set);
  3983. ++
  3984. ++ os::SuspendResume::State result = osthread->sr.running();
  3985. ++ if (result == os::SuspendResume::SR_RUNNING) {
  3986. ++ sr_semaphore.signal();
  3987. ++ break;
  3988. ++ }
  3989. ++ }
  3990. ++
  3991. ++ } else if (state == os::SuspendResume::SR_RUNNING) {
  3992. ++ // request was cancelled, continue
  3993. ++ } else {
  3994. ++ ShouldNotReachHere();
  3995. ++ }
  3996. ++
  3997. ++ resume_clear_context(osthread);
  3998. ++ } else if (current == os::SuspendResume::SR_RUNNING) {
  3999. ++ // request was cancelled, continue
  4000. ++ } else if (current == os::SuspendResume::SR_WAKEUP_REQUEST) {
  4001. ++ // ignore
  4002. ++ } else {
  4003. ++ // ignore
  4004. ++ }
  4005. ++
  4006. ++ errno = old_errno;
  4007. ++}
  4008. ++
  4009. ++
  4010. ++static int SR_initialize() {
  4011. ++ struct sigaction act;
  4012. ++ char *s;
  4013. ++ /* Get signal number to use for suspend/resume */
  4014. ++ if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
  4015. ++ int sig = ::strtol(s, 0, 10);
  4016. ++ if (sig > 0 || sig < _NSIG) {
  4017. ++ SR_signum = sig;
  4018. ++ }
  4019. ++ }
  4020. ++
  4021. ++ assert(SR_signum > SIGSEGV && SR_signum > SIGBUS,
  4022. ++ "SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769");
  4023. ++
  4024. ++ sigemptyset(&SR_sigset);
  4025. ++ sigaddset(&SR_sigset, SR_signum);
  4026. ++
  4027. ++ /* Set up signal handler for suspend/resume */
  4028. ++ act.sa_flags = SA_RESTART|SA_SIGINFO;
  4029. ++ act.sa_handler = (void (*)(int)) SR_handler;
  4030. ++
  4031. ++ // SR_signum is blocked by default.
  4032. ++ // 4528190 - We also need to block pthread restart signal (32 on all
  4033. ++ // supported Linux platforms). Note that LinuxThreads need to block
  4034. ++ // this signal for all threads to work properly. So we don't have
  4035. ++ // to use hard-coded signal number when setting up the mask.
  4036. ++ pthread_sigmask(SIG_BLOCK, NULL, &act.sa_mask);
  4037. ++
  4038. ++ if (sigaction(SR_signum, &act, 0) == -1) {
  4039. ++ return -1;
  4040. ++ }
  4041. ++
  4042. ++ // Save signal flag
  4043. ++ os::Linux::set_our_sigflags(SR_signum, act.sa_flags);
  4044. ++ return 0;
  4045. ++}
  4046. ++
  4047. ++static int SR_finalize() {
  4048. ++ return 0;
  4049. ++}
  4050. ++
  4051. ++static int sr_notify(OSThread* osthread) {
  4052. ++ int status = pthread_kill(osthread->pthread_id(), SR_signum);
  4053. ++ assert_status(status == 0, status, "pthread_kill");
  4054. ++ return status;
  4055. ++}
  4056. ++
  4057. ++// "Randomly" selected value for how long we want to spin
  4058. ++// before bailing out on suspending a thread, also how often
  4059. ++// we send a signal to a thread we want to resume
  4060. ++static const int RANDOMLY_LARGE_INTEGER = 1000000;
  4061. ++static const int RANDOMLY_LARGE_INTEGER2 = 100;
  4062. ++
  4063. ++// returns true on success and false on error - really an error is fatal
  4064. ++// but this seems the normal response to library errors
  4065. ++static bool do_suspend(OSThread* osthread) {
  4066. ++ assert(osthread->sr.is_running(), "thread should be running");
  4067. ++ assert(!sr_semaphore.trywait(), "semaphore has invalid state");
  4068. ++
  4069. ++ // mark as suspended and send signal
  4070. ++ if (osthread->sr.request_suspend() != os::SuspendResume::SR_SUSPEND_REQUEST) {
  4071. ++ // failed to switch, state wasn't running?
  4072. ++ ShouldNotReachHere();
  4073. ++ return false;
  4074. ++ }
  4075. ++
  4076. ++ if (sr_notify(osthread) != 0) {
  4077. ++ ShouldNotReachHere();
  4078. ++ }
  4079. ++
  4080. ++ // managed to send the signal and switch to SUSPEND_REQUEST, now wait for SUSPENDED
  4081. ++ while (true) {
  4082. ++ if (sr_semaphore.timedwait(0, 2 * NANOSECS_PER_MILLISEC)) {
  4083. ++ break;
  4084. ++ } else {
  4085. ++ // timeout
  4086. ++ os::SuspendResume::State cancelled = osthread->sr.cancel_suspend();
  4087. ++ if (cancelled == os::SuspendResume::SR_RUNNING) {
  4088. ++ return false;
  4089. ++ } else if (cancelled == os::SuspendResume::SR_SUSPENDED) {
  4090. ++ // make sure that we consume the signal on the semaphore as well
  4091. ++ sr_semaphore.wait();
  4092. ++ break;
  4093. ++ } else {
  4094. ++ ShouldNotReachHere();
  4095. ++ return false;
  4096. ++ }
  4097. ++ }
  4098. ++ }
  4099. ++
  4100. ++ guarantee(osthread->sr.is_suspended(), "Must be suspended");
  4101. ++ return true;
  4102. ++}
  4103. ++
  4104. ++static void do_resume(OSThread* osthread) {
  4105. ++ assert(osthread->sr.is_suspended(), "thread should be suspended");
  4106. ++ assert(!sr_semaphore.trywait(), "invalid semaphore state");
  4107. ++
  4108. ++ if (osthread->sr.request_wakeup() != os::SuspendResume::SR_WAKEUP_REQUEST) {
  4109. ++ // failed to switch to WAKEUP_REQUEST
  4110. ++ ShouldNotReachHere();
  4111. ++ return;
  4112. ++ }
  4113. ++
  4114. ++ while (true) {
  4115. ++ if (sr_notify(osthread) == 0) {
  4116. ++ if (sr_semaphore.timedwait(0, 2 * NANOSECS_PER_MILLISEC)) {
  4117. ++ if (osthread->sr.is_running()) {
  4118. ++ return;
  4119. ++ }
  4120. ++ }
  4121. ++ } else {
  4122. ++ ShouldNotReachHere();
  4123. ++ }
  4124. ++ }
  4125. ++
  4126. ++ guarantee(osthread->sr.is_running(), "Must be running!");
  4127. ++}
  4128. ++
  4129. ++////////////////////////////////////////////////////////////////////////////////
  4130. ++// interrupt support
  4131. ++
  4132. ++void os::interrupt(Thread* thread) {
  4133. ++ assert(Thread::current() == thread || Threads_lock->owned_by_self(),
  4134. ++ "possibility of dangling Thread pointer");
  4135. ++
  4136. ++ OSThread* osthread = thread->osthread();
  4137. ++
  4138. ++ if (!osthread->interrupted()) {
  4139. ++ osthread->set_interrupted(true);
  4140. ++ // More than one thread can get here with the same value of osthread,
  4141. ++ // resulting in multiple notifications. We do, however, want the store
  4142. ++ // to interrupted() to be visible to other threads before we execute unpark().
  4143. ++ OrderAccess::fence();
  4144. ++ ParkEvent * const slp = thread->_SleepEvent ;
  4145. ++ if (slp != NULL) slp->unpark() ;
  4146. ++ }
  4147. ++
  4148. ++ // For JSR166. Unpark even if interrupt status already was set
  4149. ++ if (thread->is_Java_thread())
  4150. ++ ((JavaThread*)thread)->parker()->unpark();
  4151. ++
  4152. ++ ParkEvent * ev = thread->_ParkEvent ;
  4153. ++ if (ev != NULL) ev->unpark() ;
  4154. ++
  4155. ++}
  4156. ++
  4157. ++bool os::is_interrupted(Thread* thread, bool clear_interrupted) {
  4158. ++ assert(Thread::current() == thread || Threads_lock->owned_by_self(),
  4159. ++ "possibility of dangling Thread pointer");
  4160. ++
  4161. ++ OSThread* osthread = thread->osthread();
  4162. ++
  4163. ++ bool interrupted = osthread->interrupted();
  4164. ++
  4165. ++ if (interrupted && clear_interrupted) {
  4166. ++ osthread->set_interrupted(false);
  4167. ++ // consider thread->_SleepEvent->reset() ... optional optimization
  4168. ++ }
  4169. ++
  4170. ++ return interrupted;
  4171. ++}
  4172. ++
  4173. ++///////////////////////////////////////////////////////////////////////////////////
  4174. ++// signal handling (except suspend/resume)
  4175. ++
  4176. ++// This routine may be used by user applications as a "hook" to catch signals.
  4177. ++// The user-defined signal handler must pass unrecognized signals to this
  4178. ++// routine, and if it returns true (non-zero), then the signal handler must
  4179. ++// return immediately. If the flag "abort_if_unrecognized" is true, then this
  4180. ++// routine will never retun false (zero), but instead will execute a VM panic
  4181. ++// routine kill the process.
  4182. ++//
  4183. ++// If this routine returns false, it is OK to call it again. This allows
  4184. ++// the user-defined signal handler to perform checks either before or after
  4185. ++// the VM performs its own checks. Naturally, the user code would be making
  4186. ++// a serious error if it tried to handle an exception (such as a null check
  4187. ++// or breakpoint) that the VM was generating for its own correct operation.
  4188. ++//
  4189. ++// This routine may recognize any of the following kinds of signals:
  4190. ++// SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1.
  4191. ++// It should be consulted by handlers for any of those signals.
  4192. ++//
  4193. ++// The caller of this routine must pass in the three arguments supplied
  4194. ++// to the function referred to in the "sa_sigaction" (not the "sa_handler")
  4195. ++// field of the structure passed to sigaction(). This routine assumes that
  4196. ++// the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART.
  4197. ++//
  4198. ++// Note that the VM will print warnings if it detects conflicting signal
  4199. ++// handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers".
  4200. ++//
  4201. ++extern "C" JNIEXPORT int
  4202. ++JVM_handle_linux_signal(int signo, siginfo_t* siginfo,
  4203. ++ void* ucontext, int abort_if_unrecognized);
  4204. ++
  4205. ++void signalHandler(int sig, siginfo_t* info, void* uc) {
  4206. ++ assert(info != NULL && uc != NULL, "it must be old kernel");
  4207. ++ JVM_handle_linux_signal(sig, info, uc, true);
  4208. ++}
  4209. ++
  4210. ++
  4211. ++// This boolean allows users to forward their own non-matching signals
  4212. ++// to JVM_handle_linux_signal, harmlessly.
  4213. ++bool os::Linux::signal_handlers_are_installed = false;
  4214. ++
  4215. ++// For signal-chaining
  4216. ++struct sigaction os::Linux::sigact[MAXSIGNUM];
  4217. ++unsigned int os::Linux::sigs = 0;
  4218. ++bool os::Linux::libjsig_is_loaded = false;
  4219. ++typedef struct sigaction *(*get_signal_t)(int);
  4220. ++get_signal_t os::Linux::get_signal_action = NULL;
  4221. ++
  4222. ++struct sigaction* os::Linux::get_chained_signal_action(int sig) {
  4223. ++ struct sigaction *actp = NULL;
  4224. ++
  4225. ++ if (libjsig_is_loaded) {
  4226. ++ // Retrieve the old signal handler from libjsig
  4227. ++ actp = (*get_signal_action)(sig);
  4228. ++ }
  4229. ++ if (actp == NULL) {
  4230. ++ // Retrieve the preinstalled signal handler from jvm
  4231. ++ actp = get_preinstalled_handler(sig);
  4232. ++ }
  4233. ++
  4234. ++ return actp;
  4235. ++}
  4236. ++
  4237. ++static bool call_chained_handler(struct sigaction *actp, int sig,
  4238. ++ siginfo_t *siginfo, void *context) {
  4239. ++ // Call the old signal handler
  4240. ++ if (actp->sa_handler == SIG_DFL) {
  4241. ++ // It's more reasonable to let jvm treat it as an unexpected exception
  4242. ++ // instead of taking the default action.
  4243. ++ return false;
  4244. ++ } else if (actp->sa_handler != SIG_IGN) {
  4245. ++ if ((actp->sa_flags & SA_NODEFER) == 0) {
  4246. ++ // automaticlly block the signal
  4247. ++ sigaddset(&(actp->sa_mask), sig);
  4248. ++ }
  4249. ++
  4250. ++ sa_handler_t hand;
  4251. ++ sa_sigaction_t sa;
  4252. ++ bool siginfo_flag_set = (actp->sa_flags & SA_SIGINFO) != 0;
  4253. ++ // retrieve the chained handler
  4254. ++ if (siginfo_flag_set) {
  4255. ++ sa = actp->sa_sigaction;
  4256. ++ } else {
  4257. ++ hand = actp->sa_handler;
  4258. ++ }
  4259. ++
  4260. ++ if ((actp->sa_flags & SA_RESETHAND) != 0) {
  4261. ++ actp->sa_handler = SIG_DFL;
  4262. ++ }
  4263. ++
  4264. ++ // try to honor the signal mask
  4265. ++ sigset_t oset;
  4266. ++ pthread_sigmask(SIG_SETMASK, &(actp->sa_mask), &oset);
  4267. ++
  4268. ++ // call into the chained handler
  4269. ++ if (siginfo_flag_set) {
  4270. ++ (*sa)(sig, siginfo, context);
  4271. ++ } else {
  4272. ++ (*hand)(sig);
  4273. ++ }
  4274. ++
  4275. ++ // restore the signal mask
  4276. ++ pthread_sigmask(SIG_SETMASK, &oset, 0);
  4277. ++ }
  4278. ++ // Tell jvm's signal handler the signal is taken care of.
  4279. ++ return true;
  4280. ++}
  4281. ++
  4282. ++bool os::Linux::chained_handler(int sig, siginfo_t* siginfo, void* context) {
  4283. ++ bool chained = false;
  4284. ++ // signal-chaining
  4285. ++ if (UseSignalChaining) {
  4286. ++ struct sigaction *actp = get_chained_signal_action(sig);
  4287. ++ if (actp != NULL) {
  4288. ++ chained = call_chained_handler(actp, sig, siginfo, context);
  4289. ++ }
  4290. ++ }
  4291. ++ return chained;
  4292. ++}
  4293. ++
  4294. ++struct sigaction* os::Linux::get_preinstalled_handler(int sig) {
  4295. ++ if ((( (unsigned int)1 << sig ) & sigs) != 0) {
  4296. ++ return &sigact[sig];
  4297. ++ }
  4298. ++ return NULL;
  4299. ++}
  4300. ++
  4301. ++void os::Linux::save_preinstalled_handler(int sig, struct sigaction& oldAct) {
  4302. ++ assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
  4303. ++ sigact[sig] = oldAct;
  4304. ++ sigs |= (unsigned int)1 << sig;
  4305. ++}
  4306. ++
  4307. ++// for diagnostic
  4308. ++int os::Linux::sigflags[MAXSIGNUM];
  4309. ++
  4310. ++int os::Linux::get_our_sigflags(int sig) {
  4311. ++ assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
  4312. ++ return sigflags[sig];
  4313. ++}
  4314. ++
  4315. ++void os::Linux::set_our_sigflags(int sig, int flags) {
  4316. ++ assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
  4317. ++ sigflags[sig] = flags;
  4318. ++}
  4319. ++
  4320. ++void os::Linux::set_signal_handler(int sig, bool set_installed) {
  4321. ++ // Check for overwrite.
  4322. ++ struct sigaction oldAct;
  4323. ++ sigaction(sig, (struct sigaction*)NULL, &oldAct);
  4324. ++
  4325. ++ void* oldhand = oldAct.sa_sigaction
  4326. ++ ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction)
  4327. ++ : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
  4328. ++ if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) &&
  4329. ++ oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) &&
  4330. ++ oldhand != CAST_FROM_FN_PTR(void*, (sa_sigaction_t)signalHandler)) {
  4331. ++ if (AllowUserSignalHandlers || !set_installed) {
  4332. ++ // Do not overwrite; user takes responsibility to forward to us.
  4333. ++ return;
  4334. ++ } else if (UseSignalChaining) {
  4335. ++ // save the old handler in jvm
  4336. ++ save_preinstalled_handler(sig, oldAct);
  4337. ++ // libjsig also interposes the sigaction() call below and saves the
  4338. ++ // old sigaction on it own.
  4339. ++ } else {
  4340. ++ fatal(err_msg("Encountered unexpected pre-existing sigaction handler "
  4341. ++ "%#lx for signal %d.", (long)oldhand, sig));
  4342. ++ }
  4343. ++ }
  4344. ++
  4345. ++ struct sigaction sigAct;
  4346. ++ sigfillset(&(sigAct.sa_mask));
  4347. ++ sigAct.sa_handler = SIG_DFL;
  4348. ++ if (!set_installed) {
  4349. ++ sigAct.sa_flags = SA_SIGINFO|SA_RESTART;
  4350. ++ } else {
  4351. ++ sigAct.sa_sigaction = signalHandler;
  4352. ++ sigAct.sa_flags = SA_SIGINFO|SA_RESTART;
  4353. ++ }
  4354. ++ // Save flags, which are set by ours
  4355. ++ assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range");
  4356. ++ sigflags[sig] = sigAct.sa_flags;
  4357. ++
  4358. ++ int ret = sigaction(sig, &sigAct, &oldAct);
  4359. ++ assert(ret == 0, "check");
  4360. ++
  4361. ++ void* oldhand2 = oldAct.sa_sigaction
  4362. ++ ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction)
  4363. ++ : CAST_FROM_FN_PTR(void*, oldAct.sa_handler);
  4364. ++ assert(oldhand2 == oldhand, "no concurrent signal handler installation");
  4365. ++}
  4366. ++
  4367. ++// install signal handlers for signals that HotSpot needs to
  4368. ++// handle in order to support Java-level exception handling.
  4369. ++
  4370. ++void os::Linux::install_signal_handlers() {
  4371. ++ if (!signal_handlers_are_installed) {
  4372. ++ signal_handlers_are_installed = true;
  4373. ++
  4374. ++ // signal-chaining
  4375. ++ typedef void (*signal_setting_t)();
  4376. ++ signal_setting_t begin_signal_setting = NULL;
  4377. ++ signal_setting_t end_signal_setting = NULL;
  4378. ++ begin_signal_setting = CAST_TO_FN_PTR(signal_setting_t,
  4379. ++ dlsym(RTLD_DEFAULT, "JVM_begin_signal_setting"));
  4380. ++ if (begin_signal_setting != NULL) {
  4381. ++ end_signal_setting = CAST_TO_FN_PTR(signal_setting_t,
  4382. ++ dlsym(RTLD_DEFAULT, "JVM_end_signal_setting"));
  4383. ++ get_signal_action = CAST_TO_FN_PTR(get_signal_t,
  4384. ++ dlsym(RTLD_DEFAULT, "JVM_get_signal_action"));
  4385. ++ libjsig_is_loaded = true;
  4386. ++ assert(UseSignalChaining, "should enable signal-chaining");
  4387. ++ }
  4388. ++ if (libjsig_is_loaded) {
  4389. ++ // Tell libjsig jvm is setting signal handlers
  4390. ++ (*begin_signal_setting)();
  4391. ++ }
  4392. ++
  4393. ++ set_signal_handler(SIGSEGV, true);
  4394. ++ set_signal_handler(SIGPIPE, true);
  4395. ++ set_signal_handler(SIGBUS, true);
  4396. ++ set_signal_handler(SIGILL, true);
  4397. ++ set_signal_handler(SIGFPE, true);
  4398. ++ set_signal_handler(SIGXFSZ, true);
  4399. ++
  4400. ++ if (libjsig_is_loaded) {
  4401. ++ // Tell libjsig jvm finishes setting signal handlers
  4402. ++ (*end_signal_setting)();
  4403. ++ }
  4404. ++
  4405. ++ // We don't activate signal checker if libjsig is in place, we trust ourselves
  4406. ++ // and if UserSignalHandler is installed all bets are off.
  4407. ++ // Log that signal checking is off only if -verbose:jni is specified.
  4408. ++ if (CheckJNICalls) {
  4409. ++ if (libjsig_is_loaded) {
  4410. ++ if (PrintJNIResolving) {
  4411. ++ tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
  4412. ++ }
  4413. ++ check_signals = false;
  4414. ++ }
  4415. ++ if (AllowUserSignalHandlers) {
  4416. ++ if (PrintJNIResolving) {
  4417. ++ tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
  4418. ++ }
  4419. ++ check_signals = false;
  4420. ++ }
  4421. ++ }
  4422. ++ }
  4423. ++}
  4424. ++
  4425. ++// This is the fastest way to get thread cpu time on Linux.
  4426. ++// Returns cpu time (user+sys) for any thread, not only for current.
  4427. ++// POSIX compliant clocks are implemented in the kernels 2.6.16+.
  4428. ++// It might work on 2.6.10+ with a special kernel/glibc patch.
  4429. ++// For reference, please, see IEEE Std 1003.1-2004:
  4430. ++// http://www.unix.org/single_unix_specification
  4431. ++
  4432. ++jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) {
  4433. ++ struct timespec tp;
  4434. ++ int rc = os::Linux::clock_gettime(clockid, &tp);
  4435. ++ assert(rc == 0, "clock_gettime is expected to return 0 code");
  4436. ++
  4437. ++ return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec;
  4438. ++}
  4439. ++
  4440. ++/////
  4441. ++// glibc on Linux platform uses non-documented flag
  4442. ++// to indicate, that some special sort of signal
  4443. ++// trampoline is used.
  4444. ++// We will never set this flag, and we should
  4445. ++// ignore this flag in our diagnostic
  4446. ++#ifdef SIGNIFICANT_SIGNAL_MASK
  4447. ++#undef SIGNIFICANT_SIGNAL_MASK
  4448. ++#endif
  4449. ++#define SIGNIFICANT_SIGNAL_MASK (~0x04000000)
  4450. ++
  4451. ++static const char* get_signal_handler_name(address handler,
  4452. ++ char* buf, int buflen) {
  4453. ++ int offset;
  4454. ++ bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset);
  4455. ++ if (found) {
  4456. ++ // skip directory names
  4457. ++ const char *p1, *p2;
  4458. ++ p1 = buf;
  4459. ++ size_t len = strlen(os::file_separator());
  4460. ++ while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
  4461. ++ jio_snprintf(buf, buflen, "%s+0x%x", p1, offset);
  4462. ++ } else {
  4463. ++ jio_snprintf(buf, buflen, PTR_FORMAT, handler);
  4464. ++ }
  4465. ++ return buf;
  4466. ++}
  4467. ++
  4468. ++static void print_signal_handler(outputStream* st, int sig,
  4469. ++ char* buf, size_t buflen) {
  4470. ++ struct sigaction sa;
  4471. ++
  4472. ++ sigaction(sig, NULL, &sa);
  4473. ++
  4474. ++ // See comment for SIGNIFICANT_SIGNAL_MASK define
  4475. ++ sa.sa_flags &= SIGNIFICANT_SIGNAL_MASK;
  4476. ++
  4477. ++ st->print("%s: ", os::exception_name(sig, buf, buflen));
  4478. ++
  4479. ++ address handler = (sa.sa_flags & SA_SIGINFO)
  4480. ++ ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
  4481. ++ : CAST_FROM_FN_PTR(address, sa.sa_handler);
  4482. ++
  4483. ++ if (handler == CAST_FROM_FN_PTR(address, SIG_DFL)) {
  4484. ++ st->print("SIG_DFL");
  4485. ++ } else if (handler == CAST_FROM_FN_PTR(address, SIG_IGN)) {
  4486. ++ st->print("SIG_IGN");
  4487. ++ } else {
  4488. ++ st->print("[%s]", get_signal_handler_name(handler, buf, buflen));
  4489. ++ }
  4490. ++
  4491. ++ st->print(", sa_mask[0]=" PTR32_FORMAT, *(uint32_t*)&sa.sa_mask);
  4492. ++
  4493. ++ address rh = VMError::get_resetted_sighandler(sig);
  4494. ++ // May be, handler was resetted by VMError?
  4495. ++ if(rh != NULL) {
  4496. ++ handler = rh;
  4497. ++ sa.sa_flags = VMError::get_resetted_sigflags(sig) & SIGNIFICANT_SIGNAL_MASK;
  4498. ++ }
  4499. ++
  4500. ++ st->print(", sa_flags=" PTR32_FORMAT, sa.sa_flags);
  4501. ++
  4502. ++ // Check: is it our handler?
  4503. ++ if(handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler) ||
  4504. ++ handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) {
  4505. ++ // It is our signal handler
  4506. ++ // check for flags, reset system-used one!
  4507. ++ if((int)sa.sa_flags != os::Linux::get_our_sigflags(sig)) {
  4508. ++ st->print(
  4509. ++ ", flags was changed from " PTR32_FORMAT ", consider using jsig library",
  4510. ++ os::Linux::get_our_sigflags(sig));
  4511. ++ }
  4512. ++ }
  4513. ++ st->cr();
  4514. ++}
  4515. ++
  4516. ++
  4517. ++#define DO_SIGNAL_CHECK(sig) \
  4518. ++ if (!sigismember(&check_signal_done, sig)) \
  4519. ++ os::Linux::check_signal_handler(sig)
  4520. ++
  4521. ++// This method is a periodic task to check for misbehaving JNI applications
  4522. ++// under CheckJNI, we can add any periodic checks here
  4523. ++
  4524. ++void os::run_periodic_checks() {
  4525. ++
  4526. ++ if (check_signals == false) return;
  4527. ++
  4528. ++ // SEGV and BUS if overridden could potentially prevent
  4529. ++ // generation of hs*.log in the event of a crash, debugging
  4530. ++ // such a case can be very challenging, so we absolutely
  4531. ++ // check the following for a good measure:
  4532. ++ DO_SIGNAL_CHECK(SIGSEGV);
  4533. ++ DO_SIGNAL_CHECK(SIGILL);
  4534. ++ DO_SIGNAL_CHECK(SIGFPE);
  4535. ++ DO_SIGNAL_CHECK(SIGBUS);
  4536. ++ DO_SIGNAL_CHECK(SIGPIPE);
  4537. ++ DO_SIGNAL_CHECK(SIGXFSZ);
  4538. ++
  4539. ++
  4540. ++ // ReduceSignalUsage allows the user to override these handlers
  4541. ++ // see comments at the very top and jvm_solaris.h
  4542. ++ if (!ReduceSignalUsage) {
  4543. ++ DO_SIGNAL_CHECK(SHUTDOWN1_SIGNAL);
  4544. ++ DO_SIGNAL_CHECK(SHUTDOWN2_SIGNAL);
  4545. ++ DO_SIGNAL_CHECK(SHUTDOWN3_SIGNAL);
  4546. ++ DO_SIGNAL_CHECK(BREAK_SIGNAL);
  4547. ++ }
  4548. ++
  4549. ++ DO_SIGNAL_CHECK(SR_signum);
  4550. ++ DO_SIGNAL_CHECK(INTERRUPT_SIGNAL);
  4551. ++}
  4552. ++
  4553. ++typedef int (*os_sigaction_t)(int, const struct sigaction *, struct sigaction *);
  4554. ++
  4555. ++static os_sigaction_t os_sigaction = NULL;
  4556. ++
  4557. ++void os::Linux::check_signal_handler(int sig) {
  4558. ++ char buf[O_BUFLEN];
  4559. ++ address jvmHandler = NULL;
  4560. ++
  4561. ++
  4562. ++ struct sigaction act;
  4563. ++ if (os_sigaction == NULL) {
  4564. ++ // only trust the default sigaction, in case it has been interposed
  4565. ++ os_sigaction = (os_sigaction_t)dlsym(RTLD_DEFAULT, "sigaction");
  4566. ++ if (os_sigaction == NULL) return;
  4567. ++ }
  4568. ++
  4569. ++ os_sigaction(sig, (struct sigaction*)NULL, &act);
  4570. ++
  4571. ++
  4572. ++ act.sa_flags &= SIGNIFICANT_SIGNAL_MASK;
  4573. ++
  4574. ++ address thisHandler = (act.sa_flags & SA_SIGINFO)
  4575. ++ ? CAST_FROM_FN_PTR(address, act.sa_sigaction)
  4576. ++ : CAST_FROM_FN_PTR(address, act.sa_handler) ;
  4577. ++
  4578. ++
  4579. ++ switch(sig) {
  4580. ++ case SIGSEGV:
  4581. ++ case SIGBUS:
  4582. ++ case SIGFPE:
  4583. ++ case SIGPIPE:
  4584. ++ case SIGILL:
  4585. ++ case SIGXFSZ:
  4586. ++ jvmHandler = CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler);
  4587. ++ break;
  4588. ++
  4589. ++ case SHUTDOWN1_SIGNAL:
  4590. ++ case SHUTDOWN2_SIGNAL:
  4591. ++ case SHUTDOWN3_SIGNAL:
  4592. ++ case BREAK_SIGNAL:
  4593. ++ jvmHandler = (address)user_handler();
  4594. ++ break;
  4595. ++
  4596. ++ case INTERRUPT_SIGNAL:
  4597. ++ jvmHandler = CAST_FROM_FN_PTR(address, SIG_DFL);
  4598. ++ break;
  4599. ++
  4600. ++ default:
  4601. ++ if (sig == SR_signum) {
  4602. ++ jvmHandler = CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler);
  4603. ++ } else {
  4604. ++ return;
  4605. ++ }
  4606. ++ break;
  4607. ++ }
  4608. ++
  4609. ++ if (thisHandler != jvmHandler) {
  4610. ++ tty->print("Warning: %s handler ", exception_name(sig, buf, O_BUFLEN));
  4611. ++ tty->print("expected:%s", get_signal_handler_name(jvmHandler, buf, O_BUFLEN));
  4612. ++ tty->print_cr(" found:%s", get_signal_handler_name(thisHandler, buf, O_BUFLEN));
  4613. ++ // No need to check this sig any longer
  4614. ++ sigaddset(&check_signal_done, sig);
  4615. ++ } else if(os::Linux::get_our_sigflags(sig) != 0 && (int)act.sa_flags != os::Linux::get_our_sigflags(sig)) {
  4616. ++ tty->print("Warning: %s handler flags ", exception_name(sig, buf, O_BUFLEN));
  4617. ++ tty->print("expected:" PTR32_FORMAT, os::Linux::get_our_sigflags(sig));
  4618. ++ tty->print_cr(" found:" PTR32_FORMAT, act.sa_flags);
  4619. ++ // No need to check this sig any longer
  4620. ++ sigaddset(&check_signal_done, sig);
  4621. ++ }
  4622. ++
  4623. ++ // Dump all the signal
  4624. ++ if (sigismember(&check_signal_done, sig)) {
  4625. ++ print_signal_handlers(tty, buf, O_BUFLEN);
  4626. ++ }
  4627. ++}
  4628. ++
  4629. ++extern void report_error(char* file_name, int line_no, char* title, char* format, ...);
  4630. ++
  4631. ++extern bool signal_name(int signo, char* buf, size_t len);
  4632. ++
  4633. ++const char* os::exception_name(int exception_code, char* buf, size_t size) {
  4634. ++ if (0 < exception_code && exception_code <= SIGRTMAX) {
  4635. ++ // signal
  4636. ++ if (!signal_name(exception_code, buf, size)) {
  4637. ++ jio_snprintf(buf, size, "SIG%d", exception_code);
  4638. ++ }
  4639. ++ return buf;
  4640. ++ } else {
  4641. ++ return NULL;
  4642. ++ }
  4643. ++}
  4644. ++
  4645. ++// this is called _before_ the most of global arguments have been parsed
  4646. ++void os::init(void) {
  4647. ++ char dummy; /* used to get a guess on initial stack address */
  4648. ++// first_hrtime = gethrtime();
  4649. ++
  4650. ++ // With LinuxThreads the JavaMain thread pid (primordial thread)
  4651. ++ // is different than the pid of the java launcher thread.
  4652. ++ // So, on Linux, the launcher thread pid is passed to the VM
  4653. ++ // via the sun.java.launcher.pid property.
  4654. ++ // Use this property instead of getpid() if it was correctly passed.
  4655. ++ // See bug 6351349.
  4656. ++ pid_t java_launcher_pid = (pid_t) Arguments::sun_java_launcher_pid();
  4657. ++
  4658. ++ _initial_pid = (java_launcher_pid > 0) ? java_launcher_pid : getpid();
  4659. ++
  4660. ++ clock_tics_per_sec = sysconf(_SC_CLK_TCK);
  4661. ++
  4662. ++ init_random(1234567);
  4663. ++
  4664. ++ ThreadCritical::initialize();
  4665. ++
  4666. ++ Linux::set_page_size(sysconf(_SC_PAGESIZE));
  4667. ++ if (Linux::page_size() == -1) {
  4668. ++ fatal(err_msg("os_linux.cpp: os::init: sysconf failed (%s)",
  4669. ++ strerror(errno)));
  4670. ++ }
  4671. ++ init_page_sizes((size_t) Linux::page_size());
  4672. ++
  4673. ++ Linux::initialize_system_info();
  4674. ++
  4675. ++ // main_thread points to the aboriginal thread
  4676. ++ Linux::_main_thread = pthread_self();
  4677. ++
  4678. ++ Linux::clock_init();
  4679. ++ initial_time_count = os::elapsed_counter();
  4680. ++ pthread_mutex_init(&dl_mutex, NULL);
  4681. ++
  4682. ++ // If the pagesize of the VM is greater than 8K determine the appropriate
  4683. ++ // number of initial guard pages. The user can change this with the
  4684. ++ // command line arguments, if needed.
  4685. ++ if (vm_page_size() > (int)Linux::vm_default_page_size()) {
  4686. ++ StackYellowPages = 1;
  4687. ++ StackRedPages = 1;
  4688. ++ StackShadowPages = round_to((StackShadowPages*Linux::vm_default_page_size()), vm_page_size()) / vm_page_size();
  4689. ++ }
  4690. ++}
  4691. ++
  4692. ++// To install functions for atexit system call
  4693. ++extern "C" {
  4694. ++ static void perfMemory_exit_helper() {
  4695. ++ perfMemory_exit();
  4696. ++ }
  4697. ++}
  4698. ++
  4699. ++// this is called _after_ the global arguments have been parsed
  4700. ++jint os::init_2(void)
  4701. ++{
  4702. ++ Linux::fast_thread_clock_init();
  4703. ++
  4704. ++ // Allocate a single page and mark it as readable for safepoint polling
  4705. ++ address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  4706. ++ guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" );
  4707. ++
  4708. ++ os::set_polling_page( polling_page );
  4709. ++
  4710. ++#ifndef PRODUCT
  4711. ++ if(Verbose && PrintMiscellaneous)
  4712. ++ tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page);
  4713. ++#endif
  4714. ++
  4715. ++ if (!UseMembar) {
  4716. ++ address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  4717. ++ guarantee( mem_serialize_page != MAP_FAILED, "mmap Failed for memory serialize page");
  4718. ++ os::set_memory_serialize_page( mem_serialize_page );
  4719. ++
  4720. ++#ifndef PRODUCT
  4721. ++ if(Verbose && PrintMiscellaneous)
  4722. ++ tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page);
  4723. ++#endif
  4724. ++ }
  4725. ++
  4726. ++ os::large_page_init();
  4727. ++
  4728. ++ // initialize suspend/resume support - must do this before signal_sets_init()
  4729. ++ if (SR_initialize() != 0) {
  4730. ++ perror("SR_initialize failed");
  4731. ++ return JNI_ERR;
  4732. ++ }
  4733. ++
  4734. ++ Linux::signal_sets_init();
  4735. ++ Linux::install_signal_handlers();
  4736. ++
  4737. ++ // Check minimum allowable stack size for thread creation and to initialize
  4738. ++ // the java system classes, including StackOverflowError - depends on page
  4739. ++ // size. Add a page for compiler2 recursion in main thread.
  4740. ++ // Add in 2*BytesPerWord times page size to account for VM stack during
  4741. ++ // class initialization depending on 32 or 64 bit VM.
  4742. ++ os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
  4743. ++ (size_t)(StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() +
  4744. ++ (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size());
  4745. ++
  4746. ++ size_t threadStackSizeInBytes = ThreadStackSize * K;
  4747. ++ if (threadStackSizeInBytes != 0 &&
  4748. ++ threadStackSizeInBytes < os::Linux::min_stack_allowed) {
  4749. ++ tty->print_cr("\nThe stack size specified is too small, "
  4750. ++ "Specify at least %dk",
  4751. ++ os::Linux::min_stack_allowed/ K);
  4752. ++ return JNI_ERR;
  4753. ++ }
  4754. ++
  4755. ++ // Make the stack size a multiple of the page size so that
  4756. ++ // the yellow/red zones can be guarded.
  4757. ++ JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
  4758. ++ vm_page_size()));
  4759. ++
  4760. ++ Linux::capture_initial_stack(JavaThread::stack_size_at_create());
  4761. ++
  4762. ++ Linux::libpthread_init();
  4763. ++ if (PrintMiscellaneous && (Verbose || WizardMode)) {
  4764. ++ tty->print_cr("[HotSpot is running with %s, %s(%s)]\n",
  4765. ++ Linux::glibc_version(), Linux::libpthread_version(),
  4766. ++ Linux::is_floating_stack() ? "floating stack" : "fixed stack");
  4767. ++ }
  4768. ++
  4769. ++ if (UseNUMA) {
  4770. ++ if (!Linux::libnuma_init()) {
  4771. ++ UseNUMA = false;
  4772. ++ } else {
  4773. ++ if ((Linux::numa_max_node() < 1)) {
  4774. ++ // There's only one node(they start from 0), disable NUMA.
  4775. ++ UseNUMA = false;
  4776. ++ }
  4777. ++ }
  4778. ++ // With SHM large pages we cannot uncommit a page, so there's not way
  4779. ++ // we can make the adaptive lgrp chunk resizing work. If the user specified
  4780. ++ // both UseNUMA and UseLargePages (or UseSHM) on the command line - warn and
  4781. ++ // disable adaptive resizing.
  4782. ++ if (UseNUMA && UseLargePages && UseSHM) {
  4783. ++ if (!FLAG_IS_DEFAULT(UseNUMA)) {
  4784. ++ if (FLAG_IS_DEFAULT(UseLargePages) && FLAG_IS_DEFAULT(UseSHM)) {
  4785. ++ UseLargePages = false;
  4786. ++ } else {
  4787. ++ warning("UseNUMA is not fully compatible with SHM large pages, disabling adaptive resizing");
  4788. ++ UseAdaptiveSizePolicy = false;
  4789. ++ UseAdaptiveNUMAChunkSizing = false;
  4790. ++ }
  4791. ++ } else {
  4792. ++ UseNUMA = false;
  4793. ++ }
  4794. ++ }
  4795. ++ if (!UseNUMA && ForceNUMA) {
  4796. ++ UseNUMA = true;
  4797. ++ }
  4798. ++ }
  4799. ++
  4800. ++ if (MaxFDLimit) {
  4801. ++ // set the number of file descriptors to max. print out error
  4802. ++ // if getrlimit/setrlimit fails but continue regardless.
  4803. ++ struct rlimit nbr_files;
  4804. ++ int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
  4805. ++ if (status != 0) {
  4806. ++ if (PrintMiscellaneous && (Verbose || WizardMode))
  4807. ++ perror("os::init_2 getrlimit failed");
  4808. ++ } else {
  4809. ++ nbr_files.rlim_cur = nbr_files.rlim_max;
  4810. ++ status = setrlimit(RLIMIT_NOFILE, &nbr_files);
  4811. ++ if (status != 0) {
  4812. ++ if (PrintMiscellaneous && (Verbose || WizardMode))
  4813. ++ perror("os::init_2 setrlimit failed");
  4814. ++ }
  4815. ++ }
  4816. ++ }
  4817. ++
  4818. ++ // Initialize lock used to serialize thread creation (see os::create_thread)
  4819. ++ Linux::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false));
  4820. ++
  4821. ++ // at-exit methods are called in the reverse order of their registration.
  4822. ++ // atexit functions are called on return from main or as a result of a
  4823. ++ // call to exit(3C). There can be only 32 of these functions registered
  4824. ++ // and atexit() does not set errno.
  4825. ++
  4826. ++ if (PerfAllowAtExitRegistration) {
  4827. ++ // only register atexit functions if PerfAllowAtExitRegistration is set.
  4828. ++ // atexit functions can be delayed until process exit time, which
  4829. ++ // can be problematic for embedded VM situations. Embedded VMs should
  4830. ++ // call DestroyJavaVM() to assure that VM resources are released.
  4831. ++
  4832. ++ // note: perfMemory_exit_helper atexit function may be removed in
  4833. ++ // the future if the appropriate cleanup code can be added to the
  4834. ++ // VM_Exit VMOperation's doit method.
  4835. ++ if (atexit(perfMemory_exit_helper) != 0) {
  4836. ++ warning("os::init2 atexit(perfMemory_exit_helper) failed");
  4837. ++ }
  4838. ++ }
  4839. ++
  4840. ++ // initialize thread priority policy
  4841. ++ prio_init();
  4842. ++
  4843. ++ return JNI_OK;
  4844. ++}
  4845. ++
  4846. ++// this is called at the end of vm_initialization
  4847. ++void os::init_3(void)
  4848. ++{
  4849. ++#ifdef JAVASE_EMBEDDED
  4850. ++ // Start the MemNotifyThread
  4851. ++ if (LowMemoryProtection) {
  4852. ++ MemNotifyThread::start();
  4853. ++ }
  4854. ++ return;
  4855. ++#endif
  4856. ++}
  4857. ++
  4858. ++// Mark the polling page as unreadable
  4859. ++void os::make_polling_page_unreadable(void) {
  4860. ++ if( !guard_memory((char*)_polling_page, Linux::page_size()) )
  4861. ++ fatal("Could not disable polling page");
  4862. ++};
  4863. ++
  4864. ++// Mark the polling page as readable
  4865. ++void os::make_polling_page_readable(void) {
  4866. ++ if( !linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) {
  4867. ++ fatal("Could not enable polling page");
  4868. ++ }
  4869. ++};
  4870. ++
  4871. ++int os::active_processor_count() {
  4872. ++ // Linux doesn't yet have a (official) notion of processor sets,
  4873. ++ // so just return the number of online processors.
  4874. ++ int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
  4875. ++ assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
  4876. ++ return online_cpus;
  4877. ++}
  4878. ++
  4879. ++void os::set_native_thread_name(const char *name) {
  4880. ++ // Not yet implemented.
  4881. ++ return;
  4882. ++}
  4883. ++
  4884. ++bool os::distribute_processes(uint length, uint* distribution) {
  4885. ++ // Not yet implemented.
  4886. ++ return false;
  4887. ++}
  4888. ++
  4889. ++bool os::bind_to_processor(uint processor_id) {
  4890. ++ // Not yet implemented.
  4891. ++ return false;
  4892. ++}
  4893. ++
  4894. ++///
  4895. ++
  4896. ++void os::SuspendedThreadTask::internal_do_task() {
  4897. ++ if (do_suspend(_thread->osthread())) {
  4898. ++ SuspendedThreadTaskContext context(_thread, _thread->osthread()->ucontext());
  4899. ++ do_task(context);
  4900. ++ do_resume(_thread->osthread());
  4901. ++ }
  4902. ++}
  4903. ++
  4904. ++class PcFetcher : public os::SuspendedThreadTask {
  4905. ++public:
  4906. ++ PcFetcher(Thread* thread) : os::SuspendedThreadTask(thread) {}
  4907. ++ ExtendedPC result();
  4908. ++protected:
  4909. ++ void do_task(const os::SuspendedThreadTaskContext& context);
  4910. ++private:
  4911. ++ ExtendedPC _epc;
  4912. ++};
  4913. ++
  4914. ++ExtendedPC PcFetcher::result() {
  4915. ++ guarantee(is_done(), "task is not done yet.");
  4916. ++ return _epc;
  4917. ++}
  4918. ++
  4919. ++void PcFetcher::do_task(const os::SuspendedThreadTaskContext& context) {
  4920. ++ Thread* thread = context.thread();
  4921. ++ OSThread* osthread = thread->osthread();
  4922. ++ if (osthread->ucontext() != NULL) {
  4923. ++ _epc = os::Linux::ucontext_get_pc((ucontext_t *) context.ucontext());
  4924. ++ } else {
  4925. ++ // NULL context is unexpected, double-check this is the VMThread
  4926. ++ guarantee(thread->is_VM_thread(), "can only be called for VMThread");
  4927. ++ }
  4928. ++}
  4929. ++
  4930. ++// Suspends the target using the signal mechanism and then grabs the PC before
  4931. ++// resuming the target. Used by the flat-profiler only
  4932. ++ExtendedPC os::get_thread_pc(Thread* thread) {
  4933. ++ // Make sure that it is called by the watcher for the VMThread
  4934. ++ assert(Thread::current()->is_Watcher_thread(), "Must be watcher");
  4935. ++ assert(thread->is_VM_thread(), "Can only be called for VMThread");
  4936. ++
  4937. ++ PcFetcher fetcher(thread);
  4938. ++ fetcher.run();
  4939. ++ return fetcher.result();
  4940. ++}
  4941. ++
  4942. ++int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime)
  4943. ++{
  4944. ++ if (is_NPTL()) {
  4945. ++ return pthread_cond_timedwait(_cond, _mutex, _abstime);
  4946. ++ } else {
  4947. ++#ifndef IA64
  4948. ++ // 6292965: LinuxThreads pthread_cond_timedwait() resets FPU control
  4949. ++ // word back to default 64bit precision if condvar is signaled. Java
  4950. ++ // wants 53bit precision. Save and restore current value.
  4951. ++ int fpu = get_fpu_control_word();
  4952. ++#endif // IA64
  4953. ++ int status = pthread_cond_timedwait(_cond, _mutex, _abstime);
  4954. ++#ifndef IA64
  4955. ++ set_fpu_control_word(fpu);
  4956. ++#endif // IA64
  4957. ++ return status;
  4958. ++ }
  4959. ++}
  4960. ++
  4961. ++////////////////////////////////////////////////////////////////////////////////
  4962. ++// debug support
  4963. ++
  4964. ++static address same_page(address x, address y) {
  4965. ++ int page_bits = -os::vm_page_size();
  4966. ++ if ((intptr_t(x) & page_bits) == (intptr_t(y) & page_bits))
  4967. ++ return x;
  4968. ++ else if (x > y)
  4969. ++ return (address)(intptr_t(y) | ~page_bits) + 1;
  4970. ++ else
  4971. ++ return (address)(intptr_t(y) & page_bits);
  4972. ++}
  4973. ++
  4974. ++bool os::find(address addr, outputStream* st) {
  4975. ++ Dl_info dlinfo;
  4976. ++ memset(&dlinfo, 0, sizeof(dlinfo));
  4977. ++ if (dladdr(addr, &dlinfo) != 0) {
  4978. ++ st->print(PTR_FORMAT ": ", addr);
  4979. ++ if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
  4980. ++ st->print("%s+%#x", dlinfo.dli_sname,
  4981. ++ addr - (intptr_t)dlinfo.dli_saddr);
  4982. ++ } else if (dlinfo.dli_fbase != NULL) {
  4983. ++ st->print("<offset %#x>", addr - (intptr_t)dlinfo.dli_fbase);
  4984. ++ } else {
  4985. ++ st->print("<absolute address>");
  4986. ++ }
  4987. ++ if (dlinfo.dli_fname != NULL) {
  4988. ++ st->print(" in %s", dlinfo.dli_fname);
  4989. ++ }
  4990. ++ if (dlinfo.dli_fbase != NULL) {
  4991. ++ st->print(" at " PTR_FORMAT, dlinfo.dli_fbase);
  4992. ++ }
  4993. ++ st->cr();
  4994. ++
  4995. ++ if (Verbose) {
  4996. ++ // decode some bytes around the PC
  4997. ++ address begin = same_page(addr-40, addr);
  4998. ++ address end = same_page(addr+40, addr);
  4999. ++ address lowest = (address) dlinfo.dli_sname;
  5000. ++ if (!lowest) lowest = (address) dlinfo.dli_fbase;
  5001. ++ if (begin < lowest) begin = lowest;
  5002. ++ Dl_info dlinfo2;
  5003. ++ if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
  5004. ++ && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin)
  5005. ++ end = (address) dlinfo2.dli_saddr;
  5006. ++ Disassembler::decode(begin, end, st);
  5007. ++ }
  5008. ++ return true;
  5009. ++ }
  5010. ++ return false;
  5011. ++}
  5012. ++
  5013. ++////////////////////////////////////////////////////////////////////////////////
  5014. ++// misc
  5015. ++
  5016. ++// This does not do anything on Linux. This is basically a hook for being
  5017. ++// able to use structured exception handling (thread-local exception filters)
  5018. ++// on, e.g., Win32.
  5019. ++void
  5020. ++os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method,
  5021. ++ JavaCallArguments* args, Thread* thread) {
  5022. ++ f(value, method, args, thread);
  5023. ++}
  5024. ++
  5025. ++void os::print_statistics() {
  5026. ++}
  5027. ++
  5028. ++int os::message_box(const char* title, const char* message) {
  5029. ++ int i;
  5030. ++ fdStream err(defaultStream::error_fd());
  5031. ++ for (i = 0; i < 78; i++) err.print_raw("=");
  5032. ++ err.cr();
  5033. ++ err.print_raw_cr(title);
  5034. ++ for (i = 0; i < 78; i++) err.print_raw("-");
  5035. ++ err.cr();
  5036. ++ err.print_raw_cr(message);
  5037. ++ for (i = 0; i < 78; i++) err.print_raw("=");
  5038. ++ err.cr();
  5039. ++
  5040. ++ char buf[16];
  5041. ++ // Prevent process from exiting upon "read error" without consuming all CPU
  5042. ++ while (::read(0, buf, sizeof(buf)) <= 0) { ::sleep(100); }
  5043. ++
  5044. ++ return buf[0] == 'y' || buf[0] == 'Y';
  5045. ++}
  5046. ++
  5047. ++int os::stat(const char *path, struct stat *sbuf) {
  5048. ++ char pathbuf[MAX_PATH];
  5049. ++ if (strlen(path) > MAX_PATH - 1) {
  5050. ++ errno = ENAMETOOLONG;
  5051. ++ return -1;
  5052. ++ }
  5053. ++ os::native_path(strcpy(pathbuf, path));
  5054. ++ return ::stat(pathbuf, sbuf);
  5055. ++}
  5056. ++
  5057. ++bool os::check_heap(bool force) {
  5058. ++ return true;
  5059. ++}
  5060. ++
  5061. ++int local_vsnprintf(char* buf, size_t count, const char* format, va_list args) {
  5062. ++ return ::vsnprintf(buf, count, format, args);
  5063. ++}
  5064. ++
  5065. ++// Is a (classpath) directory empty?
  5066. ++bool os::dir_is_empty(const char* path) {
  5067. ++ DIR *dir = NULL;
  5068. ++ struct dirent *ptr;
  5069. ++
  5070. ++ dir = opendir(path);
  5071. ++ if (dir == NULL) return true;
  5072. ++
  5073. ++ /* Scan the directory */
  5074. ++ bool result = true;
  5075. ++ char buf[sizeof(struct dirent) + MAX_PATH];
  5076. ++ while (result && (ptr = ::readdir(dir)) != NULL) {
  5077. ++ if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
  5078. ++ result = false;
  5079. ++ }
  5080. ++ }
  5081. ++ closedir(dir);
  5082. ++ return result;
  5083. ++}
  5084. ++
  5085. ++// This code originates from JDK's sysOpen and open64_w
  5086. ++// from src/solaris/hpi/src/system_md.c
  5087. ++
  5088. ++#ifndef O_DELETE
  5089. ++#define O_DELETE 0x10000
  5090. ++#endif
  5091. ++
  5092. ++// Open a file. Unlink the file immediately after open returns
  5093. ++// if the specified oflag has the O_DELETE flag set.
  5094. ++// O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c
  5095. ++
  5096. ++int os::open(const char *path, int oflag, int mode) {
  5097. ++
  5098. ++ if (strlen(path) > MAX_PATH - 1) {
  5099. ++ errno = ENAMETOOLONG;
  5100. ++ return -1;
  5101. ++ }
  5102. ++ int fd;
  5103. ++ int o_delete = (oflag & O_DELETE);
  5104. ++ oflag = oflag & ~O_DELETE;
  5105. ++
  5106. ++ fd = ::open64(path, oflag, mode);
  5107. ++ if (fd == -1) return -1;
  5108. ++
  5109. ++ //If the open succeeded, the file might still be a directory
  5110. ++ {
  5111. ++ struct stat64 buf64;
  5112. ++ int ret = ::fstat64(fd, &buf64);
  5113. ++ int st_mode = buf64.st_mode;
  5114. ++
  5115. ++ if (ret != -1) {
  5116. ++ if ((st_mode & S_IFMT) == S_IFDIR) {
  5117. ++ errno = EISDIR;
  5118. ++ ::close(fd);
  5119. ++ return -1;
  5120. ++ }
  5121. ++ } else {
  5122. ++ ::close(fd);
  5123. ++ return -1;
  5124. ++ }
  5125. ++ }
  5126. ++
  5127. ++ /*
  5128. ++ * All file descriptors that are opened in the JVM and not
  5129. ++ * specifically destined for a subprocess should have the
  5130. ++ * close-on-exec flag set. If we don't set it, then careless 3rd
  5131. ++ * party native code might fork and exec without closing all
  5132. ++ * appropriate file descriptors (e.g. as we do in closeDescriptors in
  5133. ++ * UNIXProcess.c), and this in turn might:
  5134. ++ *
  5135. ++ * - cause end-of-file to fail to be detected on some file
  5136. ++ * descriptors, resulting in mysterious hangs, or
  5137. ++ *
  5138. ++ * - might cause an fopen in the subprocess to fail on a system
  5139. ++ * suffering from bug 1085341.
  5140. ++ *
  5141. ++ * (Yes, the default setting of the close-on-exec flag is a Unix
  5142. ++ * design flaw)
  5143. ++ *
  5144. ++ * See:
  5145. ++ * 1085341: 32-bit stdio routines should support file descriptors >255
  5146. ++ * 4843136: (process) pipe file descriptor from Runtime.exec not being closed
  5147. ++ * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
  5148. ++ */
  5149. ++#ifdef FD_CLOEXEC
  5150. ++ {
  5151. ++ int flags = ::fcntl(fd, F_GETFD);
  5152. ++ if (flags != -1)
  5153. ++ ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
  5154. ++ }
  5155. ++#endif
  5156. ++
  5157. ++ if (o_delete != 0) {
  5158. ++ ::unlink(path);
  5159. ++ }
  5160. ++ return fd;
  5161. ++}
  5162. ++
  5163. ++
  5164. ++// create binary file, rewriting existing file if required
  5165. ++int os::create_binary_file(const char* path, bool rewrite_existing) {
  5166. ++ int oflags = O_WRONLY | O_CREAT;
  5167. ++ if (!rewrite_existing) {
  5168. ++ oflags |= O_EXCL;
  5169. ++ }
  5170. ++ return ::open64(path, oflags, S_IREAD | S_IWRITE);
  5171. ++}
  5172. ++
  5173. ++// return current position of file pointer
  5174. ++jlong os::current_file_offset(int fd) {
  5175. ++ return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
  5176. ++}
  5177. ++
  5178. ++// move file pointer to the specified offset
  5179. ++jlong os::seek_to_file_offset(int fd, jlong offset) {
  5180. ++ return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
  5181. ++}
  5182. ++
  5183. ++// This code originates from JDK's sysAvailable
  5184. ++// from src/solaris/hpi/src/native_threads/src/sys_api_td.c
  5185. ++
  5186. ++int os::available(int fd, jlong *bytes) {
  5187. ++ jlong cur, end;
  5188. ++ int mode;
  5189. ++ struct stat64 buf64;
  5190. ++
  5191. ++ if (::fstat64(fd, &buf64) >= 0) {
  5192. ++ mode = buf64.st_mode;
  5193. ++ if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
  5194. ++ /*
  5195. ++ * XXX: is the following call interruptible? If so, this might
  5196. ++ * need to go through the INTERRUPT_IO() wrapper as for other
  5197. ++ * blocking, interruptible calls in this file.
  5198. ++ */
  5199. ++ int n;
  5200. ++ if (::ioctl(fd, FIONREAD, &n) >= 0) {
  5201. ++ *bytes = n;
  5202. ++ return 1;
  5203. ++ }
  5204. ++ }
  5205. ++ }
  5206. ++ if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
  5207. ++ return 0;
  5208. ++ } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) {
  5209. ++ return 0;
  5210. ++ } else if (::lseek64(fd, cur, SEEK_SET) == -1) {
  5211. ++ return 0;
  5212. ++ }
  5213. ++ *bytes = end - cur;
  5214. ++ return 1;
  5215. ++}
  5216. ++
  5217. ++int os::socket_available(int fd, jint *pbytes) {
  5218. ++ // Linux doc says EINTR not returned, unlike Solaris
  5219. ++ int ret = ::ioctl(fd, FIONREAD, pbytes);
  5220. ++
  5221. ++ //%% note ioctl can return 0 when successful, JVM_SocketAvailable
  5222. ++ // is expected to return 0 on failure and 1 on success to the jdk.
  5223. ++ return (ret < 0) ? 0 : 1;
  5224. ++}
  5225. ++
  5226. ++// Map a block of memory.
  5227. ++char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
  5228. ++ char *addr, size_t bytes, bool read_only,
  5229. ++ bool allow_exec) {
  5230. ++ int prot;
  5231. ++ int flags = MAP_PRIVATE;
  5232. ++
  5233. ++ if (read_only) {
  5234. ++ prot = PROT_READ;
  5235. ++ } else {
  5236. ++ prot = PROT_READ | PROT_WRITE;
  5237. ++ }
  5238. ++
  5239. ++ if (allow_exec) {
  5240. ++ prot |= PROT_EXEC;
  5241. ++ }
  5242. ++
  5243. ++ if (addr != NULL) {
  5244. ++ flags |= MAP_FIXED;
  5245. ++ }
  5246. ++
  5247. ++ char* mapped_address = (char*)mmap(addr, (size_t)bytes, prot, flags,
  5248. ++ fd, file_offset);
  5249. ++ if (mapped_address == MAP_FAILED) {
  5250. ++ return NULL;
  5251. ++ }
  5252. ++ return mapped_address;
  5253. ++}
  5254. ++
  5255. ++
  5256. ++// Remap a block of memory.
  5257. ++char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
  5258. ++ char *addr, size_t bytes, bool read_only,
  5259. ++ bool allow_exec) {
  5260. ++ // same as map_memory() on this OS
  5261. ++ return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
  5262. ++ allow_exec);
  5263. ++}
  5264. ++
  5265. ++
  5266. ++// Unmap a block of memory.
  5267. ++bool os::pd_unmap_memory(char* addr, size_t bytes) {
  5268. ++ return munmap(addr, bytes) == 0;
  5269. ++}
  5270. ++
  5271. ++static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time);
  5272. ++
  5273. ++static clockid_t thread_cpu_clockid(Thread* thread) {
  5274. ++ pthread_t tid = thread->osthread()->pthread_id();
  5275. ++ clockid_t clockid;
  5276. ++
  5277. ++ // Get thread clockid
  5278. ++ int rc = os::Linux::pthread_getcpuclockid(tid, &clockid);
  5279. ++ assert(rc == 0, "pthread_getcpuclockid is expected to return 0 code");
  5280. ++ return clockid;
  5281. ++}
  5282. ++
  5283. ++// current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
  5284. ++// are used by JVM M&M and JVMTI to get user+sys or user CPU time
  5285. ++// of a thread.
  5286. ++//
  5287. ++// current_thread_cpu_time() and thread_cpu_time(Thread*) returns
  5288. ++// the fast estimate available on the platform.
  5289. ++
  5290. ++jlong os::current_thread_cpu_time() {
  5291. ++ if (os::Linux::supports_fast_thread_cpu_time()) {
  5292. ++ return os::Linux::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
  5293. ++ } else {
  5294. ++ // return user + sys since the cost is the same
  5295. ++ return slow_thread_cpu_time(Thread::current(), true /* user + sys */);
  5296. ++ }
  5297. ++}
  5298. ++
  5299. ++jlong os::thread_cpu_time(Thread* thread) {
  5300. ++ // consistent with what current_thread_cpu_time() returns
  5301. ++ if (os::Linux::supports_fast_thread_cpu_time()) {
  5302. ++ return os::Linux::fast_thread_cpu_time(thread_cpu_clockid(thread));
  5303. ++ } else {
  5304. ++ return slow_thread_cpu_time(thread, true /* user + sys */);
  5305. ++ }
  5306. ++}
  5307. ++
  5308. ++jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
  5309. ++ if (user_sys_cpu_time && os::Linux::supports_fast_thread_cpu_time()) {
  5310. ++ return os::Linux::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
  5311. ++ } else {
  5312. ++ return slow_thread_cpu_time(Thread::current(), user_sys_cpu_time);
  5313. ++ }
  5314. ++}
  5315. ++
  5316. ++jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
  5317. ++ if (user_sys_cpu_time && os::Linux::supports_fast_thread_cpu_time()) {
  5318. ++ return os::Linux::fast_thread_cpu_time(thread_cpu_clockid(thread));
  5319. ++ } else {
  5320. ++ return slow_thread_cpu_time(thread, user_sys_cpu_time);
  5321. ++ }
  5322. ++}
  5323. ++
  5324. ++//
  5325. ++// -1 on error.
  5326. ++//
  5327. ++
  5328. ++static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
  5329. ++ static bool proc_pid_cpu_avail = true;
  5330. ++ static bool proc_task_unchecked = true;
  5331. ++ static const char *proc_stat_path = "/proc/%d/stat";
  5332. ++ pid_t tid = thread->osthread()->thread_id();
  5333. ++ int i;
  5334. ++ char *s;
  5335. ++ char stat[2048];
  5336. ++ int statlen;
  5337. ++ char proc_name[64];
  5338. ++ int count;
  5339. ++ long sys_time, user_time;
  5340. ++ char string[64];
  5341. ++ char cdummy;
  5342. ++ int idummy;
  5343. ++ long ldummy;
  5344. ++ FILE *fp;
  5345. ++
  5346. ++ // We first try accessing /proc/<pid>/cpu since this is faster to
  5347. ++ // process. If this file is not present (linux kernels 2.5 and above)
  5348. ++ // then we open /proc/<pid>/stat.
  5349. ++ if ( proc_pid_cpu_avail ) {
  5350. ++ sprintf(proc_name, "/proc/%d/cpu", tid);
  5351. ++ fp = fopen(proc_name, "r");
  5352. ++ if ( fp != NULL ) {
  5353. ++ count = fscanf( fp, "%s %lu %lu\n", string, &user_time, &sys_time);
  5354. ++ fclose(fp);
  5355. ++ if ( count != 3 ) return -1;
  5356. ++
  5357. ++ if (user_sys_cpu_time) {
  5358. ++ return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
  5359. ++ } else {
  5360. ++ return (jlong)user_time * (1000000000 / clock_tics_per_sec);
  5361. ++ }
  5362. ++ }
  5363. ++ else proc_pid_cpu_avail = false;
  5364. ++ }
  5365. ++
  5366. ++ // The /proc/<tid>/stat aggregates per-process usage on
  5367. ++ // new Linux kernels 2.6+ where NPTL is supported.
  5368. ++ // The /proc/self/task/<tid>/stat still has the per-thread usage.
  5369. ++ // See bug 6328462.
  5370. ++ // There can be no directory /proc/self/task on kernels 2.4 with NPTL
  5371. ++ // and possibly in some other cases, so we check its availability.
  5372. ++ if (proc_task_unchecked && os::Linux::is_NPTL()) {
  5373. ++ // This is executed only once
  5374. ++ proc_task_unchecked = false;
  5375. ++ fp = fopen("/proc/self/task", "r");
  5376. ++ if (fp != NULL) {
  5377. ++ proc_stat_path = "/proc/self/task/%d/stat";
  5378. ++ fclose(fp);
  5379. ++ }
  5380. ++ }
  5381. ++
  5382. ++ sprintf(proc_name, proc_stat_path, tid);
  5383. ++ fp = fopen(proc_name, "r");
  5384. ++ if ( fp == NULL ) return -1;
  5385. ++ statlen = fread(stat, 1, 2047, fp);
  5386. ++ stat[statlen] = '\0';
  5387. ++ fclose(fp);
  5388. ++
  5389. ++ // Skip pid and the command string. Note that we could be dealing with
  5390. ++ // weird command names, e.g. user could decide to rename java launcher
  5391. ++ // to "java 1.4.2 :)", then the stat file would look like
  5392. ++ // 1234 (java 1.4.2 :)) R ... ...
  5393. ++ // We don't really need to know the command string, just find the last
  5394. ++ // occurrence of ")" and then start parsing from there. See bug 4726580.
  5395. ++ s = strrchr(stat, ')');
  5396. ++ i = 0;
  5397. ++ if (s == NULL ) return -1;
  5398. ++
  5399. ++ // Skip blank chars
  5400. ++ do s++; while (isspace(*s));
  5401. ++
  5402. ++ count = sscanf(s,"%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu",
  5403. ++ &cdummy, &idummy, &idummy, &idummy, &idummy, &idummy,
  5404. ++ &ldummy, &ldummy, &ldummy, &ldummy, &ldummy,
  5405. ++ &user_time, &sys_time);
  5406. ++ if ( count != 13 ) return -1;
  5407. ++ if (user_sys_cpu_time) {
  5408. ++ return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec);
  5409. ++ } else {
  5410. ++ return (jlong)user_time * (1000000000 / clock_tics_per_sec);
  5411. ++ }
  5412. ++}
  5413. ++
  5414. ++void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
  5415. ++ info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits
  5416. ++ info_ptr->may_skip_backward = false; // elapsed time not wall time
  5417. ++ info_ptr->may_skip_forward = false; // elapsed time not wall time
  5418. ++ info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned
  5419. ++}
  5420. ++
  5421. ++void os::thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
  5422. ++ info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits
  5423. ++ info_ptr->may_skip_backward = false; // elapsed time not wall time
  5424. ++ info_ptr->may_skip_forward = false; // elapsed time not wall time
  5425. ++ info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned
  5426. ++}
  5427. ++
  5428. ++bool os::is_thread_cpu_time_supported() {
  5429. ++ return true;
  5430. ++}
  5431. ++
  5432. ++// System loadavg support. Returns -1 if load average cannot be obtained.
  5433. ++// Linux doesn't yet have a (official) notion of processor sets,
  5434. ++// so just return the system wide load average.
  5435. ++int os::loadavg(double loadavg[], int nelem) {
  5436. ++ return ::getloadavg(loadavg, nelem);
  5437. ++}
  5438. ++
  5439. ++void os::pause() {
  5440. ++ char filename[MAX_PATH];
  5441. ++ if (PauseAtStartupFile && PauseAtStartupFile[0]) {
  5442. ++ jio_snprintf(filename, MAX_PATH, PauseAtStartupFile);
  5443. ++ } else {
  5444. ++ jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
  5445. ++ }
  5446. ++
  5447. ++ int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  5448. ++ if (fd != -1) {
  5449. ++ struct stat buf;
  5450. ++ ::close(fd);
  5451. ++ while (::stat(filename, &buf) == 0) {
  5452. ++ (void)::poll(NULL, 0, 100);
  5453. ++ }
  5454. ++ } else {
  5455. ++ jio_fprintf(stderr,
  5456. ++ "Could not open pause file '%s', continuing immediately.\n", filename);
  5457. ++ }
  5458. ++}
  5459. ++
  5460. ++
  5461. ++// Refer to the comments in os_solaris.cpp park-unpark.
  5462. ++//
  5463. ++// Beware -- Some versions of NPTL embody a flaw where pthread_cond_timedwait() can
  5464. ++// hang indefinitely. For instance NPTL 0.60 on 2.4.21-4ELsmp is vulnerable.
  5465. ++// For specifics regarding the bug see GLIBC BUGID 261237 :
  5466. ++// http://www.mail-archive.com/debian-glibc@lists.debian.org/msg10837.html.
  5467. ++// Briefly, pthread_cond_timedwait() calls with an expiry time that's not in the future
  5468. ++// will either hang or corrupt the condvar, resulting in subsequent hangs if the condvar
  5469. ++// is used. (The simple C test-case provided in the GLIBC bug report manifests the
  5470. ++// hang). The JVM is vulernable via sleep(), Object.wait(timo), LockSupport.parkNanos()
  5471. ++// and monitorenter when we're using 1-0 locking. All those operations may result in
  5472. ++// calls to pthread_cond_timedwait(). Using LD_ASSUME_KERNEL to use an older version
  5473. ++// of libpthread avoids the problem, but isn't practical.
  5474. ++//
  5475. ++// Possible remedies:
  5476. ++//
  5477. ++// 1. Establish a minimum relative wait time. 50 to 100 msecs seems to work.
  5478. ++// This is palliative and probabilistic, however. If the thread is preempted
  5479. ++// between the call to compute_abstime() and pthread_cond_timedwait(), more
  5480. ++// than the minimum period may have passed, and the abstime may be stale (in the
  5481. ++// past) resultin in a hang. Using this technique reduces the odds of a hang
  5482. ++// but the JVM is still vulnerable, particularly on heavily loaded systems.
  5483. ++//
  5484. ++// 2. Modify park-unpark to use per-thread (per ParkEvent) pipe-pairs instead
  5485. ++// of the usual flag-condvar-mutex idiom. The write side of the pipe is set
  5486. ++// NDELAY. unpark() reduces to write(), park() reduces to read() and park(timo)
  5487. ++// reduces to poll()+read(). This works well, but consumes 2 FDs per extant
  5488. ++// thread.
  5489. ++//
  5490. ++// 3. Embargo pthread_cond_timedwait() and implement a native "chron" thread
  5491. ++// that manages timeouts. We'd emulate pthread_cond_timedwait() by enqueuing
  5492. ++// a timeout request to the chron thread and then blocking via pthread_cond_wait().
  5493. ++// This also works well. In fact it avoids kernel-level scalability impediments
  5494. ++// on certain platforms that don't handle lots of active pthread_cond_timedwait()
  5495. ++// timers in a graceful fashion.
  5496. ++//
  5497. ++// 4. When the abstime value is in the past it appears that control returns
  5498. ++// correctly from pthread_cond_timedwait(), but the condvar is left corrupt.
  5499. ++// Subsequent timedwait/wait calls may hang indefinitely. Given that, we
  5500. ++// can avoid the problem by reinitializing the condvar -- by cond_destroy()
  5501. ++// followed by cond_init() -- after all calls to pthread_cond_timedwait().
  5502. ++// It may be possible to avoid reinitialization by checking the return
  5503. ++// value from pthread_cond_timedwait(). In addition to reinitializing the
  5504. ++// condvar we must establish the invariant that cond_signal() is only called
  5505. ++// within critical sections protected by the adjunct mutex. This prevents
  5506. ++// cond_signal() from "seeing" a condvar that's in the midst of being
  5507. ++// reinitialized or that is corrupt. Sadly, this invariant obviates the
  5508. ++// desirable signal-after-unlock optimization that avoids futile context switching.
  5509. ++//
  5510. ++// I'm also concerned that some versions of NTPL might allocate an auxilliary
  5511. ++// structure when a condvar is used or initialized. cond_destroy() would
  5512. ++// release the helper structure. Our reinitialize-after-timedwait fix
  5513. ++// put excessive stress on malloc/free and locks protecting the c-heap.
  5514. ++//
  5515. ++// We currently use (4). See the WorkAroundNTPLTimedWaitHang flag.
  5516. ++// It may be possible to refine (4) by checking the kernel and NTPL verisons
  5517. ++// and only enabling the work-around for vulnerable environments.
  5518. ++
  5519. ++// utility to compute the abstime argument to timedwait:
  5520. ++// millis is the relative timeout time
  5521. ++// abstime will be the absolute timeout time
  5522. ++// TODO: replace compute_abstime() with unpackTime()
  5523. ++
  5524. ++static struct timespec* compute_abstime(timespec* abstime, jlong millis) {
  5525. ++ if (millis < 0) millis = 0;
  5526. ++ struct timeval now;
  5527. ++ int status = gettimeofday(&now, NULL);
  5528. ++ assert(status == 0, "gettimeofday");
  5529. ++ jlong seconds = millis / 1000;
  5530. ++ millis %= 1000;
  5531. ++ if (seconds > 50000000) { // see man cond_timedwait(3T)
  5532. ++ seconds = 50000000;
  5533. ++ }
  5534. ++ abstime->tv_sec = now.tv_sec + seconds;
  5535. ++ long usec = now.tv_usec + millis * 1000;
  5536. ++ if (usec >= 1000000) {
  5537. ++ abstime->tv_sec += 1;
  5538. ++ usec -= 1000000;
  5539. ++ }
  5540. ++ abstime->tv_nsec = usec * 1000;
  5541. ++ return abstime;
  5542. ++}
  5543. ++
  5544. ++
  5545. ++// Test-and-clear _Event, always leaves _Event set to 0, returns immediately.
  5546. ++// Conceptually TryPark() should be equivalent to park(0).
  5547. ++
  5548. ++int os::PlatformEvent::TryPark() {
  5549. ++ for (;;) {
  5550. ++ const int v = _Event ;
  5551. ++ guarantee ((v == 0) || (v == 1), "invariant") ;
  5552. ++ if (Atomic::cmpxchg (0, &_Event, v) == v) return v ;
  5553. ++ }
  5554. ++}
  5555. ++
  5556. ++void os::PlatformEvent::park() { // AKA "down()"
  5557. ++ // Invariant: Only the thread associated with the Event/PlatformEvent
  5558. ++ // may call park().
  5559. ++ // TODO: assert that _Assoc != NULL or _Assoc == Self
  5560. ++ int v ;
  5561. ++ for (;;) {
  5562. ++ v = _Event ;
  5563. ++ if (Atomic::cmpxchg (v-1, &_Event, v) == v) break ;
  5564. ++ }
  5565. ++ guarantee (v >= 0, "invariant") ;
  5566. ++ if (v == 0) {
  5567. ++ // Do this the hard way by blocking ...
  5568. ++ int status = pthread_mutex_lock(_mutex);
  5569. ++ assert_status(status == 0, status, "mutex_lock");
  5570. ++ guarantee (_nParked == 0, "invariant") ;
  5571. ++ ++ _nParked ;
  5572. ++ while (_Event < 0) {
  5573. ++ status = pthread_cond_wait(_cond, _mutex);
  5574. ++ // for some reason, under 2.7 lwp_cond_wait() may return ETIME ...
  5575. ++ // Treat this the same as if the wait was interrupted
  5576. ++ if (status == ETIME) { status = EINTR; }
  5577. ++ assert_status(status == 0 || status == EINTR, status, "cond_wait");
  5578. ++ }
  5579. ++ -- _nParked ;
  5580. ++
  5581. ++ _Event = 0 ;
  5582. ++ status = pthread_mutex_unlock(_mutex);
  5583. ++ assert_status(status == 0, status, "mutex_unlock");
  5584. ++ // Paranoia to ensure our locked and lock-free paths interact
  5585. ++ // correctly with each other.
  5586. ++ OrderAccess::fence();
  5587. ++ }
  5588. ++ guarantee (_Event >= 0, "invariant") ;
  5589. ++}
  5590. ++
  5591. ++int os::PlatformEvent::park(jlong millis) {
  5592. ++ guarantee (_nParked == 0, "invariant") ;
  5593. ++
  5594. ++ int v ;
  5595. ++ for (;;) {
  5596. ++ v = _Event ;
  5597. ++ if (Atomic::cmpxchg (v-1, &_Event, v) == v) break ;
  5598. ++ }
  5599. ++ guarantee (v >= 0, "invariant") ;
  5600. ++ if (v != 0) return OS_OK ;
  5601. ++
  5602. ++ // We do this the hard way, by blocking the thread.
  5603. ++ // Consider enforcing a minimum timeout value.
  5604. ++ struct timespec abst;
  5605. ++ compute_abstime(&abst, millis);
  5606. ++
  5607. ++ int ret = OS_TIMEOUT;
  5608. ++ int status = pthread_mutex_lock(_mutex);
  5609. ++ assert_status(status == 0, status, "mutex_lock");
  5610. ++ guarantee (_nParked == 0, "invariant") ;
  5611. ++ ++_nParked ;
  5612. ++
  5613. ++ // Object.wait(timo) will return because of
  5614. ++ // (a) notification
  5615. ++ // (b) timeout
  5616. ++ // (c) thread.interrupt
  5617. ++ //
  5618. ++ // Thread.interrupt and object.notify{All} both call Event::set.
  5619. ++ // That is, we treat thread.interrupt as a special case of notification.
  5620. ++ // The underlying Solaris implementation, cond_timedwait, admits
  5621. ++ // spurious/premature wakeups, but the JLS/JVM spec prevents the
  5622. ++ // JVM from making those visible to Java code. As such, we must
  5623. ++ // filter out spurious wakeups. We assume all ETIME returns are valid.
  5624. ++ //
  5625. ++ // TODO: properly differentiate simultaneous notify+interrupt.
  5626. ++ // In that case, we should propagate the notify to another waiter.
  5627. ++
  5628. ++ while (_Event < 0) {
  5629. ++ status = os::Linux::safe_cond_timedwait(_cond, _mutex, &abst);
  5630. ++ if (status != 0 && WorkAroundNPTLTimedWaitHang) {
  5631. ++ pthread_cond_destroy (_cond);
  5632. ++ pthread_cond_init (_cond, NULL) ;
  5633. ++ }
  5634. ++ assert_status(status == 0 || status == EINTR ||
  5635. ++ status == ETIME || status == ETIMEDOUT,
  5636. ++ status, "cond_timedwait");
  5637. ++ if (!FilterSpuriousWakeups) break ; // previous semantics
  5638. ++ if (status == ETIME || status == ETIMEDOUT) break ;
  5639. ++ // We consume and ignore EINTR and spurious wakeups.
  5640. ++ }
  5641. ++ --_nParked ;
  5642. ++ if (_Event >= 0) {
  5643. ++ ret = OS_OK;
  5644. ++ }
  5645. ++ _Event = 0 ;
  5646. ++ status = pthread_mutex_unlock(_mutex);
  5647. ++ assert_status(status == 0, status, "mutex_unlock");
  5648. ++ assert (_nParked == 0, "invariant") ;
  5649. ++ // Paranoia to ensure our locked and lock-free paths interact
  5650. ++ // correctly with each other.
  5651. ++ OrderAccess::fence();
  5652. ++ return ret;
  5653. ++}
  5654. ++
  5655. ++void os::PlatformEvent::unpark() {
  5656. ++ // Transitions for _Event:
  5657. ++ // 0 :=> 1
  5658. ++ // 1 :=> 1
  5659. ++ // -1 :=> either 0 or 1; must signal target thread
  5660. ++ // That is, we can safely transition _Event from -1 to either
  5661. ++ // 0 or 1. Forcing 1 is slightly more efficient for back-to-back
  5662. ++ // unpark() calls.
  5663. ++ // See also: "Semaphores in Plan 9" by Mullender & Cox
  5664. ++ //
  5665. ++ // Note: Forcing a transition from "-1" to "1" on an unpark() means
  5666. ++ // that it will take two back-to-back park() calls for the owning
  5667. ++ // thread to block. This has the benefit of forcing a spurious return
  5668. ++ // from the first park() call after an unpark() call which will help
  5669. ++ // shake out uses of park() and unpark() without condition variables.
  5670. ++
  5671. ++ if (Atomic::xchg(1, &_Event) >= 0) return;
  5672. ++
  5673. ++ // Wait for the thread associated with the event to vacate
  5674. ++ int status = pthread_mutex_lock(_mutex);
  5675. ++ assert_status(status == 0, status, "mutex_lock");
  5676. ++ int AnyWaiters = _nParked;
  5677. ++ assert(AnyWaiters == 0 || AnyWaiters == 1, "invariant");
  5678. ++ if (AnyWaiters != 0 && WorkAroundNPTLTimedWaitHang) {
  5679. ++ AnyWaiters = 0;
  5680. ++ pthread_cond_signal(_cond);
  5681. ++ }
  5682. ++ status = pthread_mutex_unlock(_mutex);
  5683. ++ assert_status(status == 0, status, "mutex_unlock");
  5684. ++ if (AnyWaiters != 0) {
  5685. ++ status = pthread_cond_signal(_cond);
  5686. ++ assert_status(status == 0, status, "cond_signal");
  5687. ++ }
  5688. ++
  5689. ++ // Note that we signal() _after dropping the lock for "immortal" Events.
  5690. ++ // This is safe and avoids a common class of futile wakeups. In rare
  5691. ++ // circumstances this can cause a thread to return prematurely from
  5692. ++ // cond_{timed}wait() but the spurious wakeup is benign and the victim will
  5693. ++ // simply re-test the condition and re-park itself.
  5694. ++}
  5695. ++
  5696. ++
  5697. ++// JSR166
  5698. ++// -------------------------------------------------------
  5699. ++
  5700. ++/*
  5701. ++ * The solaris and linux implementations of park/unpark are fairly
  5702. ++ * conservative for now, but can be improved. They currently use a
  5703. ++ * mutex/condvar pair, plus a a count.
  5704. ++ * Park decrements count if > 0, else does a condvar wait. Unpark
  5705. ++ * sets count to 1 and signals condvar. Only one thread ever waits
  5706. ++ * on the condvar. Contention seen when trying to park implies that someone
  5707. ++ * is unparking you, so don't wait. And spurious returns are fine, so there
  5708. ++ * is no need to track notifications.
  5709. ++ */
  5710. ++
  5711. ++#define MAX_SECS 100000000
  5712. ++/*
  5713. ++ * This code is common to linux and solaris and will be moved to a
  5714. ++ * common place in dolphin.
  5715. ++ *
  5716. ++ * The passed in time value is either a relative time in nanoseconds
  5717. ++ * or an absolute time in milliseconds. Either way it has to be unpacked
  5718. ++ * into suitable seconds and nanoseconds components and stored in the
  5719. ++ * given timespec structure.
  5720. ++ * Given time is a 64-bit value and the time_t used in the timespec is only
  5721. ++ * a signed-32-bit value (except on 64-bit Linux) we have to watch for
  5722. ++ * overflow if times way in the future are given. Further on Solaris versions
  5723. ++ * prior to 10 there is a restriction (see cond_timedwait) that the specified
  5724. ++ * number of seconds, in abstime, is less than current_time + 100,000,000.
  5725. ++ * As it will be 28 years before "now + 100000000" will overflow we can
  5726. ++ * ignore overflow and just impose a hard-limit on seconds using the value
  5727. ++ * of "now + 100,000,000". This places a limit on the timeout of about 3.17
  5728. ++ * years from "now".
  5729. ++ */
  5730. ++
  5731. ++static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) {
  5732. ++ assert (time > 0, "convertTime");
  5733. ++
  5734. ++ struct timeval now;
  5735. ++ int status = gettimeofday(&now, NULL);
  5736. ++ assert(status == 0, "gettimeofday");
  5737. ++
  5738. ++ time_t max_secs = now.tv_sec + MAX_SECS;
  5739. ++
  5740. ++ if (isAbsolute) {
  5741. ++ jlong secs = time / 1000;
  5742. ++ if (secs > max_secs) {
  5743. ++ absTime->tv_sec = max_secs;
  5744. ++ }
  5745. ++ else {
  5746. ++ absTime->tv_sec = secs;
  5747. ++ }
  5748. ++ absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC;
  5749. ++ }
  5750. ++ else {
  5751. ++ jlong secs = time / NANOSECS_PER_SEC;
  5752. ++ if (secs >= MAX_SECS) {
  5753. ++ absTime->tv_sec = max_secs;
  5754. ++ absTime->tv_nsec = 0;
  5755. ++ }
  5756. ++ else {
  5757. ++ absTime->tv_sec = now.tv_sec + secs;
  5758. ++ absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000;
  5759. ++ if (absTime->tv_nsec >= NANOSECS_PER_SEC) {
  5760. ++ absTime->tv_nsec -= NANOSECS_PER_SEC;
  5761. ++ ++absTime->tv_sec; // note: this must be <= max_secs
  5762. ++ }
  5763. ++ }
  5764. ++ }
  5765. ++ assert(absTime->tv_sec >= 0, "tv_sec < 0");
  5766. ++ assert(absTime->tv_sec <= max_secs, "tv_sec > max_secs");
  5767. ++ assert(absTime->tv_nsec >= 0, "tv_nsec < 0");
  5768. ++ assert(absTime->tv_nsec < NANOSECS_PER_SEC, "tv_nsec >= nanos_per_sec");
  5769. ++}
  5770. ++
  5771. ++void Parker::park(bool isAbsolute, jlong time) {
  5772. ++ // Ideally we'd do something useful while spinning, such
  5773. ++ // as calling unpackTime().
  5774. ++
  5775. ++ // Optional fast-path check:
  5776. ++ // Return immediately if a permit is available.
  5777. ++ // We depend on Atomic::xchg() having full barrier semantics
  5778. ++ // since we are doing a lock-free update to _counter.
  5779. ++ if (Atomic::xchg(0, &_counter) > 0) return;
  5780. ++
  5781. ++ Thread* thread = Thread::current();
  5782. ++ assert(thread->is_Java_thread(), "Must be JavaThread");
  5783. ++ JavaThread *jt = (JavaThread *)thread;
  5784. ++
  5785. ++ // Optional optimization -- avoid state transitions if there's an interrupt pending.
  5786. ++ // Check interrupt before trying to wait
  5787. ++ if (Thread::is_interrupted(thread, false)) {
  5788. ++ return;
  5789. ++ }
  5790. ++
  5791. ++ // Next, demultiplex/decode time arguments
  5792. ++ timespec absTime;
  5793. ++ if (time < 0 || (isAbsolute && time == 0) ) { // don't wait at all
  5794. ++ return;
  5795. ++ }
  5796. ++ if (time > 0) {
  5797. ++ unpackTime(&absTime, isAbsolute, time);
  5798. ++ }
  5799. ++
  5800. ++
  5801. ++ // Enter safepoint region
  5802. ++ // Beware of deadlocks such as 6317397.
  5803. ++ // The per-thread Parker:: mutex is a classic leaf-lock.
  5804. ++ // In particular a thread must never block on the Threads_lock while
  5805. ++ // holding the Parker:: mutex. If safepoints are pending both the
  5806. ++ // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock.
  5807. ++ ThreadBlockInVM tbivm(jt);
  5808. ++
  5809. ++ // Don't wait if cannot get lock since interference arises from
  5810. ++ // unblocking. Also. check interrupt before trying wait
  5811. ++ if (Thread::is_interrupted(thread, false) || pthread_mutex_trylock(_mutex) != 0) {
  5812. ++ return;
  5813. ++ }
  5814. ++
  5815. ++ int status ;
  5816. ++ if (_counter > 0) { // no wait needed
  5817. ++ _counter = 0;
  5818. ++ status = pthread_mutex_unlock(_mutex);
  5819. ++ assert (status == 0, "invariant") ;
  5820. ++ // Paranoia to ensure our locked and lock-free paths interact
  5821. ++ // correctly with each other and Java-level accesses.
  5822. ++ OrderAccess::fence();
  5823. ++ return;
  5824. ++ }
  5825. ++
  5826. ++#ifdef ASSERT
  5827. ++ // Don't catch signals while blocked; let the running threads have the signals.
  5828. ++ // (This allows a debugger to break into the running thread.)
  5829. ++ sigset_t oldsigs;
  5830. ++ sigset_t* allowdebug_blocked = os::Linux::allowdebug_blocked_signals();
  5831. ++ pthread_sigmask(SIG_BLOCK, allowdebug_blocked, &oldsigs);
  5832. ++#endif
  5833. ++
  5834. ++ OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */);
  5835. ++ jt->set_suspend_equivalent();
  5836. ++ // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
  5837. ++
  5838. ++ if (time == 0) {
  5839. ++ status = pthread_cond_wait (_cond, _mutex) ;
  5840. ++ } else {
  5841. ++ status = os::Linux::safe_cond_timedwait (_cond, _mutex, &absTime) ;
  5842. ++ if (status != 0 && WorkAroundNPTLTimedWaitHang) {
  5843. ++ pthread_cond_destroy (_cond) ;
  5844. ++ pthread_cond_init (_cond, NULL);
  5845. ++ }
  5846. ++ }
  5847. ++ assert_status(status == 0 || status == EINTR ||
  5848. ++ status == ETIME || status == ETIMEDOUT,
  5849. ++ status, "cond_timedwait");
  5850. ++
  5851. ++#ifdef ASSERT
  5852. ++ pthread_sigmask(SIG_SETMASK, &oldsigs, NULL);
  5853. ++#endif
  5854. ++
  5855. ++ _counter = 0 ;
  5856. ++ status = pthread_mutex_unlock(_mutex) ;
  5857. ++ assert_status(status == 0, status, "invariant") ;
  5858. ++ // Paranoia to ensure our locked and lock-free paths interact
  5859. ++ // correctly with each other and Java-level accesses.
  5860. ++ OrderAccess::fence();
  5861. ++
  5862. ++ // If externally suspended while waiting, re-suspend
  5863. ++ if (jt->handle_special_suspend_equivalent_condition()) {
  5864. ++ jt->java_suspend_self();
  5865. ++ }
  5866. ++}
  5867. ++
  5868. ++void Parker::unpark() {
  5869. ++ int s, status ;
  5870. ++ status = pthread_mutex_lock(_mutex);
  5871. ++ assert (status == 0, "invariant") ;
  5872. ++ s = _counter;
  5873. ++ _counter = 1;
  5874. ++ if (s < 1) {
  5875. ++ if (WorkAroundNPTLTimedWaitHang) {
  5876. ++ status = pthread_cond_signal (_cond) ;
  5877. ++ assert (status == 0, "invariant") ;
  5878. ++ status = pthread_mutex_unlock(_mutex);
  5879. ++ assert (status == 0, "invariant") ;
  5880. ++ } else {
  5881. ++ status = pthread_mutex_unlock(_mutex);
  5882. ++ assert (status == 0, "invariant") ;
  5883. ++ status = pthread_cond_signal (_cond) ;
  5884. ++ assert (status == 0, "invariant") ;
  5885. ++ }
  5886. ++ } else {
  5887. ++ pthread_mutex_unlock(_mutex);
  5888. ++ assert (status == 0, "invariant") ;
  5889. ++ }
  5890. ++}
  5891. ++
  5892. ++
  5893. ++extern char** environ;
  5894. ++
  5895. ++// Run the specified command in a separate process. Return its exit value,
  5896. ++// or -1 on failure (e.g. can't fork a new process).
  5897. ++// Unlike system(), this function can be called from signal handler. It
  5898. ++// doesn't block SIGINT et al.
  5899. ++int os::fork_and_exec(char* cmd) {
  5900. ++ const char * argv[4] = {"sh", "-c", cmd, NULL};
  5901. ++
  5902. ++ // fork() in LinuxThreads/NPTL is not async-safe. It needs to run
  5903. ++ // pthread_atfork handlers and reset pthread library. All we need is a
  5904. ++ // separate process to execve. Make a direct syscall to fork process.
  5905. ++ // On IA64 there's no fork syscall, we have to use fork() and hope for
  5906. ++ // the best...
  5907. ++ pid_t pid = NOT_IA64(NOT_AARCH64(syscall(SYS_fork);))
  5908. ++ IA64_ONLY(fork();)
  5909. ++ AARCH64_ONLY(vfork();)
  5910. ++
  5911. ++ if (pid < 0) {
  5912. ++ // fork failed
  5913. ++ return -1;
  5914. ++
  5915. ++ } else if (pid == 0) {
  5916. ++ // child process
  5917. ++
  5918. ++ // execve() in LinuxThreads will call pthread_kill_other_threads_np()
  5919. ++ // first to kill every thread on the thread list. Because this list is
  5920. ++ // not reset by fork() (see notes above), execve() will instead kill
  5921. ++ // every thread in the parent process. We know this is the only thread
  5922. ++ // in the new process, so make a system call directly.
  5923. ++ // IA64 should use normal execve() from glibc to match the glibc fork()
  5924. ++ // above.
  5925. ++ NOT_IA64(syscall(SYS_execve, "/bin/sh", argv, environ);)
  5926. ++ IA64_ONLY(execve("/bin/sh", (char* const*)argv, environ);)
  5927. ++
  5928. ++ // execve failed
  5929. ++ _exit(-1);
  5930. ++
  5931. ++ } else {
  5932. ++ // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
  5933. ++ // care about the actual exit code, for now.
  5934. ++
  5935. ++ int status;
  5936. ++
  5937. ++ // Wait for the child process to exit. This returns immediately if
  5938. ++ // the child has already exited. */
  5939. ++ while (waitpid(pid, &status, 0) < 0) {
  5940. ++ switch (errno) {
  5941. ++ case ECHILD: return 0;
  5942. ++ case EINTR: break;
  5943. ++ default: return -1;
  5944. ++ }
  5945. ++ }
  5946. ++
  5947. ++ if (WIFEXITED(status)) {
  5948. ++ // The child exited normally; get its exit code.
  5949. ++ return WEXITSTATUS(status);
  5950. ++ } else if (WIFSIGNALED(status)) {
  5951. ++ // The child exited because of a signal
  5952. ++ // The best value to return is 0x80 + signal number,
  5953. ++ // because that is what all Unix shells do, and because
  5954. ++ // it allows callers to distinguish between process exit and
  5955. ++ // process death by signal.
  5956. ++ return 0x80 + WTERMSIG(status);
  5957. ++ } else {
  5958. ++ // Unknown exit code; pass it through
  5959. ++ return status;
  5960. ++ }
  5961. ++ }
  5962. ++}
  5963. ++
  5964. ++// is_headless_jre()
  5965. ++//
  5966. ++// Test for the existence of xawt/libmawt.so or libawt_xawt.so
  5967. ++// in order to report if we are running in a headless jre
  5968. ++//
  5969. ++// Since JDK8 xawt/libmawt.so was moved into the same directory
  5970. ++// as libawt.so, and renamed libawt_xawt.so
  5971. ++//
  5972. ++bool os::is_headless_jre() {
  5973. ++ struct stat statbuf;
  5974. ++ char buf[MAXPATHLEN];
  5975. ++ char libmawtpath[MAXPATHLEN];
  5976. ++ const char *xawtstr = "/xawt/libmawt.so";
  5977. ++ const char *new_xawtstr = "/libawt_xawt.so";
  5978. ++ char *p;
  5979. ++
  5980. ++ // Get path to libjvm.so
  5981. ++ os::jvm_path(buf, sizeof(buf));
  5982. ++
  5983. ++ // Get rid of libjvm.so
  5984. ++ p = strrchr(buf, '/');
  5985. ++ if (p == NULL) return false;
  5986. ++ else *p = '\0';
  5987. ++
  5988. ++ // Get rid of client or server
  5989. ++ p = strrchr(buf, '/');
  5990. ++ if (p == NULL) return false;
  5991. ++ else *p = '\0';
  5992. ++
  5993. ++ // check xawt/libmawt.so
  5994. ++ strcpy(libmawtpath, buf);
  5995. ++ strcat(libmawtpath, xawtstr);
  5996. ++ if (::stat(libmawtpath, &statbuf) == 0) return false;
  5997. ++
  5998. ++ // check libawt_xawt.so
  5999. ++ strcpy(libmawtpath, buf);
  6000. ++ strcat(libmawtpath, new_xawtstr);
  6001. ++ if (::stat(libmawtpath, &statbuf) == 0) return false;
  6002. ++
  6003. ++ return true;
  6004. ++}
  6005. ++
  6006. ++// Get the default path to the core file
  6007. ++// Returns the length of the string
  6008. ++int os::get_core_path(char* buffer, size_t bufferSize) {
  6009. ++ const char* p = get_current_directory(buffer, bufferSize);
  6010. ++
  6011. ++ if (p == NULL) {
  6012. ++ assert(p != NULL, "failed to get current directory");
  6013. ++ return 0;
  6014. ++ }
  6015. ++
  6016. ++ return strlen(buffer);
  6017. ++}
  6018. ++
  6019. ++#ifdef JAVASE_EMBEDDED
  6020. ++//
  6021. ++// A thread to watch the '/dev/mem_notify' device, which will tell us when the OS is running low on memory.
  6022. ++//
  6023. ++MemNotifyThread* MemNotifyThread::_memnotify_thread = NULL;
  6024. ++
  6025. ++// ctor
  6026. ++//
  6027. ++MemNotifyThread::MemNotifyThread(int fd): Thread() {
  6028. ++ assert(memnotify_thread() == NULL, "we can only allocate one MemNotifyThread");
  6029. ++ _fd = fd;
  6030. ++
  6031. ++ if (os::create_thread(this, os::os_thread)) {
  6032. ++ _memnotify_thread = this;
  6033. ++ os::set_priority(this, NearMaxPriority);
  6034. ++ os::start_thread(this);
  6035. ++ }
  6036. ++}
  6037. ++
  6038. ++// Where all the work gets done
  6039. ++//
  6040. ++void MemNotifyThread::run() {
  6041. ++ assert(this == memnotify_thread(), "expected the singleton MemNotifyThread");
  6042. ++
  6043. ++ // Set up the select arguments
  6044. ++ fd_set rfds;
  6045. ++ if (_fd != -1) {
  6046. ++ FD_ZERO(&rfds);
  6047. ++ FD_SET(_fd, &rfds);
  6048. ++ }
  6049. ++
  6050. ++ // Now wait for the mem_notify device to wake up
  6051. ++ while (1) {
  6052. ++ // Wait for the mem_notify device to signal us..
  6053. ++ int rc = select(_fd+1, _fd != -1 ? &rfds : NULL, NULL, NULL, NULL);
  6054. ++ if (rc == -1) {
  6055. ++ perror("select!\n");
  6056. ++ break;
  6057. ++ } else if (rc) {
  6058. ++ //ssize_t free_before = os::available_memory();
  6059. ++ //tty->print ("Notified: Free: %dK \n",os::available_memory()/1024);
  6060. ++
  6061. ++ // The kernel is telling us there is not much memory left...
  6062. ++ // try to do something about that
  6063. ++
  6064. ++ // If we are not already in a GC, try one.
  6065. ++ if (!Universe::heap()->is_gc_active()) {
  6066. ++ Universe::heap()->collect(GCCause::_allocation_failure);
  6067. ++
  6068. ++ //ssize_t free_after = os::available_memory();
  6069. ++ //tty->print ("Post-Notify: Free: %dK\n",free_after/1024);
  6070. ++ //tty->print ("GC freed: %dK\n", (free_after - free_before)/1024);
  6071. ++ }
  6072. ++ // We might want to do something like the following if we find the GC's are not helping...
  6073. ++ // Universe::heap()->size_policy()->set_gc_time_limit_exceeded(true);
  6074. ++ }
  6075. ++ }
  6076. ++}
  6077. ++
  6078. ++//
  6079. ++// See if the /dev/mem_notify device exists, and if so, start a thread to monitor it.
  6080. ++//
  6081. ++void MemNotifyThread::start() {
  6082. ++ int fd;
  6083. ++ fd = open ("/dev/mem_notify", O_RDONLY, 0);
  6084. ++ if (fd < 0) {
  6085. ++ return;
  6086. ++ }
  6087. ++
  6088. ++ if (memnotify_thread() == NULL) {
  6089. ++ new MemNotifyThread(fd);
  6090. ++ }
  6091. ++}
  6092. ++
  6093. ++#endif // JAVASE_EMBEDDED
  6094. +diff -Nur openjdk.orig/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp openjdk/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp
  6095. +--- openjdk.orig/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp 2014-02-20 19:51:45.000000000 +0100
  6096. ++++ openjdk/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp 2014-05-13 16:14:56.641091455 +0200
  6097. +@@ -253,7 +253,7 @@
  6098. + #elif defined(__APPLE__)
  6099. + inline int g_isnan(double f) { return isnan(f); }
  6100. + #elif defined(LINUX) || defined(_ALLBSD_SOURCE)
  6101. +-inline int g_isnan(float f) { return isnanf(f); }
  6102. ++inline int g_isnan(float f) { return __isnanf(f); }
  6103. + inline int g_isnan(double f) { return isnan(f); }
  6104. + #else
  6105. + #error "missing platform-specific definition here"
  6106. +@@ -267,8 +267,8 @@
  6107. +
  6108. + // Checking for finiteness
  6109. +
  6110. +-inline int g_isfinite(jfloat f) { return finite(f); }
  6111. +-inline int g_isfinite(jdouble f) { return finite(f); }
  6112. ++inline int g_isfinite(jfloat f) { return isfinite(f); }
  6113. ++inline int g_isfinite(jdouble f) { return isfinite(f); }
  6114. +
  6115. +
  6116. + // Wide characters
  6117. +diff -Nur openjdk.orig/jdk/make/com/sun/java/pack/Makefile openjdk/jdk/make/com/sun/java/pack/Makefile
  6118. +--- openjdk.orig/jdk/make/com/sun/java/pack/Makefile 2014-04-12 01:23:06.000000000 +0200
  6119. ++++ openjdk/jdk/make/com/sun/java/pack/Makefile 2014-05-13 16:14:56.641091455 +0200
  6120. +@@ -79,7 +79,7 @@
  6121. + OTHER_CXXFLAGS += $(ZLIB_CFLAGS) -DSYSTEM_ZLIB
  6122. + endif
  6123. + else
  6124. +- OTHER_CXXFLAGS += -DNO_ZLIB -DUNPACK_JNI
  6125. ++ CXXFLAGS_COMMON += -DNO_ZLIB -DUNPACK_JNI
  6126. + OTHER_LDLIBS += $(JVMLIB)
  6127. + endif
  6128. +
  6129. +diff -Nur openjdk.orig/jdk/make/com/sun/nio/sctp/Makefile openjdk/jdk/make/com/sun/nio/sctp/Makefile
  6130. +--- openjdk.orig/jdk/make/com/sun/nio/sctp/Makefile 2014-04-12 01:23:06.000000000 +0200
  6131. ++++ openjdk/jdk/make/com/sun/nio/sctp/Makefile 2014-05-13 16:14:56.641091455 +0200
  6132. +@@ -64,7 +64,7 @@
  6133. + COMPILER_WARNINGS_FATAL=true
  6134. + endif
  6135. + #OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -ljava -lnet -lpthread -ldl
  6136. +-OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -lnio -lnet -lpthread -ldl
  6137. ++OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -lnio -ljavanet -lpthread -ldl
  6138. + endif
  6139. + ifeq ($(PLATFORM), solaris)
  6140. + #LIBSCTP = -lsctp
  6141. +diff -Nur openjdk.orig/jdk/make/common/Defs.gmk openjdk/jdk/make/common/Defs.gmk
  6142. +--- openjdk.orig/jdk/make/common/Defs.gmk 2014-04-12 01:23:06.000000000 +0200
  6143. ++++ openjdk/jdk/make/common/Defs.gmk 2014-05-13 16:14:56.641091455 +0200
  6144. +@@ -204,7 +204,7 @@
  6145. + ifeq ($(PLATFORM), macosx)
  6146. + FREETYPE_HEADERS_PATH = /usr/X11R6/include
  6147. + else
  6148. +- FREETYPE_HEADERS_PATH = /usr/include
  6149. ++ FREETYPE_HEADERS_PATH = /usr/include/disabled
  6150. + endif
  6151. + endif
  6152. + endif
  6153. +diff -Nur openjdk.orig/jdk/make/common/Sanity.gmk openjdk/jdk/make/common/Sanity.gmk
  6154. +--- openjdk.orig/jdk/make/common/Sanity.gmk 2014-04-12 01:23:06.000000000 +0200
  6155. ++++ openjdk/jdk/make/common/Sanity.gmk 2014-05-13 16:14:56.641091455 +0200
  6156. +@@ -91,8 +91,7 @@
  6157. + sane-ld_run_path \
  6158. + sane-alt_bootdir \
  6159. + sane-bootdir \
  6160. +- sane-local-bootdir \
  6161. +- sane-alsa-headers
  6162. ++ sane-local-bootdir
  6163. +
  6164. + ifdef OPENJDK
  6165. + sanity-all:: sane-freetype
  6166. +diff -Nur openjdk.orig/jdk/make/common/shared/Platform.gmk openjdk/jdk/make/common/shared/Platform.gmk
  6167. +--- openjdk.orig/jdk/make/common/shared/Platform.gmk 2014-04-12 01:23:06.000000000 +0200
  6168. ++++ openjdk/jdk/make/common/shared/Platform.gmk 2014-05-13 16:14:56.641091455 +0200
  6169. +@@ -160,9 +160,6 @@
  6170. + else
  6171. + mach := $(shell uname -m)
  6172. + endif
  6173. +- ifneq (,$(wildcard /usr/bin/dpkg-architecture))
  6174. +- mach := $(shell (dpkg-architecture -qDEB_HOST_ARCH_CPU 2>/dev/null || echo $(mach)) | sed 's/arm64/aarch64/;s/powerpc$$/ppc/;s/hppa/parisc/;s/ppc64el/ppc64le/')
  6175. +- endif
  6176. + archExpr = case "$(mach)" in \
  6177. + i[3-9]86) \
  6178. + echo i586 \
  6179. +diff -Nur openjdk.orig/jdk/make/common/shared/Sanity.gmk openjdk/jdk/make/common/shared/Sanity.gmk
  6180. +--- openjdk.orig/jdk/make/common/shared/Sanity.gmk 2014-04-12 01:23:06.000000000 +0200
  6181. ++++ openjdk/jdk/make/common/shared/Sanity.gmk 2014-05-13 16:14:56.641091455 +0200
  6182. +@@ -114,11 +114,6 @@
  6183. + elif [ -f /etc/lsb-release ] ; then \
  6184. + $(EGREP) DISTRIB_RELEASE /etc/lsb-release | $(SED) -e 's@.*DISTRIB_RELEASE=\(.*\)@\1@'; \
  6185. + fi)
  6186. +- ALSA_INCLUDE=/usr/include/alsa/version.h
  6187. +- ALSA_LIBRARY=/usr/lib/libasound.so
  6188. +- _ALSA_VERSION := $(shell $(EGREP) SND_LIB_VERSION_STR $(ALSA_INCLUDE) | \
  6189. +- $(SED) -e 's@.*"\(.*\)".*@\1@' )
  6190. +- ALSA_VERSION := $(call GetVersion,$(_ALSA_VERSION))
  6191. + endif
  6192. +
  6193. + ifeq ($(PLATFORM), macosx)
  6194. +@@ -225,7 +220,6 @@
  6195. + sane-compiler \
  6196. + sane-link \
  6197. + sane-cacerts \
  6198. +- sane-alsa-headers \
  6199. + sane-ant_version \
  6200. + sane-zip_version \
  6201. + sane-unzip_version \
  6202. +@@ -1381,34 +1375,6 @@
  6203. + endif
  6204. + endif
  6205. +
  6206. +-######################################################
  6207. +-# Check that ALSA headers and libs are installed and
  6208. +-# that the header has the right version. We only
  6209. +-# need /usr/include/alsa/version.h and /usr/lib/libasound.so
  6210. +-######################################################
  6211. +-
  6212. +-ifdef REQUIRED_ALSA_VERSION
  6213. +- ALSA_CHECK := $(call CheckVersions,$(ALSA_VERSION),$(REQUIRED_ALSA_VERSION))
  6214. +-endif
  6215. +-sane-alsa-headers:
  6216. +-ifdef REQUIRED_ALSA_VERSION
  6217. +- @if [ "$(ALSA_CHECK)" != "missing" ] ; then \
  6218. +- if [ "$(ALSA_CHECK)" != "same" -a "$(ALSA_CHECK)" != "newer" ] ; then \
  6219. +- $(ECHO) "ERROR: The ALSA version must be $(REQUIRED_ALSA_VERSION) or higher. \n" \
  6220. +- " You have the following ALSA version installed: $${alsa_version} \n" \
  6221. +- " Please reinstall ALSA (drivers and lib). You can download \n" \
  6222. +- " the source distribution from http://www.alsa-project.org \n" \
  6223. +- " or go to http://www.freshrpms.net/docs/alsa/ for precompiled RPM packages. \n" \
  6224. +- "" >> $(ERROR_FILE) ; \
  6225. +- fi ; \
  6226. +- else \
  6227. +- $(ECHO) "ERROR: You seem to not have installed ALSA $(REQUIRED_ALSA_VERSION) or higher. \n" \
  6228. +- " Please install ALSA (drivers and lib). You can download the \n" \
  6229. +- " source distribution from http://www.alsa-project.org or go to \n" \
  6230. +- " http://www.freshrpms.net/docs/alsa/ for precompiled RPM packages. \n" \
  6231. +- "" >> $(ERROR_FILE) ; \
  6232. +- fi
  6233. +-endif
  6234. +
  6235. + # If a sanity file doesn't exist, just make sure it's dir exists
  6236. + $(SANITY_FILES):
  6237. +diff -Nur openjdk.orig/jdk/make/java/instrument/Makefile openjdk/jdk/make/java/instrument/Makefile
  6238. +--- openjdk.orig/jdk/make/java/instrument/Makefile 2014-04-12 01:23:06.000000000 +0200
  6239. ++++ openjdk/jdk/make/java/instrument/Makefile 2014-05-13 16:14:56.641091455 +0200
  6240. +@@ -140,6 +140,8 @@
  6241. + # We don't want to link against -ljava
  6242. + JAVALIB=
  6243. +
  6244. ++OTHER_LDLIBS += -liconv
  6245. ++
  6246. + #
  6247. + # Add to ambient vpath so we pick up the library files
  6248. + #
  6249. +diff -Nur openjdk.orig/jdk/make/java/net/Makefile openjdk/jdk/make/java/net/Makefile
  6250. +--- openjdk.orig/jdk/make/java/net/Makefile 2014-04-12 01:23:06.000000000 +0200
  6251. ++++ openjdk/jdk/make/java/net/Makefile 2014-05-13 16:14:56.641091455 +0200
  6252. +@@ -25,7 +25,7 @@
  6253. +
  6254. + BUILDDIR = ../..
  6255. + PACKAGE = java.net
  6256. +-LIBRARY = net
  6257. ++LIBRARY = javanet
  6258. + PRODUCT = sun
  6259. + include $(BUILDDIR)/common/Defs.gmk
  6260. +
  6261. +diff -Nur openjdk.orig/jdk/make/java/nio/Makefile openjdk/jdk/make/java/nio/Makefile
  6262. +--- openjdk.orig/jdk/make/java/nio/Makefile 2014-04-12 01:23:06.000000000 +0200
  6263. ++++ openjdk/jdk/make/java/nio/Makefile 2014-05-13 16:14:56.645091463 +0200
  6264. +@@ -373,7 +373,7 @@
  6265. + endif
  6266. +
  6267. + ifeq ($(PLATFORM), linux)
  6268. +- OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -ljava -lnet -lpthread $(LIBDL)
  6269. ++ OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -ljava -ljavanet -lpthread $(LIBDL)
  6270. + ifdef USE_SYSTEM_GIO
  6271. + OTHER_LDLIBS += $(GIO_LIBS)
  6272. + OTHER_INCLUDES += $(GIO_CFLAGS) -DUSE_SYSTEM_GIO
  6273. +@@ -927,7 +927,7 @@
  6274. +
  6275. + $(GENSOR_EXE) : $(TEMPDIR)/$(GENSOR_SRC)
  6276. + $(prep-target)
  6277. +- ($(CD) $(TEMPDIR); $(NIO_CC) $(CPPFLAGS) $(LDDFLAGS) \
  6278. ++ ($(CD) $(TEMPDIR); $(HOST_CC) $(CPPFLAGS_FOR_BUILD) $(LDDFLAGS) \
  6279. + -o genSocketOptionRegistry$(EXE_SUFFIX) $(GENSOR_SRC))
  6280. +
  6281. + ifdef NIO_PLATFORM_CLASSES_ROOT_DIR
  6282. +@@ -963,7 +963,7 @@
  6283. +
  6284. + $(GENUC_EXE) : $(GENUC_SRC)
  6285. + $(prep-target)
  6286. +- $(NIO_CC) $(CPPFLAGS) -o $@ $(GENUC_SRC)
  6287. ++ $(HOST_CC) $(CPPFLAGS_FOR_BUILD) -o $@ $(GENUC_SRC)
  6288. +
  6289. + ifdef NIO_PLATFORM_CLASSES_ROOT_DIR
  6290. + $(SFS_GEN)/UnixConstants.java: $(NIO_PLATFORM_CLASSES_ROOT_DIR)/sun/nio/fs/UnixConstants-$(PLATFORM)-$(ARCH).java
  6291. +diff -Nur openjdk.orig/jdk/make/java/npt/Makefile openjdk/jdk/make/java/npt/Makefile
  6292. +--- openjdk.orig/jdk/make/java/npt/Makefile 2014-04-12 01:23:06.000000000 +0200
  6293. ++++ openjdk/jdk/make/java/npt/Makefile 2014-05-13 16:14:56.645091463 +0200
  6294. +@@ -64,6 +64,8 @@
  6295. + # We don't want to link against -ljava
  6296. + JAVALIB=
  6297. +
  6298. ++OTHER_LDLIBS += -liconv
  6299. ++
  6300. + # Add -export options to explicitly spell exported symbols
  6301. + ifeq ($(PLATFORM), windows)
  6302. + OTHER_LCF += -export:nptInitialize -export:nptTerminate
  6303. +diff -Nur openjdk.orig/jdk/make/sun/awt/mawt.gmk openjdk/jdk/make/sun/awt/mawt.gmk
  6304. +--- openjdk.orig/jdk/make/sun/awt/mawt.gmk 2014-04-12 01:23:06.000000000 +0200
  6305. ++++ openjdk/jdk/make/sun/awt/mawt.gmk 2014-05-13 16:14:56.645091463 +0200
  6306. +@@ -151,22 +151,6 @@
  6307. + #endif
  6308. +
  6309. + LIBXTST = -lXtst
  6310. +-ifeq ($(PLATFORM), linux)
  6311. +- ifeq ($(ARCH_DATA_MODEL), 64)
  6312. +- # XXX what about the rest of them?
  6313. +- LIBXT = -lXt
  6314. +- else
  6315. +- # Allows for builds on Debian GNU Linux, X11 is in a different place
  6316. +- LIBXT = $(firstword $(wildcard $(OPENWIN_LIB)/libXt.a) \
  6317. +- $(wildcard /usr/lib/libXt.a))
  6318. +- LIBSM = $(firstword $(wildcard $(OPENWIN_LIB)/libSM.a) \
  6319. +- $(wildcard /usr/lib/libSM.a))
  6320. +- LIBICE = $(firstword $(wildcard $(OPENWIN_LIB)/libICE.a) \
  6321. +- $(wildcard /usr/lib/libICE.a))
  6322. +- LIBXTST = $(firstword $(wildcard $(OPENWIN_LIB)/libXtst.a) \
  6323. +- $(wildcard /usr/lib/libXtst.a))
  6324. +- endif
  6325. +-endif
  6326. +
  6327. + # Use -lXmu for EditRes support
  6328. + LIBXMU_DBG = -lXmu
  6329. +@@ -181,7 +165,7 @@
  6330. + OTHER_CFLAGS += -DMLIB_NO_LIBSUNMATH
  6331. + # XXX what is this define below? Isn't it motif-related?
  6332. + OTHER_CFLAGS += -DXMSTRINGDEFINES=1
  6333. +-OTHER_LDLIBS = $(LIBXMU) $(LIBXTST) -lXext $(LIBXT) $(LIBSM) $(LIBICE) -lX11 -lXi
  6334. ++OTHER_LDLIBS = $(LIBXMU) $(LIBXTST) -lXext -lXt -lSM -lICE -lX11 -lXi
  6335. + endif
  6336. +
  6337. + endif
  6338. +@@ -231,11 +215,6 @@
  6339. + CPPFLAGS += -I$(PLATFORM_SRC)/native/common/deps/fontconfig2
  6340. + endif
  6341. +
  6342. +-ifndef HEADLESS
  6343. +-CPPFLAGS += -I$(OPENWIN_HOME)/include
  6344. +-LDFLAGS += -L$(OPENWIN_LIB)
  6345. +-
  6346. +-endif # !HEADLESS
  6347. +
  6348. + CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/debug \
  6349. + -I$(SHARE_SRC)/native/$(PKGDIR)/../font \
  6350. +@@ -270,11 +249,6 @@
  6351. + endif # !HEADLESS
  6352. + endif # PLATFORM
  6353. +
  6354. +-ifeq ($(PLATFORM), linux)
  6355. +- # Checking for the X11/extensions headers at the additional location
  6356. +- CPPFLAGS += -I$(firstword $(wildcard $(OPENWIN_HOME)/include/X11/extensions) \
  6357. +- $(wildcard /usr/include/X11/extensions))
  6358. +-endif
  6359. +
  6360. + ifeq ($(PLATFORM), macosx))
  6361. + CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions \
  6362. +diff -Nur openjdk.orig/jdk/make/sun/awt/mawt.gmk.orig openjdk/jdk/make/sun/awt/mawt.gmk.orig
  6363. +--- openjdk.orig/jdk/make/sun/awt/mawt.gmk.orig 1970-01-01 01:00:00.000000000 +0100
  6364. ++++ openjdk/jdk/make/sun/awt/mawt.gmk.orig 2014-04-12 01:23:06.000000000 +0200
  6365. +@@ -0,0 +1,297 @@
  6366. ++#
  6367. ++# Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  6368. ++# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6369. ++#
  6370. ++# This code is free software; you can redistribute it and/or modify it
  6371. ++# under the terms of the GNU General Public License version 2 only, as
  6372. ++# published by the Free Software Foundation. Oracle designates this
  6373. ++# particular file as subject to the "Classpath" exception as provided
  6374. ++# by Oracle in the LICENSE file that accompanied this code.
  6375. ++#
  6376. ++# This code is distributed in the hope that it will be useful, but WITHOUT
  6377. ++# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  6378. ++# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  6379. ++# version 2 for more details (a copy is included in the LICENSE file that
  6380. ++# accompanied this code).
  6381. ++#
  6382. ++# You should have received a copy of the GNU General Public License version
  6383. ++# 2 along with this work; if not, write to the Free Software Foundation,
  6384. ++# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  6385. ++#
  6386. ++# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  6387. ++# or visit www.oracle.com if you need additional information or have any
  6388. ++# questions.
  6389. ++#
  6390. ++
  6391. ++#
  6392. ++# to create directory:
  6393. ++#
  6394. ++INIT += $(LIB_LOCATION)
  6395. ++
  6396. ++#
  6397. ++# Files
  6398. ++#
  6399. ++# mawt.gmk is just used in building X/Motif native code, so
  6400. ++# this list of java files is no longer included.
  6401. ++#include FILES_java_unix.gmk
  6402. ++include $(BUILDDIR)/sun/awt/FILES_c_unix.gmk
  6403. ++
  6404. ++include $(BUILDDIR)/sun/awt/FILES_export_unix.gmk
  6405. ++
  6406. ++# Check which C files should be built. Headless uses only
  6407. ++# non-motif files. Also, a version-specific motif file is
  6408. ++# compiled based on the motif version.
  6409. ++ifdef HEADLESS
  6410. ++ FILES_c = $(FILES_NO_MOTIF_c)
  6411. ++else
  6412. ++# FILES_c = $(FILES_MOTIF_c) $(FILES_NO_MOTIF_c)
  6413. ++# XXX if in FILES_MOTIF_c there are unrelated to motif stuff, create a separate list!
  6414. ++ FILES_c = $(FILES_NO_MOTIF_c)
  6415. ++endif
  6416. ++
  6417. ++ifeq ($(PLATFORM), solaris)
  6418. ++ ifneq ($(ARCH), amd64)
  6419. ++ FILES_reorder += reorder-$(ARCH)
  6420. ++ endif
  6421. ++endif
  6422. ++
  6423. ++#
  6424. ++# Rules
  6425. ++#
  6426. ++
  6427. ++# Class files should be built & clobbered in make/sun/awt
  6428. ++# If removing this line, also reinclude sun_awt.jmk
  6429. ++DONT_CLOBBER_CLASSES = true
  6430. ++
  6431. ++
  6432. ++ifndef HEADLESS
  6433. ++ifeq ($(VARIANT), OPT)
  6434. ++FILES_m = ../awt/mapfile-mawt-vers
  6435. ++endif
  6436. ++endif
  6437. ++
  6438. ++# Since this library will be living in a subdirectory below the other libraries
  6439. ++# we need to add an extra runpath so that libraries in the upper directory
  6440. ++# are found at runtime.
  6441. ++LD_RUNPATH_EXTRAS = ..
  6442. ++
  6443. ++include $(BUILDDIR)/common/Mapfile-vers.gmk
  6444. ++include $(BUILDDIR)/common/Library.gmk
  6445. ++
  6446. ++$(LIB_LOCATION):
  6447. ++ $(MKDIR) -p $@
  6448. ++
  6449. ++clean::
  6450. ++
  6451. ++#
  6452. ++# Add to the ambient vpath to pick up files in subdirectories
  6453. ++#
  6454. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/alphacomposite
  6455. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/image
  6456. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/image/gif
  6457. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/image/cvutils
  6458. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/shell
  6459. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/medialib
  6460. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/../java2d/opengl
  6461. ++vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR)/../java2d/opengl
  6462. ++vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR)/../java2d/x11
  6463. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/debug
  6464. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/../font
  6465. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/../java2d
  6466. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/../java2d/loops
  6467. ++vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/../java2d/pipe
  6468. ++vpath %.cpp $(SHARE_SRC)/native/$(PKGDIR)/image
  6469. ++vpath %.c $(PLATFORM_SRC)/native/$(PKGDIR)/robot_child
  6470. ++
  6471. ++ifndef USE_SYSTEM_CUPS
  6472. ++vpath %.c $(PLATFORM_SRC)/native/common/deps
  6473. ++endif
  6474. ++
  6475. ++ifndef USE_SYSTEM_FONTCONFIG
  6476. ++vpath %.c $(PLATFORM_SRC)/native/common/deps/fontconfig2
  6477. ++endif
  6478. ++
  6479. ++#
  6480. ++# Libraries to link in.
  6481. ++#
  6482. ++
  6483. ++
  6484. ++ifeq ($(DEBUG_BINARIES), true)
  6485. ++ CFLAGS += -g
  6486. ++endif
  6487. ++ifeq ($(HEADLESS),true)
  6488. ++CFLAGS += -DHEADLESS=$(HEADLESS)
  6489. ++CPPFLAGS += -DHEADLESS=$(HEADLESS)
  6490. ++OTHER_LDLIBS =
  6491. ++else
  6492. ++#CFLAGS += -DMOTIF_VERSION=$(MOTIF_VERSION)
  6493. ++
  6494. ++#ifeq ($(STATIC_MOTIF),true)
  6495. ++# LIBXM = $(MOTIF_LIB)/libXm.a -lXp -lXmu
  6496. ++# ifeq ($(PLATFORM), linux)
  6497. ++# ifeq ($(ARCH_DATA_MODEL), 64)
  6498. ++# LIBXT = -lXt
  6499. ++# else
  6500. ++# # Allows for builds on Debian GNU Linux, X11 is in a different place
  6501. ++# LIBXT = $(firstword $(wildcard /usr/X11R6/lib/libXt.a) \
  6502. ++# $(wildcard /usr/lib/libXt.a))
  6503. ++# LIBSM = $(firstword $(wildcard /usr/X11R6/lib/libSM.a) \
  6504. ++# $(wildcard /usr/lib/libSM.a))
  6505. ++# LIBICE = $(firstword $(wildcard /usr/X11R6/lib/libICE.a) \
  6506. ++# $(wildcard /usr/lib/libICE.a))
  6507. ++# endif
  6508. ++# endif
  6509. ++#else
  6510. ++# LIBXM = -L$(MOTIF_LIB) -lXm -lXp
  6511. ++# ifeq ($(PLATFORM), linux)
  6512. ++# LIBXT = -lXt
  6513. ++# LIBSM =
  6514. ++# LIBICE =
  6515. ++# endif
  6516. ++#endif
  6517. ++
  6518. ++LIBXTST = -lXtst
  6519. ++ifeq ($(PLATFORM), linux)
  6520. ++ ifeq ($(ARCH_DATA_MODEL), 64)
  6521. ++ # XXX what about the rest of them?
  6522. ++ LIBXT = -lXt
  6523. ++ else
  6524. ++ # Allows for builds on Debian GNU Linux, X11 is in a different place
  6525. ++ LIBXT = $(firstword $(wildcard $(OPENWIN_LIB)/libXt.a) \
  6526. ++ $(wildcard /usr/lib/libXt.a))
  6527. ++ LIBSM = $(firstword $(wildcard $(OPENWIN_LIB)/libSM.a) \
  6528. ++ $(wildcard /usr/lib/libSM.a))
  6529. ++ LIBICE = $(firstword $(wildcard $(OPENWIN_LIB)/libICE.a) \
  6530. ++ $(wildcard /usr/lib/libICE.a))
  6531. ++ LIBXTST = $(firstword $(wildcard $(OPENWIN_LIB)/libXtst.a) \
  6532. ++ $(wildcard /usr/lib/libXtst.a))
  6533. ++ endif
  6534. ++endif
  6535. ++
  6536. ++# Use -lXmu for EditRes support
  6537. ++LIBXMU_DBG = -lXmu
  6538. ++LIBXMU_OPT =
  6539. ++LIBXMU = $(LIBXMU_$(VARIANT))
  6540. ++
  6541. ++ifeq ($(PLATFORM), solaris)
  6542. ++OTHER_LDLIBS = -lXt -lXext $(LIBXTST) $(LIBXMU) -lX11 -lXi
  6543. ++endif
  6544. ++
  6545. ++ifneq (,$(findstring $(PLATFORM), linux macosx))
  6546. ++OTHER_CFLAGS += -DMLIB_NO_LIBSUNMATH
  6547. ++# XXX what is this define below? Isn't it motif-related?
  6548. ++OTHER_CFLAGS += -DXMSTRINGDEFINES=1
  6549. ++OTHER_LDLIBS = $(LIBXMU) $(LIBXTST) -lXext $(LIBXT) $(LIBSM) $(LIBICE) -lX11 -lXi
  6550. ++endif
  6551. ++
  6552. ++endif
  6553. ++# !HEADLESS
  6554. ++
  6555. ++OTHER_LDLIBS += $(JVMLIB) $(LIBCXX) \
  6556. ++ -lawt $(LIBM)
  6557. ++
  6558. ++ifdef USE_SYSTEM_CUPS
  6559. ++ OTHER_LDLIBS += $(CUPS_LIBS)
  6560. ++else
  6561. ++ OTHER_LDLIBS += $(LIBDL)
  6562. ++endif
  6563. ++
  6564. ++ifdef USE_SYSTEM_FONTCONFIG
  6565. ++ OTHER_LDLIBS += $(FONTCONFIG_LIBS)
  6566. ++else
  6567. ++ OTHER_LDLIBS += $(LIBDL)
  6568. ++endif
  6569. ++
  6570. ++#
  6571. ++# Sun CC with -Xa misdefines __STDC__ to 0 (zero).
  6572. ++# The following will force checking of X11 prototypes.
  6573. ++#
  6574. ++ifneq ($(CC_VERSION),gcc)
  6575. ++CPPFLAGS += -DFUNCPROTO=15
  6576. ++endif
  6577. ++
  6578. ++#
  6579. ++# Other extra flags needed for compiling.
  6580. ++#
  6581. ++ifdef CUPS_CFLAGS
  6582. ++ CPPFLAGS += $(CUPS_CFLAGS)
  6583. ++else
  6584. ++ CPPFLAGS += -I$(CUPS_HEADERS_PATH)
  6585. ++endif
  6586. ++
  6587. ++ifdef USE_SYSTEM_CUPS
  6588. ++ CPPFLAGS += -DUSE_SYSTEM_CUPS
  6589. ++else
  6590. ++ CPPFLAGS += -I$(PLATFORM_SRC)/native/common/deps
  6591. ++endif
  6592. ++
  6593. ++ifdef USE_SYSTEM_FONTCONFIG
  6594. ++ CPPFLAGS += $(FONTCONFIG_CFLAGS) -DUSE_SYSTEM_FONTCONFIG
  6595. ++else
  6596. ++ CPPFLAGS += -I$(PLATFORM_SRC)/native/common/deps/fontconfig2
  6597. ++endif
  6598. ++
  6599. ++ifndef HEADLESS
  6600. ++CPPFLAGS += -I$(OPENWIN_HOME)/include
  6601. ++LDFLAGS += -L$(OPENWIN_LIB)
  6602. ++
  6603. ++endif # !HEADLESS
  6604. ++
  6605. ++CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/debug \
  6606. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/../font \
  6607. ++ -I$(PLATFORM_SRC)/native/$(PKGDIR)/../font \
  6608. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/image \
  6609. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/image/cvutils \
  6610. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/shell \
  6611. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/alphacomposite \
  6612. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/medialib \
  6613. ++ -I$(PLATFORM_SRC)/native/$(PKGDIR)/medialib \
  6614. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/../java2d \
  6615. ++ -I$(PLATFORM_SRC)/native/$(PKGDIR)/../java2d \
  6616. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/../java2d/loops \
  6617. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/../java2d/pipe \
  6618. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/../java2d/opengl \
  6619. ++ -I$(PLATFORM_SRC)/native/$(PKGDIR)/../java2d/opengl \
  6620. ++ -I$(PLATFORM_SRC)/native/$(PKGDIR)/../java2d/x11 \
  6621. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/../dc/doe \
  6622. ++ -I$(SHARE_SRC)/native/$(PKGDIR)/../dc/path \
  6623. ++ -I$(PLATFORM_SRC)/native/$(PKGDIR)/../jdga \
  6624. ++ -I$(PLATFORM_SRC)/native/$(PKGDIR) \
  6625. ++ $(EVENT_MODEL)
  6626. ++
  6627. ++ifeq ($(PLATFORM), macosx)
  6628. ++CPPFLAGS += -I$(CUPS_HEADERS_PATH)
  6629. ++
  6630. ++ifndef HEADLESS
  6631. ++CPPFLAGS += -I$(MOTIF_DIR)/include \
  6632. ++ -I$(OPENWIN_HOME)/include
  6633. ++LDFLAGS += -L$(MOTIF_LIB) -L$(OPENWIN_LIB)
  6634. ++
  6635. ++endif # !HEADLESS
  6636. ++endif # PLATFORM
  6637. ++
  6638. ++ifeq ($(PLATFORM), linux)
  6639. ++ # Checking for the X11/extensions headers at the additional location
  6640. ++ CPPFLAGS += -I$(firstword $(wildcard $(OPENWIN_HOME)/include/X11/extensions) \
  6641. ++ $(wildcard /usr/include/X11/extensions))
  6642. ++endif
  6643. ++
  6644. ++ifeq ($(PLATFORM), macosx))
  6645. ++ CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions \
  6646. ++ -I$(OPENWIN_HOME)/include
  6647. ++endif
  6648. ++
  6649. ++ifeq ($(PLATFORM), solaris)
  6650. ++ CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions
  6651. ++endif
  6652. ++
  6653. ++ifeq ($(PLATFORM), macosx)
  6654. ++ CPPFLAGS += -DX11_PATH=\"$(X11_PATH)\" -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
  6655. ++endif
  6656. ++
  6657. ++LDFLAGS += -L$(LIBDIR)/$(LIBARCH)/$(TSOBJDIR) \
  6658. ++ $(AWT_RUNPATH)
  6659. ++
  6660. ++CLASSES.export += java.io.InputStream \
  6661. ++ java.lang.ThreadGroup
  6662. ++
  6663. +diff -Nur openjdk.orig/jdk/make/sun/splashscreen/Makefile openjdk/jdk/make/sun/splashscreen/Makefile
  6664. +--- openjdk.orig/jdk/make/sun/splashscreen/Makefile 2014-04-12 01:23:06.000000000 +0200
  6665. ++++ openjdk/jdk/make/sun/splashscreen/Makefile 2014-05-13 16:14:56.645091463 +0200
  6666. +@@ -55,6 +55,8 @@
  6667. +
  6668. + JAVALIB=
  6669. +
  6670. ++OTHER_LDLIBS += -liconv
  6671. ++
  6672. + #
  6673. + # C Flags
  6674. + #
  6675. +diff -Nur openjdk.orig/jdk/make/sun/xawt/Makefile openjdk/jdk/make/sun/xawt/Makefile
  6676. +--- openjdk.orig/jdk/make/sun/xawt/Makefile 2014-04-12 01:23:06.000000000 +0200
  6677. ++++ openjdk/jdk/make/sun/xawt/Makefile 2014-05-13 16:14:56.645091463 +0200
  6678. +@@ -292,16 +292,10 @@
  6679. + SIZERS = $(SIZER).32
  6680. + SIZERS_C = $(SIZER_32_C)
  6681. + SIZES = $(WRAPPER_GENERATOR_DIR)/sizes.32
  6682. +-ifdef CROSS_COMPILE_ARCH
  6683. +-CFLAGS_32 = -m32
  6684. +-endif
  6685. + else # !32
  6686. + SIZERS = $(SIZER).64
  6687. + SIZERS_C = $(SIZER_64_C)
  6688. + SIZES = $(WRAPPER_GENERATOR_DIR)/sizes.64
  6689. +-ifdef CROSS_COMPILE_ARCH
  6690. +-CFLAGS_64 = -m64
  6691. +-endif
  6692. + endif # 32
  6693. + endif # !macosx
  6694. + endif # solaris
  6695. +@@ -337,11 +331,7 @@
  6696. + WRAPPER_GENERATOR_CLASS=$(WRAPPER_GENERATOR_TEMPDIR)/WrapperGenerator.class
  6697. + XLIBTYPES=$(PLATFORM_SRC)/classes/sun/awt/X11/generator/xlibtypes.txt
  6698. +
  6699. +-ifndef CROSS_COMPILE_ARCH
  6700. +-SIZERS_CC = $(CC)
  6701. +-else
  6702. +-SIZERS_CC = $(HOST_CC)
  6703. +-endif
  6704. ++SIZERS_CC = $(CC) -static
  6705. +
  6706. + $(SIZERS): $(SIZERS_C)
  6707. + $(prep-target)
  6708. +@@ -364,7 +354,7 @@
  6709. + $(CHMOD) +w $@;\
  6710. + else \
  6711. + $(ECHO) GENERATING $@; \
  6712. +- $(WRAPPER_GENERATOR_DIR)/sizer$(suffix $@) > $@; \
  6713. ++ $(QEMU) $(WRAPPER_GENERATOR_DIR)/sizer$(suffix $@) > $@; \
  6714. + fi
  6715. + @if [ "$(DOCOMPARE)$(suffix $@)" = "true.64" ]; then \
  6716. + $(ECHO) COMPARING $@ and $(STORED_SIZES_TMPL_$(PLATFORM)_$(LIBARCH)); \
  6717. +diff -Nur openjdk.orig/jdk/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java openjdk/jdk/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java
  6718. +--- openjdk.orig/jdk/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java 2014-04-12 01:23:06.000000000 +0200
  6719. ++++ openjdk/jdk/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java 2014-05-13 16:14:56.645091463 +0200
  6720. +@@ -69,7 +69,7 @@
  6721. + */
  6722. + static {
  6723. + java.security.AccessController.doPrivileged(
  6724. +- new sun.security.action.LoadLibraryAction("net"));
  6725. ++ new sun.security.action.LoadLibraryAction("javanet"));
  6726. + }
  6727. +
  6728. + /**
  6729. +diff -Nur openjdk.orig/jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java openjdk/jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java
  6730. +--- openjdk.orig/jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java 2014-04-12 01:23:06.000000000 +0200
  6731. ++++ openjdk/jdk/src/share/classes/java/net/AbstractPlainSocketImpl.java 2014-05-13 16:14:56.645091463 +0200
  6732. +@@ -78,7 +78,7 @@
  6733. + */
  6734. + static {
  6735. + java.security.AccessController.doPrivileged(
  6736. +- new sun.security.action.LoadLibraryAction("net"));
  6737. ++ new sun.security.action.LoadLibraryAction("javanet"));
  6738. + }
  6739. +
  6740. + /**
  6741. +diff -Nur openjdk.orig/jdk/src/share/classes/java/net/DatagramPacket.java openjdk/jdk/src/share/classes/java/net/DatagramPacket.java
  6742. +--- openjdk.orig/jdk/src/share/classes/java/net/DatagramPacket.java 2014-04-12 01:23:06.000000000 +0200
  6743. ++++ openjdk/jdk/src/share/classes/java/net/DatagramPacket.java 2014-05-13 16:14:56.645091463 +0200
  6744. +@@ -47,7 +47,7 @@
  6745. + */
  6746. + static {
  6747. + java.security.AccessController.doPrivileged(
  6748. +- new sun.security.action.LoadLibraryAction("net"));
  6749. ++ new sun.security.action.LoadLibraryAction("javanet"));
  6750. + init();
  6751. + }
  6752. +
  6753. +diff -Nur openjdk.orig/jdk/src/share/classes/java/net/InetAddress.java openjdk/jdk/src/share/classes/java/net/InetAddress.java
  6754. +--- openjdk.orig/jdk/src/share/classes/java/net/InetAddress.java 2014-04-12 01:23:06.000000000 +0200
  6755. ++++ openjdk/jdk/src/share/classes/java/net/InetAddress.java 2014-05-13 16:14:56.649091471 +0200
  6756. +@@ -267,7 +267,7 @@
  6757. + static {
  6758. + preferIPv6Address = java.security.AccessController.doPrivileged(
  6759. + new GetBooleanAction("java.net.preferIPv6Addresses")).booleanValue();
  6760. +- AccessController.doPrivileged(new LoadLibraryAction("net"));
  6761. ++ AccessController.doPrivileged(new LoadLibraryAction("javanet"));
  6762. + init();
  6763. + }
  6764. +
  6765. +diff -Nur openjdk.orig/jdk/src/share/classes/java/net/NetworkInterface.java openjdk/jdk/src/share/classes/java/net/NetworkInterface.java
  6766. +--- openjdk.orig/jdk/src/share/classes/java/net/NetworkInterface.java 2014-04-12 01:23:06.000000000 +0200
  6767. ++++ openjdk/jdk/src/share/classes/java/net/NetworkInterface.java 2014-05-13 16:14:56.649091471 +0200
  6768. +@@ -53,7 +53,7 @@
  6769. + private static final int defaultIndex; /* index of defaultInterface */
  6770. +
  6771. + static {
  6772. +- AccessController.doPrivileged(new LoadLibraryAction("net"));
  6773. ++ AccessController.doPrivileged(new LoadLibraryAction("javanet"));
  6774. + init();
  6775. + defaultInterface = DefaultInterface.getDefault();
  6776. + if (defaultInterface != null) {
  6777. +diff -Nur openjdk.orig/jdk/src/share/classes/sun/net/sdp/SdpSupport.java openjdk/jdk/src/share/classes/sun/net/sdp/SdpSupport.java
  6778. +--- openjdk.orig/jdk/src/share/classes/sun/net/sdp/SdpSupport.java 2014-04-12 01:23:06.000000000 +0200
  6779. ++++ openjdk/jdk/src/share/classes/sun/net/sdp/SdpSupport.java 2014-05-13 16:14:56.649091471 +0200
  6780. +@@ -76,6 +76,6 @@
  6781. +
  6782. + static {
  6783. + AccessController.doPrivileged(
  6784. +- new sun.security.action.LoadLibraryAction("net"));
  6785. ++ new sun.security.action.LoadLibraryAction("javanet"));
  6786. + }
  6787. + }
  6788. +diff -Nur openjdk.orig/jdk/src/share/classes/sun/net/spi/DefaultProxySelector.java openjdk/jdk/src/share/classes/sun/net/spi/DefaultProxySelector.java
  6789. +--- openjdk.orig/jdk/src/share/classes/sun/net/spi/DefaultProxySelector.java 2014-04-12 01:23:06.000000000 +0200
  6790. ++++ openjdk/jdk/src/share/classes/sun/net/spi/DefaultProxySelector.java 2014-05-13 16:14:56.649091471 +0200
  6791. +@@ -95,7 +95,7 @@
  6792. + }});
  6793. + if (b != null && b.booleanValue()) {
  6794. + java.security.AccessController.doPrivileged(
  6795. +- new sun.security.action.LoadLibraryAction("net"));
  6796. ++ new sun.security.action.LoadLibraryAction("javanet"));
  6797. + hasSystemProxies = init();
  6798. + }
  6799. + }
  6800. +diff -Nur openjdk.orig/jdk/src/share/classes/sun/nio/ch/Util.java openjdk/jdk/src/share/classes/sun/nio/ch/Util.java
  6801. +--- openjdk.orig/jdk/src/share/classes/sun/nio/ch/Util.java 2014-04-12 01:23:06.000000000 +0200
  6802. ++++ openjdk/jdk/src/share/classes/sun/nio/ch/Util.java 2014-05-13 16:14:56.649091471 +0200
  6803. +@@ -483,7 +483,7 @@
  6804. + return;
  6805. + loaded = true;
  6806. + java.security.AccessController
  6807. +- .doPrivileged(new sun.security.action.LoadLibraryAction("net"));
  6808. ++ .doPrivileged(new sun.security.action.LoadLibraryAction("javanet"));
  6809. + java.security.AccessController
  6810. + .doPrivileged(new sun.security.action.LoadLibraryAction("nio"));
  6811. + // IOUtil must be initialized; Its native methods are called from
  6812. +diff -Nur openjdk.orig/jdk/src/solaris/classes/sun/net/dns/ResolverConfigurationImpl.java openjdk/jdk/src/solaris/classes/sun/net/dns/ResolverConfigurationImpl.java
  6813. +--- openjdk.orig/jdk/src/solaris/classes/sun/net/dns/ResolverConfigurationImpl.java 2014-04-12 01:23:06.000000000 +0200
  6814. ++++ openjdk/jdk/src/solaris/classes/sun/net/dns/ResolverConfigurationImpl.java 2014-05-13 16:14:56.649091471 +0200
  6815. +@@ -247,7 +247,7 @@
  6816. +
  6817. + static {
  6818. + java.security.AccessController.doPrivileged(
  6819. +- new sun.security.action.LoadLibraryAction("net"));
  6820. ++ new sun.security.action.LoadLibraryAction("javanet"));
  6821. + }
  6822. +
  6823. + }
  6824. +diff -Nur openjdk.orig/jdk/src/solaris/native/sun/awt/awt_InputMethod.c openjdk/jdk/src/solaris/native/sun/awt/awt_InputMethod.c
  6825. +--- openjdk.orig/jdk/src/solaris/native/sun/awt/awt_InputMethod.c 2014-04-12 01:23:06.000000000 +0200
  6826. ++++ openjdk/jdk/src/solaris/native/sun/awt/awt_InputMethod.c 2014-05-13 16:14:56.649091471 +0200
  6827. +@@ -246,7 +246,8 @@
  6828. + if (wcs == NULL)
  6829. + return NULL;
  6830. +
  6831. +- n = len*MB_CUR_MAX + 1;
  6832. ++ //evil hack for uclibc
  6833. ++ n = len*1 + 1;
  6834. +
  6835. + mbs = (char *) malloc(n * sizeof(char));
  6836. + if (mbs == NULL) {
  6837. +diff -Nur openjdk.orig/jdk/src/solaris/native/sun/xawt/XToolkit.c openjdk/jdk/src/solaris/native/sun/xawt/XToolkit.c
  6838. +--- openjdk.orig/jdk/src/solaris/native/sun/xawt/XToolkit.c 2014-04-12 01:23:06.000000000 +0200
  6839. ++++ openjdk/jdk/src/solaris/native/sun/xawt/XToolkit.c 2014-05-13 16:14:56.649091471 +0200
  6840. +@@ -27,9 +27,6 @@
  6841. + #include <X11/Xutil.h>
  6842. + #include <X11/Xos.h>
  6843. + #include <X11/Xatom.h>
  6844. +-#ifdef __linux__
  6845. +-#include <execinfo.h>
  6846. +-#endif
  6847. +
  6848. + #include <jvm.h>
  6849. + #include <jni.h>
  6850. +@@ -785,25 +782,6 @@
  6851. + return ret;
  6852. + }
  6853. +
  6854. +-#ifdef __linux__
  6855. +-void print_stack(void)
  6856. +-{
  6857. +- void *array[10];
  6858. +- size_t size;
  6859. +- char **strings;
  6860. +- size_t i;
  6861. +-
  6862. +- size = backtrace (array, 10);
  6863. +- strings = backtrace_symbols (array, size);
  6864. +-
  6865. +- fprintf (stderr, "Obtained %zd stack frames.\n", size);
  6866. +-
  6867. +- for (i = 0; i < size; i++)
  6868. +- fprintf (stderr, "%s\n", strings[i]);
  6869. +-
  6870. +- free (strings);
  6871. +-}
  6872. +-#endif
  6873. +
  6874. + Window get_xawt_root_shell(JNIEnv *env) {
  6875. + static jclass classXRootWindow = NULL;
  6876. +diff -Nur openjdk.orig/jdk/src/windows/classes/sun/net/dns/ResolverConfigurationImpl.java openjdk/jdk/src/windows/classes/sun/net/dns/ResolverConfigurationImpl.java
  6877. +--- openjdk.orig/jdk/src/windows/classes/sun/net/dns/ResolverConfigurationImpl.java 2014-04-12 01:23:06.000000000 +0200
  6878. ++++ openjdk/jdk/src/windows/classes/sun/net/dns/ResolverConfigurationImpl.java 2014-05-13 16:14:56.649091471 +0200
  6879. +@@ -159,7 +159,7 @@
  6880. +
  6881. + static {
  6882. + java.security.AccessController.doPrivileged(
  6883. +- new sun.security.action.LoadLibraryAction("net"));
  6884. ++ new sun.security.action.LoadLibraryAction("javanet"));
  6885. + init0();
  6886. +
  6887. + // start the address listener thread
  6888. +diff -Nur openjdk.orig/Makefile openjdk/Makefile
  6889. +--- openjdk.orig/Makefile 2014-04-04 19:44:40.000000000 +0200
  6890. ++++ openjdk/Makefile 2014-05-13 16:14:56.649091471 +0200
  6891. +@@ -53,9 +53,7 @@
  6892. + REL_JDK_DEBUG_IMAGE_DIR = ../$(OUTPUTDIR_BASENAME-debug)/$(JDK_IMAGE_DIRNAME)
  6893. + REL_JDK_FASTDEBUG_IMAGE_DIR = ../$(OUTPUTDIR_BASENAME-fastdebug)/$(JDK_IMAGE_DIRNAME)
  6894. +
  6895. +-ifndef TOPDIR
  6896. +- TOPDIR:=.
  6897. +-endif
  6898. ++TOPDIR:=.
  6899. +
  6900. + ifndef JDK_TOPDIR
  6901. + JDK_TOPDIR=$(TOPDIR)/jdk
  6902. +diff -Nur openjdk-boot.orig/hotspot/make/linux/makefiles/vm.make openjdk-boot/hotspot/make/linux/makefiles/vm.make
  6903. +--- openjdk-boot.orig/hotspot/make/linux/makefiles/vm.make 2014-02-20 19:51:45.000000000 +0100
  6904. ++++ openjdk-boot/hotspot/make/linux/makefiles/vm.make 2014-05-01 20:03:03.677930438 +0200
  6905. +@@ -288,7 +288,7 @@
  6906. + LIBS_VM += $(LIBS)
  6907. + endif
  6908. + ifeq ($(JVM_VARIANT_ZEROSHARK), true)
  6909. +- LIBS_VM += $(LIBFFI_LIBS) $(LLVM_LIBS)
  6910. ++ LIBS_VM += $(LLVM_LIBS)
  6911. + LFLAGS_VM += $(LLVM_LDFLAGS)
  6912. + endif
  6913. +
  6914. +diff -Nur openjdk-boot.orig/hotspot/make/linux/makefiles/zero.make openjdk-boot/hotspot/make/linux/makefiles/zero.make
  6915. +--- openjdk-boot.orig/hotspot/make/linux/makefiles/zero.make 2014-02-20 19:51:45.000000000 +0100
  6916. ++++ openjdk-boot/hotspot/make/linux/makefiles/zero.make 2014-05-01 20:03:03.677930438 +0200
  6917. +@@ -33,4 +33,4 @@
  6918. +
  6919. + # Make sure libffi is included
  6920. + CFLAGS += $(LIBFFI_CFLAGS)
  6921. +-LIBS_VM += $(LIBFFI_LIBS)
  6922. ++LIBS_VM += $(FFI_LDFLAGS) -Wl,-Bstatic $(LIBFFI_LIBS) -Wl,-Bdynamic
  6923. +diff -Nur openjdk-boot.orig/jdk/make/common/Sanity.gmk openjdk-boot/jdk/make/common/Sanity.gmk
  6924. +--- openjdk-boot.orig/jdk/make/common/Sanity.gmk 2014-04-12 01:23:06.000000000 +0200
  6925. ++++ openjdk-boot/jdk/make/common/Sanity.gmk 2014-05-01 20:03:03.677930438 +0200
  6926. +@@ -91,8 +91,7 @@
  6927. + sane-ld_run_path \
  6928. + sane-alt_bootdir \
  6929. + sane-bootdir \
  6930. +- sane-local-bootdir \
  6931. +- sane-alsa-headers
  6932. ++ sane-local-bootdir
  6933. +
  6934. + ifdef OPENJDK
  6935. + sanity-all:: sane-freetype
  6936. +diff -Nur openjdk-boot.orig/jdk/make/common/shared/Sanity.gmk openjdk-boot/jdk/make/common/shared/Sanity.gmk
  6937. +--- openjdk-boot.orig/jdk/make/common/shared/Sanity.gmk 2014-04-12 01:23:06.000000000 +0200
  6938. ++++ openjdk-boot/jdk/make/common/shared/Sanity.gmk 2014-05-01 20:03:03.681930476 +0200
  6939. +@@ -114,11 +114,6 @@
  6940. + elif [ -f /etc/lsb-release ] ; then \
  6941. + $(EGREP) DISTRIB_RELEASE /etc/lsb-release | $(SED) -e 's@.*DISTRIB_RELEASE=\(.*\)@\1@'; \
  6942. + fi)
  6943. +- ALSA_INCLUDE=/usr/include/alsa/version.h
  6944. +- ALSA_LIBRARY=/usr/lib/libasound.so
  6945. +- _ALSA_VERSION := $(shell $(EGREP) SND_LIB_VERSION_STR $(ALSA_INCLUDE) | \
  6946. +- $(SED) -e 's@.*"\(.*\)".*@\1@' )
  6947. +- ALSA_VERSION := $(call GetVersion,$(_ALSA_VERSION))
  6948. + endif
  6949. +
  6950. + ifeq ($(PLATFORM), macosx)
  6951. +@@ -225,7 +220,6 @@
  6952. + sane-compiler \
  6953. + sane-link \
  6954. + sane-cacerts \
  6955. +- sane-alsa-headers \
  6956. + sane-ant_version \
  6957. + sane-zip_version \
  6958. + sane-unzip_version \
  6959. +@@ -1381,35 +1375,6 @@
  6960. + endif
  6961. + endif
  6962. +
  6963. +-######################################################
  6964. +-# Check that ALSA headers and libs are installed and
  6965. +-# that the header has the right version. We only
  6966. +-# need /usr/include/alsa/version.h and /usr/lib/libasound.so
  6967. +-######################################################
  6968. +-
  6969. +-ifdef REQUIRED_ALSA_VERSION
  6970. +- ALSA_CHECK := $(call CheckVersions,$(ALSA_VERSION),$(REQUIRED_ALSA_VERSION))
  6971. +-endif
  6972. +-sane-alsa-headers:
  6973. +-ifdef REQUIRED_ALSA_VERSION
  6974. +- @if [ "$(ALSA_CHECK)" != "missing" ] ; then \
  6975. +- if [ "$(ALSA_CHECK)" != "same" -a "$(ALSA_CHECK)" != "newer" ] ; then \
  6976. +- $(ECHO) "ERROR: The ALSA version must be $(REQUIRED_ALSA_VERSION) or higher. \n" \
  6977. +- " You have the following ALSA version installed: $${alsa_version} \n" \
  6978. +- " Please reinstall ALSA (drivers and lib). You can download \n" \
  6979. +- " the source distribution from http://www.alsa-project.org \n" \
  6980. +- " or go to http://www.freshrpms.net/docs/alsa/ for precompiled RPM packages. \n" \
  6981. +- "" >> $(ERROR_FILE) ; \
  6982. +- fi ; \
  6983. +- else \
  6984. +- $(ECHO) "ERROR: You seem to not have installed ALSA $(REQUIRED_ALSA_VERSION) or higher. \n" \
  6985. +- " Please install ALSA (drivers and lib). You can download the \n" \
  6986. +- " source distribution from http://www.alsa-project.org or go to \n" \
  6987. +- " http://www.freshrpms.net/docs/alsa/ for precompiled RPM packages. \n" \
  6988. +- "" >> $(ERROR_FILE) ; \
  6989. +- fi
  6990. +-endif
  6991. +-
  6992. + # If a sanity file doesn't exist, just make sure it's dir exists
  6993. + $(SANITY_FILES):
  6994. + -@$(prep-target)
  6995. +diff -Nur openjdk-boot.orig/jdk/make/javax/sound/jsoundalsa/Makefile openjdk-boot/jdk/make/javax/sound/jsoundalsa/Makefile
  6996. +--- openjdk-boot.orig/jdk/make/javax/sound/jsoundalsa/Makefile 2014-04-12 01:23:06.000000000 +0200
  6997. ++++ openjdk-boot/jdk/make/javax/sound/jsoundalsa/Makefile 2014-05-15 15:49:03.886269427 +0200
  6998. +@@ -72,6 +72,7 @@
  6999. + -DUSE_PORTS=TRUE \
  7000. + -DUSE_PLATFORM_MIDI_OUT=TRUE \
  7001. + -DUSE_PLATFORM_MIDI_IN=TRUE \
  7002. ++ $(ALSA_CPPFLAGS) \
  7003. + -I$(SHARE_SRC)/native/com/sun/media/sound
  7004. +
  7005. + #
  7006. +diff -Nur openjdk-boot.orig/jdk/make/sun/awt/mawt.gmk openjdk-boot/jdk/make/sun/awt/mawt.gmk
  7007. +--- openjdk-boot.orig/jdk/make/sun/awt/mawt.gmk 2014-04-12 01:23:06.000000000 +0200
  7008. ++++ openjdk-boot/jdk/make/sun/awt/mawt.gmk 2014-05-01 20:03:03.681930476 +0200
  7009. +@@ -270,12 +270,6 @@
  7010. + endif # !HEADLESS
  7011. + endif # PLATFORM
  7012. +
  7013. +-ifeq ($(PLATFORM), linux)
  7014. +- # Checking for the X11/extensions headers at the additional location
  7015. +- CPPFLAGS += -I$(firstword $(wildcard $(OPENWIN_HOME)/include/X11/extensions) \
  7016. +- $(wildcard /usr/include/X11/extensions))
  7017. +-endif
  7018. +-
  7019. + ifeq ($(PLATFORM), macosx))
  7020. + CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions \
  7021. + -I$(OPENWIN_HOME)/include
  7022. +diff -Nur openjdk-boot.orig/Makefile openjdk-boot/Makefile
  7023. +--- openjdk-boot.orig/Makefile 2014-04-04 19:44:40.000000000 +0200
  7024. ++++ openjdk-boot/Makefile 2014-05-01 20:02:54.549843414 +0200
  7025. +@@ -53,9 +53,7 @@
  7026. + REL_JDK_DEBUG_IMAGE_DIR = ../$(OUTPUTDIR_BASENAME-debug)/$(JDK_IMAGE_DIRNAME)
  7027. + REL_JDK_FASTDEBUG_IMAGE_DIR = ../$(OUTPUTDIR_BASENAME-fastdebug)/$(JDK_IMAGE_DIRNAME)
  7028. +
  7029. +-ifndef TOPDIR
  7030. +- TOPDIR:=.
  7031. +-endif
  7032. ++TOPDIR:=.
  7033. +
  7034. + ifndef JDK_TOPDIR
  7035. + JDK_TOPDIR=$(TOPDIR)/jdk