IF you purchased your AMD Processor from a Retailer/Vendor and it came in an official AMD Box then you have a 3 year AMD Warranty.
But AMD Warranty doesn't apply until your Retailer/Vendor's Warranty has expired first.
I suggest you open a Online AMD Warranty Request and see if they believe your Processor needs to be RMAed to be checked from here: https://www.amd.com/en/support/kb/warranty-information/rma-form
Also open an ASRock Support ticket for the same reason for your Motherboard.
BUT BEFORE you do all that, when a computer shuts down by itself it generally due to Overheating, Overclocking, Power (PSU) or incompatible hardware or driver.
Reset your BIOS to Factory default using CMOS CLEAR procedure (removing battery) as per your manual.
Also check to see if your RAM MEMORY is listed in the QVL List for your Processor from ASRock Support and you have the latest BIOS and CHIPSET versions installed for your processor.
If you are able to boot up into Windows. Try stress testing your CPU and GPU and PSU using OCCT.
See if any of the tests crashes your computer and shuts it down by itself.
While running each test keep a close eye on Temperatures and PSU outputs for any abnormal readings.